@@ -17,6 +17,7 @@ class RecurringSelectDialog {
17
17
this . daysChanged = this . daysChanged . bind ( this ) ;
18
18
this . dateOfMonthChanged = this . dateOfMonthChanged . bind ( this ) ;
19
19
this . weekOfMonthChanged = this . weekOfMonthChanged . bind ( this ) ;
20
+ this . terminationChanged = this . terminationChanged . bind ( this ) ;
20
21
this . recurring_selector = recurring_selector ;
21
22
this . current_rule = this . recurring_selector . recurring_select ( 'current_rule' ) ;
22
23
this . initDialogBox ( ) ;
@@ -41,9 +42,12 @@ class RecurringSelectDialog {
41
42
42
43
this . mainEventInit ( ) ;
43
44
this . freqInit ( ) ;
45
+ this . terminationInit ( ) ;
44
46
this . summaryInit ( ) ;
47
+
45
48
trigger ( this . outer_holder , "recurring_select:dialog_opened" ) ;
46
49
this . freq_select . focus ( ) ;
50
+
47
51
}
48
52
49
53
cancel ( ) {
@@ -134,9 +138,9 @@ class RecurringSelectDialog {
134
138
interval_input . value = this . current_rule . hash . interval
135
139
on ( interval_input , "change keyup" , this . intervalChanged )
136
140
137
- if ( ! this . current_rule . hash . validations ) { this . current_rule . hash . validations = { } } ;
138
- if ( ! this . current_rule . hash . validations . day_of_month ) { this . current_rule . hash . validations . day_of_month = [ ] } ;
139
- if ( ! this . current_rule . hash . validations . day_of_week ) { this . current_rule . hash . validations . day_of_week = { } } ;
141
+ if ( ! this . current_rule . hash . validations ) { this . current_rule . hash . validations = { } ; }
142
+ if ( ! this . current_rule . hash . validations . day_of_month ) { this . current_rule . hash . validations . day_of_month = [ ] ; }
143
+ if ( ! this . current_rule . hash . validations . day_of_week ) { this . current_rule . hash . validations . day_of_week = { } ; }
140
144
this . init_calendar_days ( section ) ;
141
145
this . init_calendar_weeks ( section ) ;
142
146
@@ -156,6 +160,40 @@ class RecurringSelectDialog {
156
160
section . style . display = 'block'
157
161
}
158
162
163
+ terminationInit ( ) {
164
+ const section = this . outer_holder . querySelector ( ".rs_termination_section" ) ;
165
+ this . until_date = section . querySelector ( "#rs_until_date" ) ;
166
+ this . until_date . flatpickr ( {
167
+ enableTime : true ,
168
+ dateFormat : "Y-m-d H:i" ,
169
+ altInput : true ,
170
+ altFormat : "F j, Y h:i K" ,
171
+ } ) ;
172
+
173
+ if ( this . current_rule . hash && this . current_rule . hash . count ) {
174
+ this . count_option = section . querySelector ( "input[name=rs_termination][value=count]" ) ;
175
+ this . count_option . checked = true ;
176
+ this . occurence_count = section . querySelector ( "#rs_occurrence_count" ) ;
177
+ this . occurence_count . value = this . current_rule . hash . count ;
178
+ } else if ( this . current_rule . hash && this . current_rule . hash . until ) {
179
+ this . until_option = section . querySelector ( "input[name=rs_termination][value=until]" ) ;
180
+ this . until_option . checked = true ;
181
+ // IceCube::TimeUtil will serialize a TimeWithZone into a hash, such as:
182
+ // {time: Thu, 04 Sep 2014 06:59:59 +0000, zone: "Pacific Time (US & Canada)"}
183
+ // If we're initializing from an unsaved rule, until will be a string
184
+ if ( this . current_rule . hash . until . time ) {
185
+ this . until_val = new Date ( this . current_rule . hash . until . time ) ;
186
+ this . until_date . value = ( this . until_val . getFullYear ( ) + "-" + ( this . until_val . getMonth ( ) + 1 ) + "-" + this . until_val . getDate ( ) + " " + this . until_val . getHours ( ) + ":" + this . until_val . getMinutes ( ) ) ;
187
+ } else {
188
+ this . until_date . value = this . current_rule . hash . until ;
189
+ }
190
+ } else {
191
+ this . never_option = section . querySelector ( "input[name=rs_termination][value=never]" ) ;
192
+ this . never_option . checked = true ;
193
+ }
194
+
195
+ section . addEventListener ( "change" , this . terminationChanged . bind ( this ) ) ;
196
+ }
159
197
160
198
summaryInit ( ) {
161
199
this . summary = this . outer_holder . querySelector ( ".rs_summary" ) ;
@@ -212,7 +250,7 @@ class RecurringSelectDialog {
212
250
if ( Array . from ( this . current_rule . hash . validations . day_of_month ) . includes ( num ) ) {
213
251
day_link . classList . add ( "selected" ) ;
214
252
}
215
- } ;
253
+ }
216
254
217
255
// add last day of month button
218
256
const end_of_month_link = document . createElement ( "a" )
@@ -248,9 +286,9 @@ class RecurringSelectDialog {
248
286
day_link . setAttribute ( "day" , day_of_week ) ;
249
287
day_link . setAttribute ( "instance" , num ) ;
250
288
monthly_calendar . appendChild ( day_link ) ;
251
- } ;
289
+ }
252
290
}
253
- } ;
291
+ }
254
292
255
293
Object . entries ( this . current_rule . hash . validations . day_of_week ) . forEach ( ( [ key , value ] ) => {
256
294
Array . from ( value ) . forEach ( ( instance , index ) => {
@@ -278,10 +316,9 @@ class RecurringSelectDialog {
278
316
freqChanged ( ) {
279
317
if ( ! isPlainObject ( this . current_rule . hash ) ) { this . current_rule . hash = null ; } // for custom values
280
318
281
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
319
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } }
320
+ this . current_rule . str = null ;
282
321
this . current_rule . hash . interval = 1 ;
283
- this . current_rule . hash . until = null ;
284
- this . current_rule . hash . count = null ;
285
322
this . current_rule . hash . validations = null ;
286
323
this . content . querySelectorAll ( ".freq_option_section" ) . forEach ( el => el . style . display = 'none' )
287
324
this . content . querySelector ( "input[type=radio], input[type=checkbox]" ) . checked = false
@@ -305,13 +342,13 @@ class RecurringSelectDialog {
305
342
this . current_rule . hash . rule_type = "IceCube::DailyRule" ;
306
343
this . current_rule . str = this . config . texts [ "daily" ] ;
307
344
this . initDailyOptions ( ) ;
308
- } ;
309
- this . summaryUpdate ( ) ;
345
+ }
346
+ this . summaryFetch ( ) ;
310
347
}
311
348
312
349
intervalChanged ( event ) {
313
350
this . current_rule . str = null ;
314
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
351
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
315
352
this . current_rule . hash . interval = parseInt ( event . currentTarget . value ) ;
316
353
if ( ( this . current_rule . hash . interval < 1 ) || isNaN ( this . current_rule . hash . interval ) ) {
317
354
this . current_rule . hash . interval = 1 ;
@@ -322,7 +359,7 @@ class RecurringSelectDialog {
322
359
daysChanged ( event ) {
323
360
event . target . classList . toggle ( "selected" ) ;
324
361
this . current_rule . str = null ;
325
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
362
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
326
363
this . current_rule . hash . validations = { } ;
327
364
const raw_days = Array . from ( this . content . querySelectorAll ( ".day_holder a.selected" ) )
328
365
. map ( el => parseInt ( el . dataset . value ) )
@@ -334,7 +371,7 @@ class RecurringSelectDialog {
334
371
dateOfMonthChanged ( event ) {
335
372
event . target . classList . toggle ( "selected" ) ;
336
373
this . current_rule . str = null ;
337
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
374
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
338
375
this . current_rule . hash . validations = { } ;
339
376
const raw_days = Array . from ( this . content . querySelectorAll ( ".monthly_options .rs_calendar_day a.selected" ) )
340
377
. map ( el => {
@@ -349,21 +386,44 @@ class RecurringSelectDialog {
349
386
weekOfMonthChanged ( event ) {
350
387
event . target . classList . toggle ( "selected" ) ;
351
388
this . current_rule . str = null ;
352
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
389
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
353
390
this . current_rule . hash . validations = { } ;
354
391
this . current_rule . hash . validations . day_of_month = [ ] ;
355
392
this . current_rule . hash . validations . day_of_week = { } ;
356
393
this . content . querySelectorAll ( ".monthly_options .rs_calendar_week a.selected" )
357
394
. forEach ( ( elm , index ) => {
358
395
const day = parseInt ( elm . getAttribute ( "day" ) ) ;
359
396
const instance = parseInt ( elm . getAttribute ( "instance" ) ) ;
360
- if ( ! this . current_rule . hash . validations . day_of_week [ day ] ) { this . current_rule . hash . validations . day_of_week [ day ] = [ ] } ;
397
+ if ( ! this . current_rule . hash . validations . day_of_week [ day ] ) { this . current_rule . hash . validations . day_of_week [ day ] = [ ] ; }
361
398
return this . current_rule . hash . validations . day_of_week [ day ] . push ( instance ) ;
362
399
} )
363
400
this . summaryUpdate ( ) ;
364
401
return false ;
365
402
}
366
403
404
+ terminationChanged ( ) {
405
+ this . selected_termination_type = this . outer_holder . querySelector ( ".rs_termination_section input[type='radio']:checked" ) ;
406
+ if ( ! this . selected_termination_type ) { return ; }
407
+ this . current_rule . str = null ;
408
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
409
+ switch ( this . selected_termination_type . value ) {
410
+ case "count" :
411
+ this . current_rule . hash . count = parseInt ( this . occurence_count ? this . occurence_count . value : this . outer_holder . querySelector ( "#rs_occurrence_count" ) . value ) ;
412
+ if ( ( this . current_rule . hash . count < 1 ) || isNaN ( this . current_rule . hash . count ) ) {
413
+ this . current_rule . hash . count = 1 ;
414
+ }
415
+ this . current_rule . hash . until = null ;
416
+ break
417
+ case "until" :
418
+ this . current_rule . hash . until = this . until_date ? this . until_date . value : this . outer_holder . querySelector ( "#rs_until_date" ) . value ;
419
+ this . current_rule . hash . count = null ;
420
+ break
421
+ default :
422
+ this . current_rule . hash . count = null ;
423
+ this . current_rule . hash . until = null ;
424
+ }
425
+ this . summaryUpdate ( ) ;
426
+ }
367
427
// ========================= Change callbacks ===============================
368
428
369
429
template ( ) {
@@ -381,7 +441,6 @@ class RecurringSelectDialog {
381
441
<option value='Yearly'>${ this . config . texts [ "yearly" ] } </option> \
382
442
</select> \
383
443
</p> \
384
- \
385
444
<div class='daily_options freq_option_section'> \
386
445
<p> \
387
446
${ this . config . texts [ "every" ] } \
@@ -400,7 +459,7 @@ class RecurringSelectDialog {
400
459
for ( let i = this . config . texts [ "first_day_of_week" ] , day_of_week = i , end = 7 + this . config . texts [ "first_day_of_week" ] , asc = this . config . texts [ "first_day_of_week" ] <= end ; asc ? i < end : i > end ; asc ? i ++ : i -- , day_of_week = i ) {
401
460
day_of_week = day_of_week % 7 ;
402
461
str += `<a href='#' data-value='${ day_of_week } '>${ this . config . texts [ "days_first_letter" ] [ day_of_week ] } </a>` ;
403
- } ;
462
+ }
404
463
405
464
str += `\
406
465
</div> \
@@ -426,6 +485,31 @@ class RecurringSelectDialog {
426
485
${ this . config . texts [ "years" ] } \
427
486
</p> \
428
487
</div> \
488
+ <div class='rs_termination_section'>
489
+ <table>
490
+ <tr>
491
+ <td>
492
+ <label class='rs_termination_label'>${ this . config . texts [ "ends" ] } :</label>
493
+ </td>
494
+ <td>
495
+ <label>
496
+ <input type='radio' name='rs_termination' value='never' />
497
+ ${ this . config . texts [ "never" ] }
498
+ </label><br>
499
+ <label>
500
+ <input type='radio' name='rs_termination' value='count' />
501
+ ${ this . config . texts [ "after" ] }
502
+ <input type='text' data-wrapper-class='ui-recurring-select' id='rs_occurrence_count' class='rs_count' value='10' size='2' />
503
+ ${ this . config . texts [ "occurrences" ] }
504
+ </label><br>
505
+ <label>
506
+ <input type='radio' name='rs_termination' value='until' />
507
+ ${ this . config . texts [ "on" ] }
508
+ <input type='text' data-wrapper-class='ui-recurring-select' class='rs_datepicker' id='rs_until_date' />
509
+ </label>
510
+ </td>
511
+ </table>
512
+ </div>
429
513
<p class='rs_summary'> \
430
514
<span></span> \
431
515
</p> \
0 commit comments