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

Commit 4d158e0

Browse files
committedNov 27, 2013
feat(datepicker): option whether to display button bar in popup
1 parent 9ec2128 commit 4d158e0

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed
 

‎src/datepicker/datepicker.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])
258258
clearText: 'Clear',
259259
closeText: 'Done',
260260
closeOnDateSelection: true,
261-
appendToBody: false
261+
appendToBody: false,
262+
showButtonBar: true
262263
})
263264

264265
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'datepickerPopupConfig', 'datepickerConfig',
@@ -267,17 +268,17 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
267268
restrict: 'EA',
268269
require: 'ngModel',
269270
link: function(originalScope, element, attrs, ngModel) {
270-
var dateFormat;
271+
var scope = originalScope.$new(), // create a child scope so we are not polluting original one
272+
dateFormat,
273+
closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ? originalScope.$eval(attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection,
274+
appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ? originalScope.$eval(attrs.datepickerAppendToBody) : datepickerPopupConfig.appendToBody;
275+
271276
attrs.$observe('datepickerPopup', function(value) {
272277
dateFormat = value || datepickerPopupConfig.dateFormat;
273278
ngModel.$render();
274279
});
275280

276-
var closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ? originalScope.$eval(attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection;
277-
var appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ? originalScope.$eval(attrs.datepickerAppendToBody) : datepickerPopupConfig.appendToBody;
278-
279-
// create a child scope for the datepicker directive so we are not polluting original scope
280-
var scope = originalScope.$new();
281+
scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? originalScope.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar;
281282

282283
originalScope.$on('$destroy', function() {
283284
scope.$destroy();

‎src/datepicker/docs/readme.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Everything is formatted using the [date filter](http://docs.angularjs.org/api/ng
77

88
### Datepicker Settings ###
99

10-
All settings can be provided as attributes in the `<datepicker>` or globally configured through the `datepickerConfig`. `datepicker-popup` options may be provided as attributes in the `datepicker-popup`'s element, or globally configured through the `datepickerPopupConfig`.
10+
All settings can be provided as attributes in the `<datepicker>` or globally configured through the `datepickerConfig`.
11+
1112
* `ng-model` <i class="icon-eye-open"></i>
1213
:
1314
The date object.
@@ -64,12 +65,16 @@ All settings can be provided as attributes in the `<datepicker>` or globally con
6465
### Popup Settings ###
6566

6667
Options for datepicker can be passed as JSON using the `datepicker-options` attribute.
67-
Specific settings for the `datepicker-popup` are:
68+
Specific settings for the `datepicker-popup`, that can globally configured through the `datepickerPopupConfig`, are:
6869

6970
* `datepicker-popup`
7071
_(Default: 'yyyy-MM-dd')_ :
7172
The format for displayed dates.
7273

74+
* `show-button-bar`
75+
_(Default: true)_ :
76+
Whether to display a button bar underneath the datepicker.
77+
7378
* `current-text`
7479
_(Default: 'Today')_ :
7580
The text to display for the current day button.
@@ -89,7 +94,7 @@ Specific settings for the `datepicker-popup` are:
8994
* `close-on-date-selection`
9095
_(Default: true)_ :
9196
Whether to close calendar when a date is chosen.
92-
97+
9398
* `datepicker-append-to-body`
9499
_(Default: false)_:
95100
Append the datepicker popup element to `body`, rather than inserting after `datepicker-popup`. For global configuration, use `datepickerPopupConfig.appendToBody`.

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

+16-6
Original file line numberDiff line numberDiff line change
@@ -1137,15 +1137,20 @@ describe('datepicker directive', function () {
11371137
});
11381138

11391139
describe('button bar', function() {
1140-
var buttons;
1140+
var buttons, buttonBarElement;
11411141
beforeEach(inject(function() {
1142-
assignButtons();
1142+
assignButtonBar();
11431143
}));
11441144

1145-
function assignButtons() {
1146-
buttons = dropdownEl.find('li').eq(2).find('button');
1145+
function assignButtonBar() {
1146+
buttonBarElement = dropdownEl.find('li').eq(-1);
1147+
buttons = buttonBarElement.find('button');
11471148
}
11481149

1150+
it('should be visible', function() {
1151+
expect(buttonBarElement.css('display')).not.toBe('none');
1152+
});
1153+
11491154
it('should have four buttons', function() {
11501155
expect(buttons.length).toBe(4);
11511156

@@ -1170,12 +1175,13 @@ describe('datepicker directive', function () {
11701175

11711176
describe('customization', function() {
11721177
beforeEach(inject(function() {
1178+
$rootScope.showBar = false;
11731179
$rootScope.clearText = 'Null it!';
11741180
$rootScope.close = 'Close';
1175-
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);
1181+
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" show-button-bar="showBar"><div>')($rootScope);
11761182
$rootScope.$digest();
11771183
assignElements(wrapElement);
1178-
assignButtons();
1184+
assignButtonBar();
11791185
}));
11801186

11811187
it('should change text from attributes', function() {
@@ -1184,6 +1190,10 @@ describe('datepicker directive', function () {
11841190
expect(buttons.eq(2).text()).toBe('Null it!');
11851191
expect(buttons.eq(3).text()).toBe('CloseME');
11861192
});
1193+
1194+
it('should hide bar', function() {
1195+
expect(buttonBarElement.css('display')).toBe('none');
1196+
});
11871197
});
11881198
});
11891199

‎template/datepicker/popup.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<ul class="dropdown-menu" ng-style="{display: (isOpen && 'block') || 'none', top: position.top+'px', left: position.left+'px'}">
22
<li ng-transclude></li>
3-
<li class="divider"></li>
4-
<li style="padding: 9px;">
3+
<li ng-show="showButtonBar" style="padding:10px 9px 2px">
54
<span class="btn-group">
65
<button type="button" class="btn btn-small btn-inverse" ng-click="today()">{{currentText}}</button>
76
<button type="button" class="btn btn-small btn-info" ng-click="showWeeks = ! showWeeks" ng-class="{active: showWeeks}">{{toggleWeeksText}}</button>

0 commit comments

Comments
 (0)