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

Commit c6ba8d7

Browse files
committedSep 21, 2013
feat(datepicker): add i18n support for bar buttons in popup
Closes #777
1 parent dde804b commit c6ba8d7

File tree

5 files changed

+107
-9
lines changed

5 files changed

+107
-9
lines changed
 

‎src/datepicker/datepicker.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])
253253

254254
.constant('datepickerPopupConfig', {
255255
dateFormat: 'yyyy-MM-dd',
256+
currentText: 'Today',
257+
toggleWeeksText: 'Weeks',
258+
clearText: 'Clear',
259+
closeText: 'Done',
256260
closeOnDateSelection: true
257261
})
258262

@@ -266,12 +270,25 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
266270
var closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ? scope.$eval(attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection;
267271
var dateFormat = attrs.datepickerPopup || datepickerPopupConfig.dateFormat;
268272

269-
// create a child scope for the datepicker directive so we are not polluting original scope
273+
// create a child scope for the datepicker directive so we are not polluting original scope
270274
var scope = originalScope.$new();
271275
originalScope.$on('$destroy', function() {
272276
scope.$destroy();
273277
});
274278

279+
attrs.$observe('currentText', function(text) {
280+
scope.currentText = angular.isDefined(text) ? text : datepickerPopupConfig.currentText;
281+
});
282+
attrs.$observe('toggleWeeksText', function(text) {
283+
scope.toggleWeeksText = angular.isDefined(text) ? text : datepickerPopupConfig.toggleWeeksText;
284+
});
285+
attrs.$observe('clearText', function(text) {
286+
scope.clearText = angular.isDefined(text) ? text : datepickerPopupConfig.clearText;
287+
});
288+
attrs.$observe('closeText', function(text) {
289+
scope.closeText = angular.isDefined(text) ? text : datepickerPopupConfig.closeText;
290+
});
291+
275292
var getIsOpen, setIsOpen;
276293
if ( attrs.isOpen ) {
277294
getIsOpen = $parse(attrs.isOpen);
@@ -431,7 +448,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
431448
};
432449
}])
433450

434-
.directive('datepickerPopupWrap', [function() {
451+
.directive('datepickerPopupWrap', function() {
435452
return {
436453
restrict:'E',
437454
replace: true,
@@ -444,4 +461,4 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
444461
});
445462
}
446463
};
447-
}]);
464+
});

‎src/datepicker/docs/demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77

88
<div class="form-horizontal">
9-
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" />
9+
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
1010
<button class="btn" ng-click="open()"><i class="icon-calendar"></i></button>
1111
</div>
1212

‎src/datepicker/docs/readme.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The datepicker shows dates that come from other than the main month being displa
55

66
Everything is formatted using the [date filter](http://docs.angularjs.org/api/ng.filter:date) and thus is also localized.
77

8-
### Settings ###
8+
### Datepicker Settings ###
99

1010
All settings can be provided as attributes in the `<datepicker>` or globally configured through the `datepickerConfig`.
1111

@@ -60,3 +60,33 @@ All settings can be provided as attributes in the `<datepicker>` or globally con
6060
* `month-title-format`
6161
_(Default: 'yyyy')_ :
6262
Format of title when selecting month.
63+
64+
65+
### Popup Settings ###
66+
67+
Options for datepicker can be passed as JSON using the `datepicker-options` attribute.
68+
Specific settings for the `datepicker-popup` are:
69+
70+
* `datepicker-popup`
71+
_(Default: 'yyyy-MM-dd')_ :
72+
The format for displayed dates.
73+
74+
* `current-text`
75+
_(Default: 'Today')_ :
76+
The text to display for the current day button.
77+
78+
* `toggle-weeks-text`
79+
_(Default: 'Weeks')_ :
80+
The text to display for the toggling week numbers button.
81+
82+
* `clear-text`
83+
_(Default: 'Clear')_ :
84+
The text to display for the clear button.
85+
86+
* `close-text`
87+
_(Default: 'Done')_ :
88+
The text to display for the close button.
89+
90+
* `close-on-date-selection`
91+
_(Default: true)_ :
92+
Whether to close calendar when a date is chosen.

‎src/datepicker/test/datepicker.spec.js

+51
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,57 @@ describe('datepicker directive', function () {
10911091
});
10921092
});
10931093

1094+
describe('button bar', function() {
1095+
var buttons;
1096+
beforeEach(inject(function() {
1097+
assignButtons();
1098+
}));
1099+
1100+
function assignButtons() {
1101+
buttons = dropdownEl.find('li').eq(2).find('button');
1102+
}
1103+
1104+
it('should have four buttons', function() {
1105+
expect(buttons.length).toBe(4);
1106+
1107+
expect(buttons.eq(0).text()).toBe('Today');
1108+
expect(buttons.eq(1).text()).toBe('Weeks');
1109+
expect(buttons.eq(2).text()).toBe('Clear');
1110+
expect(buttons.eq(3).text()).toBe('Done');
1111+
});
1112+
1113+
it('should have a button to clear value', function() {
1114+
buttons.eq(2).click();
1115+
expect($rootScope.date).toBe(null);
1116+
});
1117+
1118+
it('should have a button to close calendar', function() {
1119+
inputEl.focus();
1120+
expect(dropdownEl.css('display')).not.toBe('none');
1121+
1122+
buttons.eq(3).click();
1123+
expect(dropdownEl.css('display')).toBe('none');
1124+
});
1125+
1126+
describe('customization', function() {
1127+
beforeEach(inject(function() {
1128+
$rootScope.clearText = 'Null it!';
1129+
$rootScope.close = 'Close';
1130+
var wrapElement = $compile('<div><input ng-model="date" datepicker-popup current-text="Now" toggle-weeks-text="T.W." clear-text="{{clearText}}" close-text="{{close}}ME"><div>')($rootScope);
1131+
$rootScope.$digest();
1132+
assignElements(wrapElement);
1133+
assignButtons();
1134+
}));
1135+
1136+
it('should change text from attributes', function() {
1137+
expect(buttons.eq(0).text()).toBe('Now');
1138+
expect(buttons.eq(1).text()).toBe('T.W.');
1139+
expect(buttons.eq(2).text()).toBe('Null it!');
1140+
expect(buttons.eq(3).text()).toBe('CloseME');
1141+
});
1142+
});
1143+
});
1144+
10941145
describe('use with `ng-required` directive', function() {
10951146
beforeEach(inject(function() {
10961147
$rootScope.date = '';

‎template/datepicker/popup.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<li class="divider"></li>
44
<li style="padding: 9px;">
55
<span class="btn-group">
6-
<button class="btn btn-small btn-inverse" ng-click="today()">Today</button>
7-
<button class="btn btn-small btn-info" ng-click="showWeeks = ! showWeeks" ng-class="{active: showWeeks}">Weeks</button>
8-
<button class="btn btn-small btn-danger" ng-click="clear()">Clear</button>
6+
<button type="button" class="btn btn-small btn-inverse" ng-click="today()">{{currentText}}</button>
7+
<button type="button" class="btn btn-small btn-info" ng-click="showWeeks = ! showWeeks" ng-class="{active: showWeeks}">{{toggleWeeksText}}</button>
8+
<button type="button" class="btn btn-small btn-danger" ng-click="clear()">{{clearText}}</button>
99
</span>
10-
<button class="btn btn-small btn-success pull-right" ng-click="isOpen = false">Close</button>
10+
<button type="button" class="btn btn-small btn-success pull-right" ng-click="isOpen = false">{{closeText}}</button>
1111
</li>
1212
</ul>

0 commit comments

Comments
 (0)