1
1
angular . module ( 'ui.bootstrap.datepicker' , [ 'ui.bootstrap.dateparser' , 'ui.bootstrap.isClass' , 'ui.bootstrap.position' ] )
2
2
3
3
. value ( '$datepickerSuppressError' , false )
4
+ . value ( 'uibDatepickerAttributeWarning' , true )
4
5
5
6
. constant ( 'uibDatepickerConfig' , {
6
7
datepickerMode : 'day' ,
@@ -21,8 +22,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
21
22
yearRows : 4
22
23
} )
23
24
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 ) {
26
27
var self = this ,
27
28
ngModelCtrl = { $setViewValue : angular . noop } , // nullModelCtrl;
28
29
ngModelOptions = { } ,
@@ -130,15 +131,27 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
130
131
// Interpolated configuration attributes
131
132
angular . forEach ( [ 'formatDay' , 'formatMonth' , 'formatYear' , 'formatDayHeader' , 'formatDayTitle' , 'formatMonthTitle' ] , function ( key ) {
132
133
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
+ }
133
138
} ) ;
134
139
135
140
// Evaled configuration attributes
136
141
angular . forEach ( [ 'showWeeks' , 'yearRows' , 'yearColumns' , 'shortcutPropagation' ] , function ( key ) {
137
142
self [ key ] = angular . isDefined ( $attrs [ key ] ) ?
138
143
$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
+ }
139
148
} ) ;
140
149
141
150
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
+
142
155
self . startingDay = $scope . $parent . $eval ( $attrs . startingDay ) ;
143
156
} else if ( angular . isNumber ( datepickerConfig . startingDay ) ) {
144
157
self . startingDay = datepickerConfig . startingDay ;
@@ -149,6 +162,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
149
162
// Watchable date attributes
150
163
angular . forEach ( [ 'minDate' , 'maxDate' ] , function ( key ) {
151
164
if ( $attrs [ key ] ) {
165
+ if ( datepickerAttributeWarning ) {
166
+ $log . warn ( 'uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead' ) ;
167
+ }
168
+
152
169
watchListeners . push ( $scope . $parent . $watch ( $attrs [ key ] , function ( value ) {
153
170
if ( value ) {
154
171
if ( angular . isDate ( value ) ) {
@@ -169,6 +186,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
169
186
170
187
angular . forEach ( [ 'minMode' , 'maxMode' ] , function ( key ) {
171
188
if ( $attrs [ key ] ) {
189
+ if ( datepickerAttributeWarning ) {
190
+ $log . warn ( 'uib-datepicker ' + key + ' attribute usage is deprecated, use datepicker-options attribute instead' ) ;
191
+ }
192
+
172
193
watchListeners . push ( $scope . $parent . $watch ( $attrs [ key ] , function ( value ) {
173
194
self [ key ] = $scope [ key ] = angular . isDefined ( value ) ? value : $attrs [ key ] ;
174
195
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
182
203
} ) ;
183
204
184
205
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
+
185
210
this . activeDate = dateParser . fromTimezone ( $scope . $parent . $eval ( $attrs . initDate ) , ngModelOptions . timezone ) || new Date ( ) ;
186
211
watchListeners . push ( $scope . $parent . $watch ( $attrs . initDate , function ( initDate ) {
187
212
if ( initDate && ( ngModelCtrl . $isEmpty ( ngModelCtrl . $modelValue ) || ngModelCtrl . $invalid ) ) {
@@ -194,7 +219,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
194
219
}
195
220
}
196
221
197
- $scope . datepickerMode = $scope . datepickerMode || datepickerConfig . datepickerMode ;
222
+ $scope . datepickerMode = $scope . datepickerMode ||
223
+ datepickerConfig . datepickerMode ;
198
224
$scope . uniqueId = 'datepicker-' + $scope . $id + '-' + Math . floor ( Math . random ( ) * 10000 ) ;
199
225
200
226
$scope . disabled = angular . isDefined ( $attrs . disabled ) || false ;
@@ -673,6 +699,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
673
699
} ;
674
700
} )
675
701
702
+ . value ( 'uibDatepickerPopupAttributeWarning' , true )
703
+
676
704
. constant ( 'uibDatepickerPopupConfig' , {
677
705
altInputFormats : [ ] ,
678
706
appendToBody : false ,
@@ -692,8 +720,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
692
720
showButtonBar : true
693
721
} )
694
722
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 ) {
697
725
var cache = { } ,
698
726
isHtml5DateInput = false ;
699
727
var dateFormat , closeOnDateSelection , appendToBody , onOpenFocus ,
@@ -705,14 +733,50 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
705
733
this . init = function ( _ngModel_ ) {
706
734
ngModel = _ngModel_ ;
707
735
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
+ }
714
758
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
+ }
716
780
717
781
if ( datepickerPopupConfig . html5Types [ attrs . type ] ) {
718
782
dateFormat = datepickerPopupConfig . html5Types [ attrs . type ] ;
@@ -774,6 +838,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
774
838
775
839
angular . forEach ( [ 'minMode' , 'maxMode' , 'datepickerMode' , 'shortcutPropagation' ] , function ( key ) {
776
840
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
+
777
845
var getAttribute = $parse ( attrs [ key ] ) ;
778
846
var propConfig = {
779
847
get : function ( ) {
@@ -797,6 +865,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
797
865
798
866
angular . forEach ( [ 'minDate' , 'maxDate' , 'initDate' ] , function ( key ) {
799
867
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
+
800
872
var getAttribute = $parse ( attrs [ key ] ) ;
801
873
802
874
watchListeners . push ( scope . $parent . $watch ( getAttribute , function ( value ) {
@@ -826,6 +898,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
826
898
827
899
angular . forEach ( [ 'formatDay' , 'formatMonth' , 'formatYear' , 'formatDayHeader' , 'formatDayTitle' , 'formatMonthTitle' , 'showWeeks' , 'startingDay' , 'yearRows' , 'yearColumns' ] , function ( key ) {
828
900
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
+
829
905
datepickerEl . attr ( cameltoDash ( key ) , attrs [ key ] ) ;
830
906
}
831
907
} ) ;
0 commit comments