This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository chorem. See http://git.chorem.org/chorem.git commit 1b5889ed149f5f841285f36b758679c406ea3523 Author: kootox <jean.couteau@gmail.com> Date: Thu Mar 26 14:45:01 2015 +0100 Fix too quick angularjs update -> copy ui-date into sources and allowGlobals on salesFunnel module --- .../WEB-INF/jsp/salesReports/salesFunnel.jsp | 4 +- chorem-webmotion/src/main/webapp/js/salesFunnel.js | 4 +- chorem-webmotion/src/main/webapp/js/ui-date.js | 157 +++++++++++++++++++++ 3 files changed, 162 insertions(+), 3 deletions(-) diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp index 0897f00..1479711 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/salesReports/salesFunnel.jsp @@ -23,9 +23,9 @@ <head> <link rel="stylesheet/less" href="<c:url value='/css/chorem-sales.css'/>"> - <script type="text/javascript" src="<c:url value='/js/salesFunnel.js'/>"></script> + <script type="text/javascript" src="<c:url value='/js/ui-date.js'/>"></script> <script type="text/javascript" src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.2.js"></script> - <script type="text/javascript" src="https://raw.github.com/angular-ui/ui-date/master/src/date.js"></script> + <script type="text/javascript" src="<c:url value='/js/salesFunnel.js'/>"></script> </head> <body> diff --git a/chorem-webmotion/src/main/webapp/js/salesFunnel.js b/chorem-webmotion/src/main/webapp/js/salesFunnel.js index 66233ce..0988baf 100644 --- a/chorem-webmotion/src/main/webapp/js/salesFunnel.js +++ b/chorem-webmotion/src/main/webapp/js/salesFunnel.js @@ -18,7 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -var salesFunnel = angular.module('salesFunnel', ['wikitty', 'ui.bootstrap', 'ui.date']); +var salesFunnel = angular.module('salesFunnel', ['wikitty', 'ui.bootstrap', 'ui.date']).config(["$controllerProvider", function($controllerProvider) { + $controllerProvider.allowGlobals(); +}]); salesFunnel.directive('datepicker', function() { return { diff --git a/chorem-webmotion/src/main/webapp/js/ui-date.js b/chorem-webmotion/src/main/webapp/js/ui-date.js new file mode 100644 index 0000000..a6d8e97 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/js/ui-date.js @@ -0,0 +1,157 @@ +/*global angular */ +/* + jQuery UI Datepicker plugin wrapper + + @note If ≤ IE8 make sure you have a polyfill for Date.toISOString() + @param [ui-date] {object} Options to pass to $.fn.datepicker() merged onto uiDateConfig + */ + +angular.module('ui.date', []) + +.constant('uiDateConfig', {}) + +.directive('uiDate', ['uiDateConfig', 'uiDateConverter', function (uiDateConfig, uiDateConverter) { + 'use strict'; + var options; + options = {}; + angular.extend(options, uiDateConfig); + return { + require:'?ngModel', + link:function (scope, element, attrs, controller) { + var getOptions = function () { + return angular.extend({}, uiDateConfig, scope.$eval(attrs.uiDate)); + }; + var initDateWidget = function () { + var showing = false; + var opts = getOptions(); + + // If we have a controller (i.e. ngModelController) then wire it up + if (controller) { + + // Set the view value in a $apply block when users selects + // (calling directive user's function too if provided) + var _onSelect = opts.onSelect || angular.noop; + opts.onSelect = function (value, picker) { + scope.$apply(function() { + showing = true; + controller.$setViewValue(element.datepicker('getDate')); + _onSelect(value, picker); + element.blur(); + }); + }; + + var _beforeShow = opts.beforeShow || angular.noop; + opts.beforeShow = function(input, picker) { + showing = true; + _beforeShow(input, picker); + }; + + var _onClose = opts.onClose || angular.noop; + opts.onClose = function(value, picker) { + showing = false; + _onClose(value, picker); + }; + element.off('blur.datepicker').on('blur.datepicker', function() { + if ( !showing ) { + scope.$apply(function() { + element.datepicker('setDate', element.datepicker('getDate')); + controller.$setViewValue(element.datepicker('getDate')); + }); + } + }); + + // Update the date picker when the model changes + controller.$render = function () { + var date = controller.$modelValue; + if ( angular.isDefined(date) && date !== null && !angular.isDate(date) ) { + if ( angular.isString(controller.$modelValue) ) { + date = uiDateConverter.stringToDate(attrs.uiDateFormat, controller.$modelValue); + } else { + throw new Error('ng-Model value must be a Date, or a String object with a date formatter - currently it is a ' + typeof date + ' - use ui-date-format to convert it from a string'); + } + } + element.datepicker('setDate', date); + }; + } + // Check if the element already has a datepicker. + if (element.data('datepicker')) { + // Updates the datepicker options + element.datepicker('option', opts); + element.datepicker('refresh'); + } else { + // Creates the new datepicker widget + element.datepicker(opts); + + //Cleanup on destroy, prevent memory leaking + element.on('$destroy', function () { + element.datepicker('destroy'); + }); + } + + if ( controller ) { + // Force a render to override whatever is in the input text box + controller.$render(); + } + }; + // Watch for changes to the directives options + scope.$watch(getOptions, initDateWidget, true); + } + }; +} +]) +.factory('uiDateConverter', ['uiDateFormatConfig', function(uiDateFormatConfig){ + + function dateToString(dateFormat, value){ + dateFormat = dateFormat || uiDateFormatConfig; + if (value) { + if (dateFormat) { + return jQuery.datepicker.formatDate(dateFormat, value); + } + + if (value.toISOString) { + return value.toISOString(); + } + } + return null; + } + + function stringToDate(dateFormat, value) { + dateFormat = dateFormat || uiDateFormatConfig; + if ( angular.isString(value) ) { + if (dateFormat) { + return jQuery.datepicker.parseDate(dateFormat, value); + } + + var isoDate = new Date(value); + return isNaN(isoDate.getTime()) ? null : isoDate; + } + return null; + } + + return { + stringToDate: stringToDate, + dateToString: dateToString + }; + +}]) +.constant('uiDateFormatConfig', '') +.directive('uiDateFormat', ['uiDateConverter', function(uiDateConverter) { + var directive = { + require:'ngModel', + link: function(scope, element, attrs, modelCtrl) { + var dateFormat = attrs.uiDateFormat; + + // Use the datepicker with the attribute value as the dateFormat string to convert to and from a string + modelCtrl.$formatters.unshift(function(value) { + return uiDateConverter.stringToDate(dateFormat, value); + }); + + modelCtrl.$parsers.push(function(value){ + return uiDateConverter.dateToString(dateFormat, value); + }); + + } + }; + + return directive; +}]); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.