This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit 5cfefb86ca1a22cb0fe358579035d8774320f7c6 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue Aug 5 18:19:06 2014 +0200 Improve directive auto-save --- pollen-ui-angular/src/main/webapp/js/directives.js | 53 ++++++++++++++++------ 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/directives.js b/pollen-ui-angular/src/main/webapp/js/directives.js index 451aa94..92b4eb7 100644 --- a/pollen-ui-angular/src/main/webapp/js/directives.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -208,19 +208,19 @@ angular.module('pollenDirective', []) $timeout(function () { scope.oldVal[attrs.ngModel] = scope.$eval(attrs.ngModel); scope.$watch(attrs.ngModel, function (newVal, oldVal) { - if (angular.isDefined(oldVal) && newVal != scope.oldVal[attrs.ngModel]) { + if (scope.$eval(attrs.ngModel) != scope.oldVal[attrs.ngModel]) { scope.change = true; } else { scope.change = false; } }, true); - }, 500); + }); var save = function () { - if (scope.change) { - scope.change = false; - scope.oldVal[attrs.ngModel] = scope.$eval(attrs.ngModel);; + if (scope.change && !scope.lock) { scope.$apply(function () { + scope.change = false; + scope.oldVal[attrs.ngModel] = scope.$eval(attrs.ngModel);; scope.$eval(attrs.autoSave); }); } @@ -233,6 +233,29 @@ angular.module('pollenDirective', []) scope.timeout = $timeout(save,1000); }); + element.bind('dp.change', function(newDate) { + try { + scope.$digest(); + } + catch (e) { + } + }); + + element.bind('dp.show', function() { + console.log('is open'); + scope.lock = true; + + }) + + element.bind('dp.hide', function () { + scope.lock = false; + if (scope.timeout) { + $timeout.cancel(scope.timeout); + } + + scope.timeout = $timeout(save, 100); + }) + element.bind('blur', function () { if (scope.timeout) { $timeout.cancel(scope.timeout) @@ -486,6 +509,10 @@ angular.module('pollenDirective', []) } }]) +///////////////////////////////////////////////////////// +// DATE TIME PICKER DIRECTIVE // +// http://eonasdan.github.io/bootstrap-datetimepicker/ // +///////////////////////////////////////////////////////// .directive("datetimepicker", ["$timeout", "$route", "SessionStorage", function ($timeout, $route, SessionStorage) { return { restrict : "E", @@ -549,16 +576,14 @@ angular.module('pollenDirective', []) }); }); - scope.dateTimePicker.on("dp.change", function(e) { - $timeout.cancel(scope.timeout); - - scope.timeout = $timeout(function () { - scope.$apply(function () { - scope.ngModel = new Date(scope.dateTimePicker.data("DateTimePicker").getDate().format()); - element.trigger("change"); - }); - }, 500); + scope.dateTimePicker.on("dp.show", function (e) { + if (angular.isUndefined(scope.ngModel) || scope.ngModel == null) { + scope.ngModel = scope.dateTimePicker.data("DateTimePicker").setDate(moment()); + } + }) + scope.dateTimePicker.on("dp.change", function(e) { + scope.ngModel = new Date(scope.dateTimePicker.data("DateTimePicker").getDate().format()).getTime(); }); scope.exit = function() { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.