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

Commit a97b364

Browse files
committed
feat(datepicker): add deprecation notices
- Add deprecation notices for datepicker & popup
1 parent 068d181 commit a97b364

File tree

3 files changed

+1543
-13
lines changed

3 files changed

+1543
-13
lines changed

Diff for: 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;
@@ -675,6 +701,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
675701
};
676702
})
677703

704+
.value('uibDatepickerPopupAttributeWarning', true)
705+
678706
.constant('uibDatepickerPopupConfig', {
679707
altInputFormats: [],
680708
appendToBody: false,
@@ -694,8 +722,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
694722
showButtonBar: true
695723
})
696724

697-
.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$parse', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig',
698-
function(scope, element, attrs, $compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig) {
725+
.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$log', '$parse', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig', 'uibDatepickerPopupAttributeWarning',
726+
function(scope, element, attrs, $compile, $log, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig, datepickerPopupAttributeWarning) {
699727
var cache = {},
700728
isHtml5DateInput = false;
701729
var dateFormat, closeOnDateSelection, appendToBody, onOpenFocus,
@@ -707,14 +735,50 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
707735
this.init = function(_ngModel_) {
708736
ngModel = _ngModel_;
709737
ngModelOptions = _ngModel_.$options || datepickerConfig.ngModelOptions;
710-
closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ? scope.$parent.$eval(attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection;
711-
appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ? scope.$parent.$eval(attrs.datepickerAppendToBody) : datepickerPopupConfig.appendToBody;
712-
onOpenFocus = angular.isDefined(attrs.onOpenFocus) ? scope.$parent.$eval(attrs.onOpenFocus) : datepickerPopupConfig.onOpenFocus;
713-
datepickerPopupTemplateUrl = angular.isDefined(attrs.datepickerPopupTemplateUrl) ? attrs.datepickerPopupTemplateUrl : datepickerPopupConfig.datepickerPopupTemplateUrl;
714-
datepickerTemplateUrl = angular.isDefined(attrs.datepickerTemplateUrl) ? attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl;
715-
altInputFormats = angular.isDefined(attrs.altInputFormats) ? scope.$parent.$eval(attrs.altInputFormats) : datepickerPopupConfig.altInputFormats;
738+
if (angular.isDefined(scope.datepickerOptions)) {
739+
closeOnDateSelection = angular.isDefined(scope.datepickerOptions.closeOnDateSelection) ?
740+
scope.datepickerOptions.closeOnDateSelection :
741+
datepickerPopupConfig.closeOnDateSelection;
742+
appendToBody = angular.isDefined(scope.datepickerOptions.datepickerAppendToBody) ?
743+
scope.datepickerOptions.datepickerAppendToBody :
744+
datepickerPopupConfig.datepickerAppendToBody;
745+
onOpenFocus = angular.isDefined(scope.datepickerOptions.onOpenFocus) ?
746+
scope.datepickerOptions.onOpenFocus :
747+
datepickerPopupConfig.onOpenFocus;
748+
datepickerPopupTemplateUrl = angular.isDefined(scope.datepickerOptions.datepickerPopupTemplateUrl) ?
749+
scope.datepickerOptions.datepickerPopupTemplateUrl :
750+
datepickerPopupConfig.datepickerPopupTemplateUrl;
751+
datepickerTemplateUrl = angular.isDefined(scope.datepickerOptions.datepickerTemplateUrl) ?
752+
scope.datepickerOptions.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl;
753+
altInputFormats = angular.isDefined(scope.datepickerOptions.altInputFormats) ?
754+
scope.datepickerOptions.altInputFormats :
755+
datepickerPopupConfig.altInputFormats;
756+
} else {
757+
if (datepickerPopupAttributeWarning) {
758+
$log.warn('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead');
759+
}
716760

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

719783
if (datepickerPopupConfig.html5Types[attrs.type]) {
720784
dateFormat = datepickerPopupConfig.html5Types[attrs.type];
@@ -776,6 +840,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
776840

777841
angular.forEach(['minMode', 'maxMode', 'datepickerMode', 'shortcutPropagation'], function(key) {
778842
if (attrs[key]) {
843+
if (key !== 'datepickerMode' && datepickerPopupAttributeWarning) {
844+
$log.warn('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead');
845+
}
846+
779847
var getAttribute = $parse(attrs[key]);
780848
var propConfig = {
781849
get: function() {
@@ -799,6 +867,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
799867

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

804876
watchListeners.push(scope.$parent.$watch(getAttribute, function(value) {
@@ -828,6 +900,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
828900

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

0 commit comments

Comments
 (0)