This is an automated email from the git hooks/post-receive script. New commit to branch feature/dateTimePicker in repository pollen. See http://git.chorem.org/pollen.git commit 1bee25ba052f194ba7f38ea3f5b22573f3892d72 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jul 30 11:34:44 2014 +0200 Improve directive dateTimePicker --- pollen-ui-angular/src/main/webapp/js/directives.js | 54 +++++++++++++++++----- .../src/main/webapp/partials/dateTimePicker.html | 2 +- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index f96a65e..83fc937 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -486,12 +486,15 @@ angular.module('pollenDirective', []) } }]) -.directive("datetimepicker", ["$timeout", "SessionStorage", function ($timeout, SessionStorage) { +.directive("datetimepicker", ["$timeout", "$route", "SessionStorage", function ($timeout, $route, SessionStorage) { return { restrict : "E", scope : { ngModel: '=', - focus: '=' + focus: '=', + minDate: '=', + maxDate: '=', + forId: '@' }, templateUrl:"partials/dateTimePicker.html", link: function(scope, element, attrs) { @@ -500,20 +503,50 @@ angular.module('pollenDirective', []) language: SessionStorage.get().locale }); - if (angular.isDate(scope.ngModel)) { - scope.dateTimePicker.data("DateTimePicker").setDate(new Date(scope.ngModel)); - } + var setDate = function () { + if (angular.isDefined(scope.ngModel)) { + scope.dateTimePicker.data("DateTimePicker").setDate(new Date(scope.ngModel)); + } + }; setDate(); + + var setMinDate = function () { + if (angular.isDefined(scope.minDate)) { + scope.dateTimePicker.data("DateTimePicker").setMinDate(moment(scope.minDate).subtract('day', 1)); + } + }; setMinDate(); scope.$on("switchLocale", function () { - scope.dateTimePicker.data("DateTimePicker").setLanguage(SessionStorage.get().locale); + scope.dateTimePicker.data("DateTimePicker").destroy(); + scope.dateTimePicker.datetimepicker({ + language: SessionStorage.get().locale + }); + setDate(); }) + var setMaxDate = function () { + if (angular.isDefined(scope.maxDate)) { + scope.dateTimePicker.data("DateTimePicker").setMaxDate(moment(scope.maxDate).add('day', 1)); + } + }; setMaxDate(); + $timeout(function () { scope.$watch('ngModel', function (newVal, oldVal) { - if (angular.isDate(newVal) && newVal != oldVal) { - scope.dateTimePicker.data("DateTimePicker").setDate(new Date(newVal)); + if (newVal != oldVal) { + setDate(); } - }) + }); + + scope.$watch('minDate', function (newVal, oldVal) { + if (newVal != oldVal) { + setMinDate(); + } + }); + + scope.$watch('maxDate', function (newVal, oldVal) { + if (newVal != oldVal) { + setMaxDate(); + } + }); }); scope.dateTimePicker.on("dp.change", function(e) { @@ -522,11 +555,10 @@ angular.module('pollenDirective', []) scope.timeout = $timeout(function () { scope.$apply(function () { scope.ngModel = new Date(scope.dateTimePicker.data("DateTimePicker").getDate().format()); + element.trigger("change"); }); }, 500); - element.trigger("change"); - }); scope.exit = function() { diff --git a/pollen-ui-angular/src/main/webapp/partials/dateTimePicker.html b/pollen-ui-angular/src/main/webapp/partials/dateTimePicker.html index a346e6c..857fb78 100644 --- a/pollen-ui-angular/src/main/webapp/partials/dateTimePicker.html +++ b/pollen-ui-angular/src/main/webapp/partials/dateTimePicker.html @@ -1,5 +1,5 @@ <div class="input-group date datetimepicker"> - <input type="text" class="form-control" focus-me="focus" ng-exit="exit()" /> + <input type="text" class="form-control" focus-me="focus" ng-exit="exit()" id="{{forId}}" /> <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span> </span> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.