Skip to content

Added avrDateField directive to show a datepicker #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="row">
<label ng-if="!label" class="control-label col-sm-4">{{field.name}}</label>
<label class="control-label col-sm-4" ng-if="label" ng-bind="label"></label>
<div class="col-sm-8">
<select ng-model="date.year" ng-change="onChange()">
<option ng-selected="date.year == item" ng-repeat="item in years" ng-value="item">{{item}}</option>
</select>

<select ng-model="date.month" ng-change="onChange()">
<option ng-selected="date.month == item" ng-repeat="item in months" ng-value="item">{{item}}</option>
</select>

<select ng-model="date.day" ng-change="onChange()">
<option ng-selected="date.day == item" ng-repeat="item in getDays()" ng-value="item">{{item}}</option>
</select>
</div>
</div>
65 changes: 65 additions & 0 deletions avRegistration/fields/date-field-directive/date-field-directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* This file is part of agora-gui-common.
* Copyright (C) 2015-2016 Agora Voting SL <agora@agoravoting.com>

* agora-gui-common is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License.

* agora-gui-common is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.

* You should have received a copy of the GNU Affero General Public License
* along with agora-gui-common. If not, see <http://www.gnu.org/licenses/>.
**/

angular.module('avRegistration')
.directive('avrDateField', function($state, Patterns) {
function link(scope, element, attrs) {
scope.years = [];
scope.months = [];
scope.field = scope.$parent.field;

var now = new Date();
scope.date = {
year: now.getFullYear(),
month: now.getMonth() + 1,
day: now.getDate()
};

var initY = (new Date()).getFullYear();
var i = 0;

for (i=initY; i>=initY-130; i--) {
scope.years.push(i);
}

for (i=1; i<=12; i++) {
scope.months.push(i);
}

scope.getDays = function() {
var days = [];
var ndays = (new Date(scope.date.year, scope.date.month, 0)).getDate();
for (i=1; i<=ndays; i++) {
days.push(i);
}
return days;
};

scope.onChange = function() {
scope.ngModel = scope.date.year + "-" + scope.date.month + "-" + scope.date.day;
};
}
return {
restrict: 'AE',
link: link,
scope: {
ngModel: '=',
label: '=',
},
templateUrl: 'avRegistration/fields/date-field-directive/date-field-directive.html'
};
});
Empty file.
30 changes: 30 additions & 0 deletions dist/appCommon-v103111.8.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,35 @@ angular.module("avRegistration").factory("Authmethod", [ "$http", "$cookies", "C
scope: !0,
templateUrl: "avRegistration/fields/email-field-directive/email-field-directive.html"
};
} ]), angular.module("avRegistration").directive("avrDateField", [ "$state", "Patterns", function($state, Patterns) {
function link(scope, element, attrs) {
scope.years = [], scope.months = [], scope.field = scope.$parent.field;
var now = new Date();
scope.date = {
year: now.getFullYear(),
month: now.getMonth() + 1,
day: now.getDate()
};
var initY = new Date().getFullYear(), i = 0;
for (i = initY; i >= initY - 130; i--) scope.years.push(i);
for (i = 1; i <= 12; i++) scope.months.push(i);
scope.getDays = function() {
var days = [], ndays = new Date(scope.date.year, scope.date.month, 0).getDate();
for (i = 1; i <= ndays; i++) days.push(i);
return days;
}, scope.onChange = function() {
scope.ngModel = scope.date.year + "-" + scope.date.month + "-" + scope.date.day;
};
}
return {
restrict: "AE",
link: link,
scope: {
ngModel: "=",
label: "="
},
templateUrl: "avRegistration/fields/date-field-directive/date-field-directive.html"
};
} ]), angular.module("avRegistration").directive("avrPasswordField", [ "$state", function($state) {
return {
restrict: "AE",
Expand Down Expand Up @@ -1183,6 +1212,7 @@ angular.module("jm.i18next").config([ "$i18nextProvider", "ConfigServiceProvider
$templateCache.put("avRegistration/fields/bool-field-directive/bool-field-directive.html", '<div class="form-group"><label class="control-label col-sm-4"><input type="checkbox" class="form-control" id="{{index}}Text" ng-model="field.value" ng-disabled="field.disabled" tabindex="{{index}}" ng-required="{{field.required}}"></label><div class="col-sm-8"><label class="text-left" for="{{index}}Text"><span ng-bind-html="field.name | addTargetBlank"></span></label><p class="help-block" ng-if="field.help" ng-bind-html="field.help | addTargetBlank"></p><div class="input-error"></div></div></div>'),
$templateCache.put("avRegistration/fields/captcha-field-directive/captcha-field-directive.html", '<div class="form-group"><div class="col-sm-8 col-sm-offset-4"><img ng-src="{{authMethod.captcha_image_url}}" style="width:161px;height:65px"></div><label for="{{index}}Text" class="control-label col-sm-4"><span>{{field.name}}</span></label><div class="col-sm-8"><input type="text" class="form-control" id="{{index}}Text" minlength="{{field.min}}" maxlength="{{field.max}}" ng-model="field.value" ng-disabled="field.disabled" tabindex="{{index}}" required><p class="help-block" ng-if="field.help">{{field.help}}</p><div class="input-error">{{authMethod.captcha_status}}</div></div></div>'),
$templateCache.put("avRegistration/fields/code-field-directive/code-field-directive.html", '<div class="form-group"><label for="{{code_id}}" class="control-label col-sm-4" ng-i18next="avRegistration.codeLabel"></label><div class="col-sm-8"><input type="text" class="form-control" id="{{code_id}}" ng-model="field.value" ng-disabled="field.disabled" tabindex="{{index}}" autocomplete="off" ng-class="{\'filled\': form[code_id].$viewValue.length > 0}" minlength="8" maxlength="9" ng-pattern="codePattern" name="{{code_id}}" ng-i18next="[placeholder]avRegistration.codePlaceholder" required><p class="help-block" ng-i18next="avRegistration.codeHelp"></p><p class="help-block code-help"><span ng-if="allowUserResend && showResendAuthCode() && !sendingData && ((\'sms\' !== method && \'sms-otp\' !== method) || isValidTel)"><b ng-i18next="avRegistration.noCodeReceivedQuestion"></b> <a ng-click="resendAuthCode(field)" ng-i18next="avRegistration.sendCodeAgain"></a> <span></span></span></p><div class="input-error"></div></div></div>'),
$templateCache.put("avRegistration/fields/date-field-directive/date-field-directive.html", '<div class="row"><label ng-if="!label" class="control-label col-sm-4">{{field.name}}</label><label class="control-label col-sm-4" ng-if="label" ng-bind="label"></label><div class="col-sm-8"><select ng-model="date.year" ng-change="onChange()"><option ng-selected="date.year == item" ng-repeat="item in years" ng-value="item">{{item}}</option></select><select ng-model="date.month" ng-change="onChange()"><option ng-selected="date.month == item" ng-repeat="item in months" ng-value="item">{{item}}</option></select><select ng-model="date.day" ng-change="onChange()"><option ng-selected="date.day == item" ng-repeat="item in getDays()" ng-value="item">{{item}}</option></select></div></div>'),
$templateCache.put("avRegistration/fields/dni-field-directive/dni-field-directive.html", '<ng-form name="fieldForm"><div class="form-group" ng-class="{\'has-error\': fieldForm.input.$dirty && fieldForm.input.$invalid}"><label for="input" class="control-label col-sm-4"><span>{{field.name}}</span></label><div class="col-sm-8"><input type="text" name="input" class="form-control" minlength="{{field.min}}" maxlength="{{field.max}}" ng-model="field.value" ng-model-options="{debounce: 500}" ng-disabled="field.disabled" tabindex="{{index}}" ui-validate="{dni: \'validateDni($value)\'}" ng-required="{{field.required}}"><p class="help-block" ng-i18next="avRegistration.dniHelp"></p><div class="input-error"><span class="error text-brand-danger" ng-show="fieldForm.input.$dirty && fieldForm.input.$invalid" ng-i18next="avRegistration.invalidDni"></span></div></div></div></ng-form>'),
$templateCache.put("avRegistration/fields/email-field-directive/email-field-directive.html", '<div class="form-group" ng-class="{true: \'has-error\',false: \'is-required\'}[form.emailText.$dirty && form.emailText.$invalid]"><label for="emailText" class="control-label col-sm-4" ng-i18next="avRegistration.emailLabel"></label><div class="col-sm-8"><input type="text" class="form-control" ng-model="field.value" name="emailText" id="emailText" ng-i18next="[placeholder]avRegistration.emailPlaceholder" tabindex="{{index}}" ng-pattern="patterns(\'email\')" required ng-disabled="field.disabled"><div class="input-error"><small class="error text-danger" ng-show="form.emailText.$dirty && form.emailText.$invalid" ng-i18next="avRegistration.emailError"></small></div></div></div>'),
$templateCache.put("avRegistration/fields/image-field-directive/image-field-directive.html", '<ng-form name="fieldForm"><div class="form-group" ng-class="{\'has-error\': fieldForm.input.$dirty && fieldForm.input.$invalid}"><label for="input" class="control-label col-sm-4"><span>{{field.name}}</span></label><div class="col-sm-8"><input type="file" name="image" id="image-field" class="form-control" ng-disabled="field.disabled" tabindex="{{index}}" ng-required="{{field.required}}"><p class="help-block" ng-i18next="avRegistration.imageHelp"></p><div class="input-error"><span class="error text-brand-danger" ng-show="fieldForm.input.$dirty && fieldForm.input.$invalid" ng-i18next="avRegistration.invalidImage"></span></div></div></div></ng-form>'),
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<script src="avRegistration/patterns-service.js" class="app"></script>
<script src="avRegistration/field-directive/field-directive.js" class="app"></script>
<script src="avRegistration/fields/email-field-directive/email-field-directive.js" class="app"></script>
<script src="avRegistration/fields/date-field-directive/date-field-directive.js" class="app"></script>
<script src="avRegistration/fields/password-field-directive/password-field-directive.js" class="app"></script>
<script src="avRegistration/fields/text-field-directive/text-field-directive.js" class="app"></script>
<script src="avRegistration/fields/dni-field-directive/dni-field-directive.js" class="app"></script>
Expand Down