@@ -3,6 +3,7 @@ class Config
3
3
@firstDayOfWeek = @ _firstDayOfWeek (options .firstDayOfWeek )
4
4
@timeZone = @ _timeZone (options .timeZone )
5
5
@periods = @ _periods (options .periods )
6
+ @customPeriodRanges = @ _customPeriodRanges (options .customPeriodRanges )
6
7
@period = @ _period (options .period )
7
8
@single = @ _single (options .single )
8
9
@opened = @ _opened (options .opened )
@@ -19,6 +20,7 @@ class Config
19
20
@endDate = @ _endDate (options .endDate )
20
21
21
22
@ranges = @ _ranges (options .ranges )
23
+ @isCustomPeriodRangeActive = ko .observable (false )
22
24
23
25
@anchorElement = @ _anchorElement (options .anchorElement )
24
26
@parentElement = @ _parentElement (options .parentElement )
@@ -40,6 +42,11 @@ class Config
40
42
_periods : (val ) ->
41
43
ko .observableArray (val || Period .allPeriods )
42
44
45
+ _customPeriodRanges : (obj ) ->
46
+ obj ||= {}
47
+ for title, value of obj
48
+ @ parseRange (value, title)
49
+
43
50
_period : (val ) ->
44
51
val ||= @ periods ()[0 ]
45
52
throw new Error (' Invalid period' ) unless val in [' day' , ' week' , ' month' , ' quarter' , ' year' ]
@@ -88,15 +95,18 @@ class Config
88
95
when ' custom'
89
96
new CustomDateRange (title)
90
97
else
91
- throw new Error (' Value should be an array' ) unless $ .isArray (value)
92
- [startDate , endDate ] = value
93
- throw new Error (' Missing start date' ) unless startDate
94
- throw new Error (' Missing end date' ) unless endDate
95
- from = MomentUtil .tz (startDate, @ timeZone ())
96
- to = MomentUtil .tz (endDate, @ timeZone ())
97
- throw new Error (' Invalid start date' ) unless from .isValid ()
98
- throw new Error (' Invalid end date' ) unless to .isValid ()
99
- new DateRange (title, from , to)
98
+ @ parseRange (value, title)
99
+
100
+ parseRange : (value , title ) ->
101
+ throw new Error (' Value should be an array' ) unless $ .isArray (value)
102
+ [startDate , endDate ] = value
103
+ throw new Error (' Missing start date' ) unless startDate
104
+ throw new Error (' Missing end date' ) unless endDate
105
+ from = MomentUtil .tz (startDate, @ timeZone ())
106
+ to = MomentUtil .tz (endDate, @ timeZone ())
107
+ throw new Error (' Invalid start date' ) unless from .isValid ()
108
+ throw new Error (' Invalid end date' ) unless to .isValid ()
109
+ new DateRange (title, from , to)
100
110
101
111
_locale : (val ) ->
102
112
$ .extend ({
0 commit comments