Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 86bfc5b

Browse files
committed
feat(datepicker): add customer button click event
1 parent 8e54820 commit 86bfc5b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/datepicker/datepicker.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
296296
scope.closeText = angular.isDefined(text) ? text : datepickerPopupConfig.closeText;
297297
});
298298

299+
if(attrs.onCustomerButtonClick){
300+
var onCustomerButtonClick = $parse(attrs.onCustomerButtonClick);
301+
scope.onCustomerButtonClick = function(){
302+
var param = Array.prototype.slice.call(arguments, 0);
303+
onCustomerButtonClick(originalScope, {$param: param});
304+
};
305+
}
306+
299307
var getIsOpen, setIsOpen;
300308
if ( attrs.isOpen ) {
301309
getIsOpen = $parse(attrs.isOpen);

src/datepicker/test/datepicker.spec.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,10 +1264,11 @@ describe('datepicker directive with empty initial state', function () {
12641264
});
12651265
});
12661266

1267-
describe('',function(){
1267+
describe('customise button group',function(){
12681268
var $rootScope, element, $httpBackend;
12691269

12701270
beforeEach(module('ui.bootstrap.datepicker'));
1271+
beforeEach(module('template/datepicker/datepicker.html'));
12711272
beforeEach(module('template/datepicker/popup.html'));
12721273
beforeEach(inject(function(_$compile_, _$rootScope_,_$httpBackend_) {
12731274
$compile = _$compile_;
@@ -1276,8 +1277,9 @@ describe('',function(){
12761277
}));
12771278

12781279
it("should send request to get customer template", function(){
1280+
$rootScope.onCustomerButtonClick = function(){};
12791281
var templateUrl = "test.html",
1280-
html = '<div><button type="button" ng-click="selectDate(\'2012-01-01\')">Next financial day</button></div>';
1282+
html = '<div><button type="button" ng-click="onCustomerButtonClick(\'next financial\')">Next financial day</button></div>';
12811283
$httpBackend.whenGET(templateUrl).respond(200, html);
12821284
element = $compile('<datepicker-popup-wrap button-group-template-url="' + templateUrl + '"></datepicker-popup-wrap>')($rootScope);
12831285
$rootScope.$digest();
@@ -1286,4 +1288,20 @@ describe('',function(){
12861288
expect(element.find('button').text()).toEqual("Next financial day");
12871289
});
12881290

1291+
it("should send customer click event", function(){
1292+
$rootScope.onCustomerButtonClick = function(){};
1293+
spyOn($rootScope,"onCustomerButtonClick").andCallThrough();
1294+
var templateUrl = "test.html",
1295+
html = '<div><button class="customerBtn" type="button" ng-click="onCustomerButtonClick(\'next financial\')">Next financial day</button></div>';
1296+
$httpBackend.whenGET(templateUrl).respond(200, html);
1297+
element = $compile('<div><input type="text" datepicker-popup="" on-customer-button-click="onCustomerButtonClick($param);" ng-model="dt" button-group-template-url="' + templateUrl + '"/></div>')($rootScope);
1298+
$rootScope.$digest();
1299+
$httpBackend.flush();
1300+
1301+
element.find('.customerBtn').click();
1302+
$rootScope.$digest();
1303+
expect($rootScope.onCustomerButtonClick).toHaveBeenCalledWith(['next financial']);
1304+
});
1305+
1306+
12891307
});

0 commit comments

Comments
 (0)