@@ -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" ) ;
@@ -166,6 +204,7 @@ class RecurringSelectDialog {
166
204
167
205
summaryUpdate ( new_string ) {
168
206
// this.summary.style.width = `${this.content.getBoundingClientRect().width}px`;
207
+ console . log ( "Updating summary" , this . current_rule . hash , this . current_rule . str ) ;
169
208
if ( ( this . current_rule . hash != null ) && ( this . current_rule . str != null ) ) {
170
209
this . summary . classList . remove ( "fetching" ) ;
171
210
this . save_button . classList . remove ( "disabled" ) ;
@@ -212,7 +251,7 @@ class RecurringSelectDialog {
212
251
if ( Array . from ( this . current_rule . hash . validations . day_of_month ) . includes ( num ) ) {
213
252
day_link . classList . add ( "selected" ) ;
214
253
}
215
- } ;
254
+ }
216
255
217
256
// add last day of month button
218
257
const end_of_month_link = document . createElement ( "a" )
@@ -248,9 +287,9 @@ class RecurringSelectDialog {
248
287
day_link . setAttribute ( "day" , day_of_week ) ;
249
288
day_link . setAttribute ( "instance" , num ) ;
250
289
monthly_calendar . appendChild ( day_link ) ;
251
- } ;
290
+ }
252
291
}
253
- } ;
292
+ }
254
293
255
294
Object . entries ( this . current_rule . hash . validations . day_of_week ) . forEach ( ( [ key , value ] ) => {
256
295
Array . from ( value ) . forEach ( ( instance , index ) => {
@@ -278,10 +317,9 @@ class RecurringSelectDialog {
278
317
freqChanged ( ) {
279
318
if ( ! isPlainObject ( this . current_rule . hash ) ) { this . current_rule . hash = null ; } // for custom values
280
319
281
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
320
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } }
321
+ this . current_rule . str = null ;
282
322
this . current_rule . hash . interval = 1 ;
283
- this . current_rule . hash . until = null ;
284
- this . current_rule . hash . count = null ;
285
323
this . current_rule . hash . validations = null ;
286
324
this . content . querySelectorAll ( ".freq_option_section" ) . forEach ( el => el . style . display = 'none' )
287
325
this . content . querySelector ( "input[type=radio], input[type=checkbox]" ) . checked = false
@@ -305,13 +343,13 @@ class RecurringSelectDialog {
305
343
this . current_rule . hash . rule_type = "IceCube::DailyRule" ;
306
344
this . current_rule . str = this . config . texts [ "daily" ] ;
307
345
this . initDailyOptions ( ) ;
308
- } ;
309
- this . summaryUpdate ( ) ;
346
+ }
347
+ this . summaryFetch ( ) ;
310
348
}
311
349
312
350
intervalChanged ( event ) {
313
351
this . current_rule . str = null ;
314
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
352
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
315
353
this . current_rule . hash . interval = parseInt ( event . currentTarget . value ) ;
316
354
if ( ( this . current_rule . hash . interval < 1 ) || isNaN ( this . current_rule . hash . interval ) ) {
317
355
this . current_rule . hash . interval = 1 ;
@@ -322,7 +360,7 @@ class RecurringSelectDialog {
322
360
daysChanged ( event ) {
323
361
event . target . classList . toggle ( "selected" ) ;
324
362
this . current_rule . str = null ;
325
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
363
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
326
364
this . current_rule . hash . validations = { } ;
327
365
const raw_days = Array . from ( this . content . querySelectorAll ( ".day_holder a.selected" ) )
328
366
. map ( el => parseInt ( el . dataset . value ) )
@@ -334,7 +372,7 @@ class RecurringSelectDialog {
334
372
dateOfMonthChanged ( event ) {
335
373
event . target . classList . toggle ( "selected" ) ;
336
374
this . current_rule . str = null ;
337
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
375
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
338
376
this . current_rule . hash . validations = { } ;
339
377
const raw_days = Array . from ( this . content . querySelectorAll ( ".monthly_options .rs_calendar_day a.selected" ) )
340
378
. map ( el => {
@@ -349,21 +387,44 @@ class RecurringSelectDialog {
349
387
weekOfMonthChanged ( event ) {
350
388
event . target . classList . toggle ( "selected" ) ;
351
389
this . current_rule . str = null ;
352
- if ( ! this . current_rule . hash ) { this . current_rule . hash = { } } ;
390
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
353
391
this . current_rule . hash . validations = { } ;
354
392
this . current_rule . hash . validations . day_of_month = [ ] ;
355
393
this . current_rule . hash . validations . day_of_week = { } ;
356
394
this . content . querySelectorAll ( ".monthly_options .rs_calendar_week a.selected" )
357
395
. forEach ( ( elm , index ) => {
358
396
const day = parseInt ( elm . getAttribute ( "day" ) ) ;
359
397
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 ] = [ ] } ;
398
+ if ( ! this . current_rule . hash . validations . day_of_week [ day ] ) { this . current_rule . hash . validations . day_of_week [ day ] = [ ] ; }
361
399
return this . current_rule . hash . validations . day_of_week [ day ] . push ( instance ) ;
362
400
} )
363
401
this . summaryUpdate ( ) ;
364
402
return false ;
365
403
}
366
404
405
+ terminationChanged ( ) {
406
+ this . selected_termination_type = this . outer_holder . querySelector ( ".rs_termination_section input[type='radio']:checked" ) ;
407
+ if ( ! this . selected_termination_type ) { return ; }
408
+ this . current_rule . str = null ;
409
+ if ( ! this . current_rule . hash ) { this . current_rule . hash = { } ; }
410
+ switch ( this . selected_termination_type . value ) {
411
+ case "count" :
412
+ this . current_rule . hash . count = parseInt ( this . occurence_count ? this . occurence_count . value : this . outer_holder . querySelector ( "#rs_occurrence_count" ) . value ) ;
413
+ if ( ( this . current_rule . hash . count < 1 ) || isNaN ( this . current_rule . hash . count ) ) {
414
+ this . current_rule . hash . count = 1 ;
415
+ }
416
+ this . current_rule . hash . until = null ;
417
+ break
418
+ case "until" :
419
+ this . current_rule . hash . until = this . until_date ? this . until_date . value : this . outer_holder . querySelector ( "#rs_until_date" ) . value ;
420
+ this . current_rule . hash . count = null ;
421
+ break
422
+ default :
423
+ this . current_rule . hash . count = null ;
424
+ this . current_rule . hash . until = null ;
425
+ }
426
+ this . summaryUpdate ( ) ;
427
+ }
367
428
// ========================= Change callbacks ===============================
368
429
369
430
template ( ) {
@@ -381,7 +442,6 @@ class RecurringSelectDialog {
381
442
<option value='Yearly'>${ this . config . texts [ "yearly" ] } </option> \
382
443
</select> \
383
444
</p> \
384
- \
385
445
<div class='daily_options freq_option_section'> \
386
446
<p> \
387
447
${ this . config . texts [ "every" ] } \
@@ -400,7 +460,7 @@ class RecurringSelectDialog {
400
460
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
461
day_of_week = day_of_week % 7 ;
402
462
str += `<a href='#' data-value='${ day_of_week } '>${ this . config . texts [ "days_first_letter" ] [ day_of_week ] } </a>` ;
403
- } ;
463
+ }
404
464
405
465
str += `\
406
466
</div> \
@@ -426,6 +486,31 @@ class RecurringSelectDialog {
426
486
${ this . config . texts [ "years" ] } \
427
487
</p> \
428
488
</div> \
489
+ <div class='rs_termination_section'>
490
+ <table>
491
+ <tr>
492
+ <td>
493
+ <label class='rs_termination_label'>${ this . config . texts [ "ends" ] } :</label>
494
+ </td>
495
+ <td>
496
+ <label>
497
+ <input type='radio' name='rs_termination' value='never' />
498
+ ${ this . config . texts [ "never" ] }
499
+ </label><br>
500
+ <label>
501
+ <input type='radio' name='rs_termination' value='count' />
502
+ ${ this . config . texts [ "after" ] }
503
+ <input type='text' data-wrapper-class='ui-recurring-select' id='rs_occurrence_count' class='rs_count' value='10' size='2' />
504
+ ${ this . config . texts [ "occurrences" ] }
505
+ </label><br>
506
+ <label>
507
+ <input type='radio' name='rs_termination' value='until' />
508
+ ${ this . config . texts [ "on" ] }
509
+ <input type='text' data-wrapper-class='ui-recurring-select' class='rs_datepicker' id='rs_until_date' />
510
+ </label>
511
+ </td>
512
+ </table>
513
+ </div>
429
514
<p class='rs_summary'> \
430
515
<span></span> \
431
516
</p> \
0 commit comments