From 78dabd2f5ed32301a630cfaba42eebeb9915c202 Mon Sep 17 00:00:00 2001 From: ariesjia Date: Sun, 22 Sep 2013 14:37:04 +0800 Subject: [PATCH 1/4] fix(datepicker): min date, max date today on default view --- .idea/.name | 1 + .idea/bootstrap.iml | 9 + .idea/encodings.xml | 5 + .idea/misc.xml | 5 + .idea/modules.xml | 9 + .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 7 + .idea/workspace.xml | 310 +++++++++++++++++++++++++ src/datepicker/datepicker.js | 7 + src/datepicker/test/datepicker.spec.js | 41 ++++ 10 files changed, 399 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/bootstrap.iml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000000..ac7bcbbf37 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +bootstrap \ No newline at end of file diff --git a/.idea/bootstrap.iml b/.idea/bootstrap.iml new file mode 100644 index 0000000000..6b8184f8ef --- /dev/null +++ b/.idea/bootstrap.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000..e206d70d85 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..1162f43828 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..5eadce65b8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000000..922003b843 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..c80f2198b5 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000000..d345e61289 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,310 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1379831021227 + 1379831021227 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 130ada20d4..4f100fe9be 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -190,6 +190,13 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position']) } else if ( updateSelected ) { selected = date; } + }else{ + if( datepickerCtrl.minDate && datepickerCtrl.minDate > selected ){ + selected = datepickerCtrl.minDate; + } + if( datepickerCtrl.maxDate && datepickerCtrl.maxDate < selected ){ + selected = datepickerCtrl.maxDate; + } } ngModel.$setValidity('date', valid); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 2e81632d5f..8c715b6e6d 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1144,6 +1144,47 @@ describe('datepicker directive', function () { expect(inputEl.val()).toBe('pizza'); }); }); + + describe('max min logic', function() { + var monthNames = [ "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" ], + now = new Date(), + lastYear = now.getFullYear() - 1, + nextYear = now.getFullYear() + 1; + + beforeEach(inject(function() { + $rootScope.maxdate = null; + $rootScope.mindate = null; + $rootScope.date = null; + element = $compile('')($rootScope); + $rootScope.$digest(); + })); + + it('should be show today to default', function() { + expect(getTitle()).toEqual(monthNames[now.getMonth()] + " " + now.getFullYear()); + }); + + it('should be show today to default', function() { + $rootScope.mindate = new Date(lastYear, 8, 1); + $rootScope.maxdate = new Date(nextYear, 8, 1); + $rootScope.$digest(); + expect(getTitle()).toEqual(monthNames[now.getMonth()] + " " + now.getFullYear()); + }); + + it('initial date is min when min after current date', function() { + $rootScope.mindate = new Date(nextYear, 8, 1); + $rootScope.$digest(); + expect(getTitle()).toEqual('September ' + nextYear ); + }); + + it('initial date is max when max before current date', function() { + $rootScope.maxdate = new Date(lastYear, 8, 1); + $rootScope.$digest(); + expect(getTitle()).toEqual('September ' + lastYear); + }); + + }); + }); }); From 2cb71c417555a20ac6780861b4358abb8a92106b Mon Sep 17 00:00:00 2001 From: ariesjia Date: Sun, 22 Sep 2013 14:42:40 +0800 Subject: [PATCH 2/4] chore(idea): remove idea --- .idea/.name | 1 - .idea/bootstrap.iml | 9 - .idea/encodings.xml | 5 - .idea/misc.xml | 5 - .idea/modules.xml | 9 - .idea/scopes/scope_settings.xml | 5 - .idea/vcs.xml | 7 - .idea/workspace.xml | 310 -------------------------------- 8 files changed, 351 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/bootstrap.iml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index ac7bcbbf37..0000000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -bootstrap \ No newline at end of file diff --git a/.idea/bootstrap.iml b/.idea/bootstrap.iml deleted file mode 100644 index 6b8184f8ef..0000000000 --- a/.idea/bootstrap.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index e206d70d85..0000000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 1162f43828..0000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 5eadce65b8..0000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b843..0000000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index c80f2198b5..0000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index d345e61289..0000000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,310 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1379831021227 - 1379831021227 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From a42e36464a754b41d4462c894f7522f7e50e517b Mon Sep 17 00:00:00 2001 From: ariesjia Date: Sun, 22 Sep 2013 17:23:35 +0800 Subject: [PATCH 3/4] feat(datepicker): let button group can be customise --- .gitignore | 1 + src/datepicker/datepicker.js | 29 +++++++++++++++++++-- src/datepicker/test/datepicker.spec.js | 27 +++++++++++++++++++ template/datepicker/popup-button-group.html | 6 +++++ template/datepicker/popup.html | 5 ---- 5 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 template/datepicker/popup-button-group.html diff --git a/.gitignore b/.gitignore index 45aee72754..31afeae887 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ lib-cov *.gz *.swp *.swo +.idea .DS_Store pids diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 1457d8431e..3681716384 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -335,6 +335,10 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon 'ng-model': 'date', 'ng-change': 'dateSelection()' }); + + if (angular.isDefined(attrs.buttonGroupTemplateUrl)) { + popupEl.attr('button-group-template-url', attrs.buttonGroupTemplateUrl); + } var datepickerEl = popupEl.find('datepicker'); if (attrs.datepickerOptions) { datepickerEl.attr(angular.extend({}, originalScope.$eval(attrs.datepickerOptions))); @@ -446,6 +450,9 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon scope.today = function() { $setModelValue(originalScope, new Date()); }; + scope.selectDate = function(date) { + $setModelValue(originalScope, date ? new Date(date) : new Date()); + }; scope.clear = function() { $setModelValue(originalScope, null); }; @@ -455,7 +462,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon }; }]) -.directive('datepickerPopupWrap', function() { +.directive('datepickerPopupWrap',["$compile", function($compile) { return { restrict:'E', replace: true, @@ -466,6 +473,24 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon event.preventDefault(); event.stopPropagation(); }); + var popupEl = angular.element(''); + if (angular.isDefined(attrs.buttonGroupTemplateUrl)) { + popupEl.attr('button-group-template-url', attrs.buttonGroupTemplateUrl); + } + element.find("li").eq(2).prepend($compile(popupEl)(scope)); + } + }; +}]) + +.directive('datepickerPopupButtonGroup',["$parse", "$templateCache", "$http", "$compile", + function($parse, $templateCache, $http, $compile) { + return { + restrict:'AE', + link:function (scope, element, attrs) { + var tplUrl = attrs.buttonGroupTemplateUrl || 'template/datepicker/popup-button-group.html'; + $http.get(tplUrl, {cache: $templateCache}).success(function(tplContent){ + element.replaceWith($compile(tplContent.trim())(scope)); + }); } }; -}); +}]); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 8aa5abeb21..bf5ef90713 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -3,6 +3,7 @@ describe('datepicker directive', function () { beforeEach(module('ui.bootstrap.datepicker')); beforeEach(module('template/datepicker/datepicker.html')); beforeEach(module('template/datepicker/popup.html')); + beforeEach(module('template/datepicker/popup-button-group.html')); beforeEach(inject(function(_$compile_, _$rootScope_) { $compile = _$compile_; $rootScope = _$rootScope_; @@ -1236,6 +1237,8 @@ describe('datepicker directive', function () { }); + + }); }); @@ -1259,4 +1262,28 @@ describe('datepicker directive with empty initial state', function () { it('is shows rows with days', function() { expect(element.find('tbody').find('tr').length).toBeGreaterThan(3); }); +}); + +describe('',function(){ + var $rootScope, element, $httpBackend; + + beforeEach(module('ui.bootstrap.datepicker')); + beforeEach(module('template/datepicker/popup.html')); + beforeEach(inject(function(_$compile_, _$rootScope_,_$httpBackend_) { + $compile = _$compile_; + $rootScope = _$rootScope_; + $httpBackend = _$httpBackend_; + })); + + it("should send request to get customer template", function(){ + var templateUrl = "test.html", + html = '
'; + $httpBackend.whenGET(templateUrl).respond(200, html); + element = $compile('')($rootScope); + $rootScope.$digest(); + $httpBackend.flush(); + + expect(element.find('button').text()).toEqual("Next financial day"); + }); + }); \ No newline at end of file diff --git a/template/datepicker/popup-button-group.html b/template/datepicker/popup-button-group.html new file mode 100644 index 0000000000..c08f660480 --- /dev/null +++ b/template/datepicker/popup-button-group.html @@ -0,0 +1,6 @@ + + + + + diff --git a/template/datepicker/popup.html b/template/datepicker/popup.html index d45be356df..768d31d125 100644 --- a/template/datepicker/popup.html +++ b/template/datepicker/popup.html @@ -2,11 +2,6 @@
  • - - - - -
  • \ No newline at end of file From 86bfc5b9b0d7b042cf11cced8cdd8cbeaa9aee17 Mon Sep 17 00:00:00 2001 From: ariesjia Date: Mon, 23 Sep 2013 10:25:37 +0800 Subject: [PATCH 4/4] feat(datepicker): add customer button click event --- src/datepicker/datepicker.js | 8 ++++++++ src/datepicker/test/datepicker.spec.js | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 3681716384..d11047497c 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -296,6 +296,14 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon scope.closeText = angular.isDefined(text) ? text : datepickerPopupConfig.closeText; }); + if(attrs.onCustomerButtonClick){ + var onCustomerButtonClick = $parse(attrs.onCustomerButtonClick); + scope.onCustomerButtonClick = function(){ + var param = Array.prototype.slice.call(arguments, 0); + onCustomerButtonClick(originalScope, {$param: param}); + }; + } + var getIsOpen, setIsOpen; if ( attrs.isOpen ) { getIsOpen = $parse(attrs.isOpen); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index bf5ef90713..4f9db1f236 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1264,10 +1264,11 @@ describe('datepicker directive with empty initial state', function () { }); }); -describe('',function(){ +describe('customise button group',function(){ var $rootScope, element, $httpBackend; beforeEach(module('ui.bootstrap.datepicker')); + beforeEach(module('template/datepicker/datepicker.html')); beforeEach(module('template/datepicker/popup.html')); beforeEach(inject(function(_$compile_, _$rootScope_,_$httpBackend_) { $compile = _$compile_; @@ -1276,8 +1277,9 @@ describe('',function(){ })); it("should send request to get customer template", function(){ + $rootScope.onCustomerButtonClick = function(){}; var templateUrl = "test.html", - html = '
    '; + html = '
    '; $httpBackend.whenGET(templateUrl).respond(200, html); element = $compile('')($rootScope); $rootScope.$digest(); @@ -1286,4 +1288,20 @@ describe('',function(){ expect(element.find('button').text()).toEqual("Next financial day"); }); + it("should send customer click event", function(){ + $rootScope.onCustomerButtonClick = function(){}; + spyOn($rootScope,"onCustomerButtonClick").andCallThrough(); + var templateUrl = "test.html", + html = '
    '; + $httpBackend.whenGET(templateUrl).respond(200, html); + element = $compile('
    ')($rootScope); + $rootScope.$digest(); + $httpBackend.flush(); + + element.find('.customerBtn').click(); + $rootScope.$digest(); + expect($rootScope.onCustomerButtonClick).toHaveBeenCalledWith(['next financial']); + }); + + }); \ No newline at end of file