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

Commit 10eac7c

Browse files
committed
feat(datepicker): add deprecation notices
- Add deprecation notices for datepicker & popup Closes #5415
1 parent e4fc201 commit 10eac7c

File tree

3 files changed

+1543
-13
lines changed

3 files changed

+1543
-13
lines changed

src/datepicker/datepicker.js

+88-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.isClass', 'ui.bootstrap.position'])
22

33
.value('$datepickerSuppressError', false)
4+
.value('uibDatepickerAttributeWarning', true)
45

56
.constant('uibDatepickerConfig', {
67
datepickerMode: 'day',
@@ -21,8 +22,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
2122
yearRows: 4
2223
})
2324

24-
.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser',
25-
function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) {
25+
.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDatepickerAttributeWarning', 'uibDateParser',
26+
function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerSuppressError, datepickerAttributeWarning, dateParser) {
2627
var self = this,
2728
ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl;
2829
ngModelOptions = {},
@@ -130,15 +131,27 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
130131
// Interpolated configuration attributes
131132
angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle'], function(key) {
132133
self[key] = angular.isDefined($attrs[key]) ? $interpolate($attrs[key])($scope.$parent) : datepickerConfig[key];
134+
135+
if (angular.isDefined($attrs[key]) && datepickerAttributeWarning) {
136+
$log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead');
137+
}
133138
});
134139

135140
// Evaled configuration attributes
136141
angular.forEach(['showWeeks', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) {
137142
self[key] = angular.isDefined($attrs[key]) ?
138143
$scope.$parent.$eval($attrs[key]) : datepickerConfig[key];
144+
145+
if (angular.isDefined($attrs[key]) && datepickerAttributeWarning) {
146+
$log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead');
147+
}
139148
});
140149

141150
if (angular.isDefined($attrs.startingDay)) {
151+
if (datepickerAttributeWarning) {
152+
$log.warn('uib-datepicker startingDay attribute usage is deprecated, use datepicker-options attribute instead');
153+
}
154+
142155
self.startingDay = $scope.$parent.$eval($attrs.startingDay);
143156
} else if (angular.isNumber(datepickerConfig.startingDay)) {
144157
self.startingDay = datepickerConfig.startingDay;
@@ -149,6 +162,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
149162
// Watchable date attributes
150163
angular.forEach(['minDate', 'maxDate'], function(key) {
151164
if ($attrs[key]) {
165+
if (datepickerAttributeWarning) {
166+
$log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead');
167+
}
168+
152169
watchListeners.push($scope.$parent.$watch($attrs[key], function(value) {
153170
if (value) {
154171
if (angular.isDate(value)) {
@@ -169,6 +186,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
169186

170187
angular.forEach(['minMode', 'maxMode'], function(key) {
171188
if ($attrs[key]) {
189+
if (datepickerAttributeWarning) {
190+
$log.warn('uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead');
191+
}
192+
172193
watchListeners.push($scope.$parent.$watch($attrs[key], function(value) {
173194
self[key] = $scope[key] = angular.isDefined(value) ? value : $attrs[key];
174195
if (key === 'minMode' && self.modes.indexOf($scope.datepickerMode) < self.modes.indexOf(self[key]) ||
@@ -182,6 +203,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
182203
});
183204

184205
if (angular.isDefined($attrs.initDate)) {
206+
if (datepickerAttributeWarning) {
207+
$log.warn('uib-datepicker initDate attribute usage is deprecated, use datepicker-options attribute instead');
208+
}
209+
185210
this.activeDate = dateParser.fromTimezone($scope.$parent.$eval($attrs.initDate), ngModelOptions.timezone) || new Date();
186211
watchListeners.push($scope.$parent.$watch($attrs.initDate, function(initDate) {
187212
if (initDate && (ngModelCtrl.$isEmpty(ngModelCtrl.$modelValue) || ngModelCtrl.$invalid)) {
@@ -194,7 +219,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
194219
}
195220
}
196221

197-
$scope.datepickerMode = $scope.datepickerMode || datepickerConfig.datepickerMode;
222+
$scope.datepickerMode = $scope.datepickerMode ||
223+
datepickerConfig.datepickerMode;
198224
$scope.uniqueId = 'datepicker-' + $scope.$id + '-' + Math.floor(Math.random() * 10000);
199225

200226
$scope.disabled = angular.isDefined($attrs.disabled) || false;
@@ -673,6 +699,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
673699
};
674700
})
675701

702+
.value('uibDatepickerPopupAttributeWarning', true)
703+
676704
.constant('uibDatepickerPopupConfig', {
677705
altInputFormats: [],
678706
appendToBody: false,
@@ -692,8 +720,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
692720
showButtonBar: true
693721
})
694722

695-
.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$parse', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig',
696-
function(scope, element, attrs, $compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig) {
723+
.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$log', '$parse', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig', 'uibDatepickerPopupAttributeWarning',
724+
function(scope, element, attrs, $compile, $log, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig, datepickerPopupAttributeWarning) {
697725
var cache = {},
698726
isHtml5DateInput = false;
699727
var dateFormat, closeOnDateSelection, appendToBody, onOpenFocus,
@@ -705,14 +733,50 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
705733
this.init = function(_ngModel_) {
706734
ngModel = _ngModel_;
707735
ngModelOptions = _ngModel_.$options || datepickerConfig.ngModelOptions;
708-
closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ? scope.$parent.$eval(attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection;
709-
appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ? scope.$parent.$eval(attrs.datepickerAppendToBody) : datepickerPopupConfig.appendToBody;
710-
onOpenFocus = angular.isDefined(attrs.onOpenFocus) ? scope.$parent.$eval(attrs.onOpenFocus) : datepickerPopupConfig.onOpenFocus;
711-
datepickerPopupTemplateUrl = angular.isDefined(attrs.datepickerPopupTemplateUrl) ? attrs.datepickerPopupTemplateUrl : datepickerPopupConfig.datepickerPopupTemplateUrl;
712-
datepickerTemplateUrl = angular.isDefined(attrs.datepickerTemplateUrl) ? attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl;
713-
altInputFormats = angular.isDefined(attrs.altInputFormats) ? scope.$parent.$eval(attrs.altInputFormats) : datepickerPopupConfig.altInputFormats;
736+
if (angular.isDefined(scope.datepickerOptions)) {
737+
closeOnDateSelection = angular.isDefined(scope.datepickerOptions.closeOnDateSelection) ?
738+
scope.datepickerOptions.closeOnDateSelection :
739+
datepickerPopupConfig.closeOnDateSelection;
740+
appendToBody = angular.isDefined(scope.datepickerOptions.datepickerAppendToBody) ?
741+
scope.datepickerOptions.datepickerAppendToBody :
742+
datepickerPopupConfig.datepickerAppendToBody;
743+
onOpenFocus = angular.isDefined(scope.datepickerOptions.onOpenFocus) ?
744+
scope.datepickerOptions.onOpenFocus :
745+
datepickerPopupConfig.onOpenFocus;
746+
datepickerPopupTemplateUrl = angular.isDefined(scope.datepickerOptions.datepickerPopupTemplateUrl) ?
747+
scope.datepickerOptions.datepickerPopupTemplateUrl :
748+
datepickerPopupConfig.datepickerPopupTemplateUrl;
749+
datepickerTemplateUrl = angular.isDefined(scope.datepickerOptions.datepickerTemplateUrl) ?
750+
scope.datepickerOptions.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl;
751+
altInputFormats = angular.isDefined(scope.datepickerOptions.altInputFormats) ?
752+
scope.datepickerOptions.altInputFormats :
753+
datepickerPopupConfig.altInputFormats;
754+
} else {
755+
if (datepickerPopupAttributeWarning) {
756+
$log.warn('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead');
757+
}
714758

715-
scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar;
759+
closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ?
760+
scope.$parent.$eval(attrs.closeOnDateSelection) :
761+
datepickerPopupConfig.closeOnDateSelection;
762+
appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ?
763+
scope.$parent.$eval(attrs.datepickerAppendToBody) :
764+
datepickerPopupConfig.appendToBody;
765+
onOpenFocus = angular.isDefined(attrs.onOpenFocus) ?
766+
scope.$parent.$eval(attrs.onOpenFocus) : datepickerPopupConfig.onOpenFocus;
767+
datepickerPopupTemplateUrl = angular.isDefined(attrs.datepickerPopupTemplateUrl) ?
768+
attrs.datepickerPopupTemplateUrl :
769+
datepickerPopupConfig.datepickerPopupTemplateUrl;
770+
datepickerTemplateUrl = angular.isDefined(attrs.datepickerTemplateUrl) ?
771+
attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl;
772+
altInputFormats = angular.isDefined(attrs.altInputFormats) ?
773+
scope.$parent.$eval(attrs.altInputFormats) :
774+
datepickerPopupConfig.altInputFormats;
775+
776+
scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ?
777+
scope.$parent.$eval(attrs.showButtonBar) :
778+
datepickerPopupConfig.showButtonBar;
779+
}
716780

717781
if (datepickerPopupConfig.html5Types[attrs.type]) {
718782
dateFormat = datepickerPopupConfig.html5Types[attrs.type];
@@ -774,6 +838,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
774838

775839
angular.forEach(['minMode', 'maxMode', 'datepickerMode', 'shortcutPropagation'], function(key) {
776840
if (attrs[key]) {
841+
if (key !== 'datepickerMode' && datepickerPopupAttributeWarning) {
842+
$log.warn('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead');
843+
}
844+
777845
var getAttribute = $parse(attrs[key]);
778846
var propConfig = {
779847
get: function() {
@@ -797,6 +865,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
797865

798866
angular.forEach(['minDate', 'maxDate', 'initDate'], function(key) {
799867
if (attrs[key]) {
868+
if (datepickerPopupAttributeWarning) {
869+
$log.warn('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead');
870+
}
871+
800872
var getAttribute = $parse(attrs[key]);
801873

802874
watchListeners.push(scope.$parent.$watch(getAttribute, function(value) {
@@ -826,6 +898,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
826898

827899
angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle', 'showWeeks', 'startingDay', 'yearRows', 'yearColumns'], function(key) {
828900
if (angular.isDefined(attrs[key])) {
901+
if (datepickerPopupAttributeWarning) {
902+
$log.warn('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead');
903+
}
904+
829905
datepickerEl.attr(cameltoDash(key), attrs[key]);
830906
}
831907
});

0 commit comments

Comments
 (0)