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 ;
@@ -675,6 +701,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
675
701
} ;
676
702
} )
677
703
704
+ . value ( 'uibDatepickerPopupAttributeWarning' , true )
705
+
678
706
. constant ( 'uibDatepickerPopupConfig' , {
679
707
altInputFormats : [ ] ,
680
708
appendToBody : false ,
@@ -694,8 +722,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
694
722
showButtonBar : true
695
723
} )
696
724
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 ) {
699
727
var cache = { } ,
700
728
isHtml5DateInput = false ;
701
729
var dateFormat , closeOnDateSelection , appendToBody , onOpenFocus ,
@@ -707,14 +735,50 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
707
735
this . init = function ( _ngModel_ ) {
708
736
ngModel = _ngModel_ ;
709
737
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
+ }
716
760
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
+ }
718
782
719
783
if ( datepickerPopupConfig . html5Types [ attrs . type ] ) {
720
784
dateFormat = datepickerPopupConfig . html5Types [ attrs . type ] ;
@@ -776,6 +840,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
776
840
777
841
angular . forEach ( [ 'minMode' , 'maxMode' , 'datepickerMode' , 'shortcutPropagation' ] , function ( key ) {
778
842
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
+
779
847
var getAttribute = $parse ( attrs [ key ] ) ;
780
848
var propConfig = {
781
849
get : function ( ) {
@@ -799,6 +867,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
799
867
800
868
angular . forEach ( [ 'minDate' , 'maxDate' , 'initDate' ] , function ( key ) {
801
869
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
+
802
874
var getAttribute = $parse ( attrs [ key ] ) ;
803
875
804
876
watchListeners . push ( scope . $parent . $watch ( getAttribute , function ( value ) {
@@ -828,6 +900,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
828
900
829
901
angular . forEach ( [ 'formatDay' , 'formatMonth' , 'formatYear' , 'formatDayHeader' , 'formatDayTitle' , 'formatMonthTitle' , 'showWeeks' , 'startingDay' , 'yearRows' , 'yearColumns' ] , function ( key ) {
830
902
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
+
831
907
datepickerEl . attr ( cameltoDash ( key ) , attrs [ key ] ) ;
832
908
}
833
909
} ) ;
0 commit comments