diff --git a/app/scripts/datePicker.js b/app/scripts/datePicker.js index 849b1ee..601fe13 100644 --- a/app/scripts/datePicker.js +++ b/app/scripts/datePicker.js @@ -185,6 +185,9 @@ Module.directive('datePicker', ['datePickerConfig', function datePickerDirective }; scope.setDate = function (date) { + if(attrs.disabled) { + return; + } scope.date = date; // change next view var nextView = scope.views[scope.views.indexOf(scope.view) + 1]; diff --git a/app/scripts/dateRange.js b/app/scripts/dateRange.js index b17ef71..38ec101 100644 --- a/app/scripts/dateRange.js +++ b/app/scripts/dateRange.js @@ -9,7 +9,10 @@ Module.directive('dateRange', function () { start: '=', end: '=' }, - link: function (scope) { + link: function (scope, element, attrs) { + attrs.$observe('disabled', function(isDisabled){ + scope.disableDatePickers = !!isDisabled; + }); scope.$watch('start.getTime()', function (value) { if (value && scope.end && value > scope.end.getTime()) { scope.end = new Date(value); diff --git a/app/templates/daterange.html b/app/templates/daterange.html index 3c93641..bdbb6ed 100644 --- a/app/templates/daterange.html +++ b/app/templates/daterange.html @@ -2,10 +2,10 @@
-
+
-
+
diff --git a/dist/index.js b/dist/index.js index 2a5a8ea..c391496 100644 --- a/dist/index.js +++ b/dist/index.js @@ -187,6 +187,9 @@ Module.directive('datePicker', ['datePickerConfig', function datePickerDirective }; scope.setDate = function (date) { + if(attrs.disabled) { + return; + } scope.date = date; // change next view var nextView = scope.views[scope.views.indexOf(scope.view) + 1]; @@ -342,7 +345,10 @@ Module.directive('dateRange', function () { start: '=', end: '=' }, - link: function (scope) { + link: function (scope, element, attrs) { + attrs.$observe('disabled', function(isDisabled){ + scope.disableDatePickers = !!isDisabled; + }); scope.$watch('start.getTime()', function (value) { if (value && scope.end && value > scope.end.getTime()) { scope.end = new Date(value); @@ -729,13 +735,13 @@ angular.module("datePicker").run(["$templateCache", function($templateCache) { "\n" + " \r" + "\n" + - "
\r" + + "
\r" + "\n" + " \r" + "\n" + " \r" + "\n" + - "
\r" + + "
\r" + "\n" + " \r" + "\n" + diff --git a/dist/index.min.js b/dist/index.min.js index 4aefdd3..29eb982 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -"use strict";!function(a){function b(a,b){a=new Date(a||new Date),a=new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours());for(var c=[],d=a.getTime()+36e5;a.getTime()b);){for(var e=[],f=0;7>f;f++)e.push(new Date(a)),a.setDate(a.getDate()+1);d.push(e)}return d}function d(a){var b=[];a=new Date(a||new Date),a.setFullYear(a.getFullYear()-a.getFullYear()%10);for(var c=0;12>c;c++)b.push(new Date(a.getFullYear()+(c-1),0,1));return b}function e(a){a=new Date(a||new Date),a=new Date(a.getFullYear(),a.getMonth(),a.getDate()),a.setDate(a.getDate()-(a.getDay()-1));for(var b=[],c=0;7>c;c++)b.push(new Date(a)),a.setDate(a.getDate()+1);return b}function f(a){a=new Date(a||new Date);for(var b=a.getFullYear(),c=[],d=0;12>d;d++)c.push(new Date(b,d,1));return c}function g(a){a=new Date(a||new Date),a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setMilliseconds(0);for(var b=[],c=0;24>c;c++)b.push(a),a=new Date(a.getTime()+36e5);return b}function h(a,b){return a&&a.getTime()<=b.getTime()}function i(a,b){return a.getTime()>=b.getTime()}function j(a,b){return a&&a.getFullYear()===b.getFullYear()}function k(a,b){return j(a,b)&&a.getMonth()===b.getMonth()}function l(a,b){return k(a,b)&&a.getDate()===b.getDate()}function m(a,b){return l(a,b)&&a.getHours()===b.getHours()}function n(a,b){return m(a,b)&&a.getMinutes()===b.getMinutes()}var o=a.module("datePicker",[]);o.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],step:5}),o.filter("time",function(){function a(a){return("0"+a.getHours()).slice(-2)+":"+("0"+a.getMinutes()).slice(-2)}return function(b){return b instanceof Date||(b=new Date(b),!isNaN(b.getTime()))?a(b):void 0}}),o.directive("datePicker",["datePickerConfig",function(a){return{template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(o,p,q){function r(){var a=o.view,h=o.date;switch(a){case"year":o.years=d(h);break;case"month":o.months=f(h);break;case"date":o.weekdays=o.weekdays||e(),o.weeks=c(h);break;case"hours":o.hours=g(h);break;case"minutes":o.minutes=b(h,t)}}function s(){return"date"!==o.view?o.view:o.model?o.model.getMonth():null}o.date=new Date(o.model||new Date),o.views=a.views.concat(),o.view=q.view||a.view,o.now=new Date,o.template=q.template||a.template;var t=parseInt(q.step||a.step,10),u=!!q.partial;o.views=o.views.slice(o.views.indexOf(q.maxView||"year"),o.views.indexOf(q.minView||"minutes")+1),(1===o.views.length||-1===o.views.indexOf(o.view))&&(o.view=o.views[0]),o.setView=function(a){-1!==o.views.indexOf(a)&&(o.view=a)},o.setDate=function(a){o.date=a;var b=o.views[o.views.indexOf(o.view)+1];if(!b||u||o.model){o.model=new Date(o.model||a);var c=u?"minutes":o.view;switch(c){case"minutes":o.model.setMinutes(a.getMinutes());case"hours":o.model.setHours(a.getHours());case"date":o.model.setDate(a.getDate());case"month":o.model.setMonth(a.getMonth());case"year":o.model.setFullYear(a.getFullYear())}o.$emit("setDate",o.model,o.view)}b&&o.setView(b)},o.$watch(s,r),o.next=function(a){var b=o.date;switch(a=a||1,o.view){case"year":case"month":b.setFullYear(b.getFullYear()+a);break;case"date":b.setMonth(b.getMonth()+a);break;case"hours":case"minutes":b.setHours(b.getHours()+a)}r()},o.prev=function(a){return o.next(-a||-1)},o.isAfter=function(a){return o.after&&h(a,o.after)},o.isBefore=function(a){return o.before&&i(a,o.before)},o.isSameMonth=function(a){return k(o.model,a)},o.isSameYear=function(a){return j(o.model,a)},o.isSameDay=function(a){return l(o.model,a)},o.isSameHour=function(a){return m(o.model,a)},o.isSameMinutes=function(a){return n(o.model,a)},o.isNow=function(a){var b=!0,c=o.now;switch(o.view){case"minutes":b&=~~(a.getMinutes()/t)===~~(c.getMinutes()/t);case"hours":b&=a.getHours()===c.getHours();case"date":b&=a.getDate()===c.getDate();case"month":b&=a.getMonth()===c.getMonth();case"year":b&=a.getFullYear()===c.getFullYear()}return b}}}}]);var o=a.module("datePicker");o.directive("dateRange",function(){return{templateUrl:"templates/daterange.html",scope:{start:"=",end:"="},link:function(a){a.$watch("start.getTime()",function(b){b&&a.end&&b>a.end.getTime()&&(a.end=new Date(b))}),a.$watch("end.getTime()",function(b){b&&a.start&&b'},format:"yyyy-MM-dd HH:mm",views:["date","year","month","hours","minutes"],dismiss:!1,position:"relative"}),o.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),o.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse",function(b,c,d,e,f){var g=c.find("body"),h=d("date");return{require:"ngModel",scope:!0,link:function(c,d,i,j){function k(a){return h(a,r)}function l(){return j.$modelValue}function m(a){a.stopPropagation(),j.$pristine&&(j.$dirty=!0,j.$pristine=!1,d.removeClass(p).addClass(q),s&&s.$setDirty(),j.$render())}function n(){x&&(x.remove(),x=null),z&&(z.remove(),z=null)}function o(){if(!x){if(x=b(A)(c),c.$digest(),c.$on("setDate",function(a,b,c){m(a),w&&t[t.length-1]===c&&n()}),c.$on("$destroy",n),"absolute"===y){var e=a.extend(d.offset(),{height:d[0].offsetHeight});x.css({top:e.top+e.height,left:e.left,display:"block",position:y}),g.append(x)}else z=a.element("
"),d[0].parentElement.insertBefore(z[0],d[0]),z.append(x),x.css({top:d[0].offsetHeight+"px",display:"block"});x.bind("mousedown",function(a){a.preventDefault()})}}var r=i.format||e.format,s=d.inheritedData("$formController"),t=f(i.views)(c)||e.views.concat(),u=i.view||t[0],v=t.indexOf(u),w=i.dismiss?f(i.dismiss)(c):e.dismiss,x=null,y=i.position||e.position,z=null;-1===v&&t.splice(v,1),t.unshift(u),j.$formatters.push(k),j.$parsers.unshift(l);var A=e.template(i);d.bind("focus",o),d.bind("blur",n)}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{date|date:"yyyy MMMM"}}
{{ day|date:"EEE" }}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{years[0].getFullYear()}}-{{years[years.length-1].getFullYear()}}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{ date|date:"yyyy" }}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{ date|date:"dd MMMM yyyy" }}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{ date|date:"dd MMMM yyyy" }}\r\n
\r\n \r\n
\r\n
\r\n
\r\n'),a.put("templates/daterange.html",'
\r\n \r\n \r\n \r\n \r\n \r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n')}])}(angular); \ No newline at end of file +"use strict";!function(a){function b(a,b){a=new Date(a||new Date),a=new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours());for(var c=[],d=a.getTime()+36e5;a.getTime()b);){for(var e=[],f=0;7>f;f++)e.push(new Date(a)),a.setDate(a.getDate()+1);d.push(e)}return d}function d(a){var b=[];a=new Date(a||new Date),a.setFullYear(a.getFullYear()-a.getFullYear()%10);for(var c=0;12>c;c++)b.push(new Date(a.getFullYear()+(c-1),0,1));return b}function e(a){a=new Date(a||new Date),a=new Date(a.getFullYear(),a.getMonth(),a.getDate()),a.setDate(a.getDate()-(a.getDay()-1));for(var b=[],c=0;7>c;c++)b.push(new Date(a)),a.setDate(a.getDate()+1);return b}function f(a){a=new Date(a||new Date);for(var b=a.getFullYear(),c=[],d=0;12>d;d++)c.push(new Date(b,d,1));return c}function g(a){a=new Date(a||new Date),a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setMilliseconds(0);for(var b=[],c=0;24>c;c++)b.push(a),a=new Date(a.getTime()+36e5);return b}function h(a,b){return a&&a.getTime()<=b.getTime()}function i(a,b){return a.getTime()>=b.getTime()}function j(a,b){return a&&a.getFullYear()===b.getFullYear()}function k(a,b){return j(a,b)&&a.getMonth()===b.getMonth()}function l(a,b){return k(a,b)&&a.getDate()===b.getDate()}function m(a,b){return l(a,b)&&a.getHours()===b.getHours()}function n(a,b){return m(a,b)&&a.getMinutes()===b.getMinutes()}var o=a.module("datePicker",[]);o.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],step:5}),o.filter("time",function(){function a(a){return("0"+a.getHours()).slice(-2)+":"+("0"+a.getMinutes()).slice(-2)}return function(b){return b instanceof Date||(b=new Date(b),!isNaN(b.getTime()))?a(b):void 0}}),o.directive("datePicker",["datePickerConfig",function(a){return{template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(o,p,q){function r(){var a=o.view,h=o.date;switch(a){case"year":o.years=d(h);break;case"month":o.months=f(h);break;case"date":o.weekdays=o.weekdays||e(),o.weeks=c(h);break;case"hours":o.hours=g(h);break;case"minutes":o.minutes=b(h,t)}}function s(){return"date"!==o.view?o.view:o.model?o.model.getMonth():null}o.date=new Date(o.model||new Date),o.views=a.views.concat(),o.view=q.view||a.view,o.now=new Date,o.template=q.template||a.template;var t=parseInt(q.step||a.step,10),u=!!q.partial;o.views=o.views.slice(o.views.indexOf(q.maxView||"year"),o.views.indexOf(q.minView||"minutes")+1),(1===o.views.length||-1===o.views.indexOf(o.view))&&(o.view=o.views[0]),o.setView=function(a){-1!==o.views.indexOf(a)&&(o.view=a)},o.setDate=function(a){if(!q.disabled){o.date=a;var b=o.views[o.views.indexOf(o.view)+1];if(!b||u||o.model){o.model=new Date(o.model||a);var c=u?"minutes":o.view;switch(c){case"minutes":o.model.setMinutes(a.getMinutes());case"hours":o.model.setHours(a.getHours());case"date":o.model.setDate(a.getDate());case"month":o.model.setMonth(a.getMonth());case"year":o.model.setFullYear(a.getFullYear())}o.$emit("setDate",o.model,o.view)}b&&o.setView(b)}},o.$watch(s,r),o.next=function(a){var b=o.date;switch(a=a||1,o.view){case"year":case"month":b.setFullYear(b.getFullYear()+a);break;case"date":b.setMonth(b.getMonth()+a);break;case"hours":case"minutes":b.setHours(b.getHours()+a)}r()},o.prev=function(a){return o.next(-a||-1)},o.isAfter=function(a){return o.after&&h(a,o.after)},o.isBefore=function(a){return o.before&&i(a,o.before)},o.isSameMonth=function(a){return k(o.model,a)},o.isSameYear=function(a){return j(o.model,a)},o.isSameDay=function(a){return l(o.model,a)},o.isSameHour=function(a){return m(o.model,a)},o.isSameMinutes=function(a){return n(o.model,a)},o.isNow=function(a){var b=!0,c=o.now;switch(o.view){case"minutes":b&=~~(a.getMinutes()/t)===~~(c.getMinutes()/t);case"hours":b&=a.getHours()===c.getHours();case"date":b&=a.getDate()===c.getDate();case"month":b&=a.getMonth()===c.getMonth();case"year":b&=a.getFullYear()===c.getFullYear()}return b}}}}]);var o=a.module("datePicker");o.directive("dateRange",function(){return{templateUrl:"templates/daterange.html",scope:{start:"=",end:"="},link:function(a,b,c){c.$observe("disabled",function(b){a.disableDatePickers=!!b}),a.$watch("start.getTime()",function(b){b&&a.end&&b>a.end.getTime()&&(a.end=new Date(b))}),a.$watch("end.getTime()",function(b){b&&a.start&&b'},format:"yyyy-MM-dd HH:mm",views:["date","year","month","hours","minutes"],dismiss:!1,position:"relative"}),o.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),o.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse",function(b,c,d,e,f){var g=c.find("body"),h=d("date");return{require:"ngModel",scope:!0,link:function(c,d,i,j){function k(a){return h(a,r)}function l(){return j.$modelValue}function m(a){a.stopPropagation(),j.$pristine&&(j.$dirty=!0,j.$pristine=!1,d.removeClass(p).addClass(q),s&&s.$setDirty(),j.$render())}function n(){x&&(x.remove(),x=null),z&&(z.remove(),z=null)}function o(){if(!x){if(x=b(A)(c),c.$digest(),c.$on("setDate",function(a,b,c){m(a),w&&t[t.length-1]===c&&n()}),c.$on("$destroy",n),"absolute"===y){var e=a.extend(d.offset(),{height:d[0].offsetHeight});x.css({top:e.top+e.height,left:e.left,display:"block",position:y}),g.append(x)}else z=a.element("
"),d[0].parentElement.insertBefore(z[0],d[0]),z.append(x),x.css({top:d[0].offsetHeight+"px",display:"block"});x.bind("mousedown",function(a){a.preventDefault()})}}var r=i.format||e.format,s=d.inheritedData("$formController"),t=f(i.views)(c)||e.views.concat(),u=i.view||t[0],v=t.indexOf(u),w=i.dismiss?f(i.dismiss)(c):e.dismiss,x=null,y=i.position||e.position,z=null;-1===v&&t.splice(v,1),t.unshift(u),j.$formatters.push(k),j.$parsers.unshift(l);var A=e.template(i);d.bind("focus",o),d.bind("blur",n)}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{date|date:"yyyy MMMM"}}
{{ day|date:"EEE" }}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{years[0].getFullYear()}}-{{years[years.length-1].getFullYear()}}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{ date|date:"yyyy" }}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{ date|date:"dd MMMM yyyy" }}
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
{{ date|date:"dd MMMM yyyy" }}\r\n
\r\n \r\n
\r\n
\r\n
\r\n'),a.put("templates/daterange.html",'
\r\n \r\n \r\n \r\n \r\n \r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n')}])}(angular); \ No newline at end of file