File: EditRecurrence

package info (click to toggle)
rt-extension-repeatticket 2.04-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 472 kB
  • sloc: perl: 4,006; sh: 70; makefile: 45
file content (458 lines) | stat: -rw-r--r-- 24,773 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<script type="text/javascript">
jQuery( function () {
    jQuery('div.repeat input[name=repeat-enabled]').change( function () {
        var val = jQuery(this).val();
        if ( jQuery(this).is(':checked') ) {
            jQuery('div.repeat div.repeat-toggle').removeClass('hidden');
        }
        else {
            jQuery('div.repeat div.repeat-toggle').addClass('hidden');
        }
    } );

    jQuery('div.repeat input[name=repeat-type]').change( function () {
        var val = jQuery(this).val();
        jQuery('div.repeat .repeat-details:not(.repeat-details-'+val+')').addClass('hidden');
        jQuery('div.repeat .repeat-details-' +val ).removeClass('hidden');
    } );

    jQuery('div.repeat input[name=repeat-create-on-recurring-date]').change( function () {
        var val = jQuery(this).val();
        if ( val == 0 ) {
            jQuery('div#repeat-coexistent-number-div').removeClass('hidden');
            jQuery('svg#lead-time-tooltip-simple').addClass('hidden');
            jQuery('svg#lead-time-tooltip-concurrent').removeClass('hidden');
            if ( jQuery('div.repeat input[name=repeat-coexistent-number]').val() == 0 ) {
              jQuery('div.repeat input[name=repeat-coexistent-number]').val( <% RT->Config->Get('RepeatTicketCoexistentNumber') || 1 %> );
            }
        }
        else {
            jQuery('div#repeat-coexistent-number-div').addClass('hidden');
            jQuery('svg#lead-time-tooltip-simple').removeClass('hidden');
            jQuery('svg#lead-time-tooltip-concurrent').addClass('hidden');
            jQuery('div.repeat input[name=repeat-coexistent-number]').val(0);
        }
    } );

% if ( $ReadOnly ) {
    jQuery('div.repeat.read-only input, div.repeat.read-only select').attr('disabled', true);
% }
} );
</script>
<div class="repeat <% $ReadOnly ? 'read-only' : '' %>">

  <div class="form-row">
    <div class="label input col-4">
      <&|/l&>Enable Recurrence:</&>
    </div>
    <div class="value col-8">
      <div class="form-check pl-0">
        <div class="custom-control custom-checkbox">
          <input type="checkbox" id="<% $InputIdPrefix %>repeat-enabled" name="repeat-enabled" class="custom-control-input" value="1" <% $ARGSRef->{'repeat-enabled'} ? ' checked="checked"': '' |n %>>
          <label for="<% $InputIdPrefix %>repeat-enabled" class="custom-control-label"></label>
        </div>
      </div>
    </div>
  </div>

  <div class="repeat-toggle <% $ARGSRef->{'repeat-enabled'} ? '' : 'hidden' %> ">

    <div class="form-row">
      <div class="label input col-4">
        <&|/l&>Ticket Create Mode</&>:
      </div>
      <div class="value col-8">
        <div class="form-check form-check-inline">
          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-create-on-recurring-date-true" name="repeat-create-on-recurring-date" class="custom-control-input" value="1" <% $ARGSRef->{'repeat-create-on-recurring-date'} ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-create-on-recurring-date-true"><&|/l&>Simple Mode - Ticket created on Recurring Date</&></label>
          </div>
        </div>

        <div class="form-check form-check-inline">
          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-create-on-recurring-date-false" name="repeat-create-on-recurring-date" class="custom-control-input" value="0" <% $ARGSRef->{'repeat-create-on-recurring-date'} ? '' : ' checked="checked"' |n %>>
            <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-create-on-recurring-date-false"><&|/l&>Concurrent Tickets Mode - Ticket due on Recurring Date</&></label>
          </div>
        </div>
      </div>
    </div>

    <div id="repeat-coexistent-number-div" class="form-row <% $ARGSRef->{'repeat-create-on-recurring-date'} ? 'hidden' : '' %>">
      <div class="label input col-4">
        <&|/l&>Concurrent active tickets</&>:
      </div>
      <div class="value col-8">
        <input class="form-control" size="3" name="repeat-coexistent-number" type="text" value="<% $ARGSRef->{'repeat-coexistent-number'} %>" />
      </div>
    </div>

    <div class="form-row">
      <div class="label input col-4">
        <&|/l&>Ticket lead time (days)</&>:
        <span id="lead-time-tooltip-simple" class="far fa-question-circle icon-helper <% $ARGSRef->{'repeat-create-on-recurring-date'} ? '' : 'hidden' %>" data-toggle="tooltip" data-placement="top" data-original-title="<% loc($lead_time_tooltip_simple) %>"></span>
        <span id="lead-time-tooltip-concurrent" class="far fa-question-circle icon-helper <% $ARGSRef->{'repeat-create-on-recurring-date'} ? 'hidden' : '' %>" data-toggle="tooltip" data-placement="top" data-original-title="<% loc($lead_time_tooltip_concurrent) %>"></span>
      </div>
      <div class="value col-8">
        <input class="form-control" size="3" name="repeat-lead-time" type="text" value="<% $ARGSRef->{'repeat-lead-time'} %>" />
      </div>
    </div>

    <div class="form-row">
      <div class="label input col-4">
        <&|/l&>Recurrence pattern</&>:
      </div>
      <div class="value col-8">

        <div class="form-check form-check-inline">
          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-type-daily" name="repeat-type" class="custom-control-input" value="daily" <% ($ARGSRef->{'repeat-type'} || '') eq 'daily' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-type-daily"><&|/l&>Daily</&></label>
          </div>
        </div>

        <div class="form-check form-check-inline">
          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-type-weekly" name="repeat-type" class="custom-control-input" value="weekly" <% ($ARGSRef->{'repeat-type'} || '') eq 'weekly' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-type-weekly"><&|/l&>Weekly</&></label>
          </div>
        </div>

        <div class="form-check form-check-inline">
          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-type-monthly" name="repeat-type" class="custom-control-input" value="monthly" <% ($ARGSRef->{'repeat-type'} || '') eq 'monthly' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-type-monthly"><&|/l&>Monthly</&></label>
          </div>
        </div>

        <div class="form-check form-check-inline">
          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-type-yearly" name="repeat-type" class="custom-control-input" value="yearly" <% ($ARGSRef->{'repeat-type'} || '') eq 'yearly' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-type-yearly"><&|/l&>Yearly</&></label>
          </div>

        </div>

        <div class="mt-3 repeat-details repeat-details-daily <% ($ARGSRef->{'repeat-type'} || '' ) eq 'daily' ? '' : 'hidden' %>">

          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-daily-day" name="repeat-details-daily" class="custom-control-input" value="day" <% ($ARGSRef->{'repeat-details-daily'} || '') eq 'day' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-daily-day"><&|/l_unsafe, $input->("repeat-details-daily-day") &>Every [_1] Day(s)</&></label>
          </div>

          <div class="mt-1 custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-daily-weekday" name="repeat-details-daily" class="custom-control-input" value="weekday" <% ($ARGSRef->{'repeat-details-daily'} || '') eq 'weekday' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-details-daily-weekday"><&|/l&>Every Weekday</&></label>
          </div>

          <div class="mt-1 custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-daily-complete" name="repeat-details-daily" class="custom-control-input" value="complete" <% ($ARGSRef->{'repeat-details-daily'} || '') eq 'complete' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-daily-complete"><&|/l_unsafe, $input->("repeat-details-daily-complete") &>Create new task [_1] day(s) after each task is completed</&></label>
          </div>

        </div>

        <div class="mt-3 repeat-details repeat-details-weekly <% ($ARGSRef->{'repeat-type'} || '' ) eq 'weekly' ? '' : 'hidden' %>">
          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-weekly-week" name="repeat-details-weekly" class="custom-control-input" value="week" <% ($ARGSRef->{'repeat-details-weekly'} || '') eq 'week' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-weekly-week"><&|/l_unsafe, $input->("repeat-details-weekly-week") &>Recur every [_1] week(s) on</&>:</label>
          </div>

          <div class="ml-4">
%         for my $number ( 0 .. 6 ) {
            <div class="form-check form-check-inline">
              <div class="custom-control custom-checkbox">
                <input id="<% $InputIdPrefix %>repeat-details-weekly-weeks-<% $week_values[$number] %>" name="repeat-details-weekly-weeks" type="checkbox" class="custom-control-input" value="<% $week_values[$number] %>"
%             if ( defined $ARGSRef->{'repeat-details-weekly-weeks'} && (
%               ( ref $ARGSRef->{'repeat-details-weekly-weeks'} && grep { $_ eq $week_values[$number] }
%               @{$ARGSRef->{'repeat-details-weekly-weeks'}} ) ||
%               ( $ARGSRef->{'repeat-details-weekly-weeks'} eq $week_values[$number] ) ) ) {
                  checked="checked"
%             }
                />
                <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-details-weekly-weeks-<% $week_values[$number] %>"><% loc($week_labels[$number]) %></label>
              </div>
            </div>
%       }
          </div>

          <div class="mt-1 custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-weekly-complete" name="repeat-details-weekly" class="custom-control-input" value="complete" <% ($ARGSRef->{'repeat-details-weekly'} || '') eq 'complete' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-weekly-complete"><&|/l_unsafe, $input->("repeat-details-weekly-complete") &>Create new task [_1] week(s) after each task is completed</&></label>
          </div>

        </div>

        <div class="mt-3 repeat-details repeat-details-monthly <% ($ARGSRef->{'repeat-type'} || '' ) eq 'monthly' ? '' : 'hidden' %>">

          <div class="custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-monthly-day" name="repeat-details-monthly" class="custom-control-input" value="day" <% ($ARGSRef->{'repeat-details-monthly'} || '') eq 'day' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-monthly-day"><&|/l_unsafe, $input->("repeat-details-monthly-day-day"), $input->("repeat-details-monthly-day-month") &>Day [_1] of every [_2] month(s)</&></label>
          </div>

          <div class="mt-1 custom-control custom-radio z-index-auto">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-monthly-week" name="repeat-details-monthly" class="custom-control-input" value="week" <% ($ARGSRef->{'repeat-details-monthly'} || '') eq 'week' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-monthly-week"><&|/l_unsafe, $nth->("repeat-details-monthly-week-number"), $wday->("repeat-details-monthly-week-week"), $input->("repeat-details-monthly-week-month") &>The [_1] [_2] of every [_3] month(s)</&></label>
          </div>

          <div class="mt-1 custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-monthly-complete" name="repeat-details-monthly" class="custom-control-input" value="complete" <% ($ARGSRef->{'repeat-details-monthly'} || '') eq 'complete' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-monthly-complete"><&|/l_unsafe, $input->("repeat-details-monthly-complete") &>Create new task [_1] month(s) after each task is completed</&></label>
          </div>

        </div>

        <div class="mt-3 repeat-details repeat-details-yearly <% ($ARGSRef->{'repeat-type'} || '' ) eq 'yearly' ? '' : 'hidden' %>">

          <div class="custom-control custom-radio z-index-auto">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-yearly-day" name="repeat-details-yearly" class="custom-control-input" value="day" <% ($ARGSRef->{'repeat-details-yearly'} || '') eq 'day' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-yearly-day"><&|/l_unsafe, $month->("repeat-details-yearly-day-month"), $input->("repeat-details-yearly-day-day") &>Every [_1] [_2]</&></label>
          </div>

          <div class="mt-1 custom-control custom-radio z-index-auto">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-yearly-week" name="repeat-details-yearly" class="custom-control-input" value="week" <% ($ARGSRef->{'repeat-details-yearly'} || '') eq 'week' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-yearly-week"><&|/l_unsafe, $nth->("repeat-details-yearly-week-number"), $wday->("repeat-details-yearly-week-week"), $month->("repeat-details-yearly-week-month") &>The [_1] [_2] of [_3]</&></label>
          </div>

          <div class="mt-1 custom-control custom-radio">
            <input type="radio" id="<% $InputIdPrefix %>repeat-details-yearly-complete" name="repeat-details-yearly" class="custom-control-input" value="complete" <% ($ARGSRef->{'repeat-details-yearly'} || '') eq 'complete' ? ' checked="checked"': '' |n %>>
            <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-details-yearly-complete"><&|/l_unsafe, $input->("repeat-details-yearly-complete") &>Create new task [_1] year(s) after each task is completed</&></label>
          </div>

        </div>

      </div>
    </div>

    <div class="form-row mt-2">
      <div class="label input col-4">
        <&|/l&>Start of recurrence</&>:
      </div>
      <div class="value col-8">
        <& /Elements/SelectDate, Name => 'repeat-start-date', id => "${InputIdPrefix}repeat-start-date_Date", ShowTime => 0, Default => $ARGSRef->{'repeat-start-date'} || '' &>
      </div>
    </div>

    <div class="form-row">
      <div class="label input col-4">
        <&|/l&>End of recurrence</&>:
      </div>
      <div class="value col-8 form-check">

        <div class="custom-control custom-radio">
          <input type="radio" id="<% $InputIdPrefix %>repeat-end-none" name="repeat-end" class="custom-control-input" value="none" <% ($ARGSRef->{'repeat-end'} || '') eq 'none' ? ' checked="checked"': '' |n %>>
          <label class="custom-control-label" for="<% $InputIdPrefix %>repeat-end-none"><&|/l&>No end date</&></label>
        </div>

        <div class="mt-1 custom-control custom-radio">
          <input type="radio" id="<% $InputIdPrefix %>repeat-end-number" name="repeat-end" class="custom-control-input" value="number" <% ($ARGSRef->{'repeat-end'} || '') eq 'number' ? ' checked="checked"': '' |n %>>
          <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-end-number"><&|/l_unsafe, $input->("repeat-end-number",6,10) &>End after [_1] occurrence(s)</&>
%         if ( $Initial ) {
            <input name="repeat-occurrences" type="hidden" value="1">
%         } else {
            <&|/l&>Current</&>: <input size="6" type="text" name="repeat-occurrences" readonly="readonly" value="<% $ARGSRef->{'repeat-occurrences'} %>">
%         }
          </label>
        </div>

        <div class="mt-1 custom-control custom-radio">
          <input type="radio" id="<% $InputIdPrefix %>repeat-end-type-date" name="repeat-end" class="custom-control-input" value="date" <% ($ARGSRef->{'repeat-end'} || '') eq 'date' ? ' checked="checked"': '' |n %>>
          <label class="custom-control-label has-text-input" for="<% $InputIdPrefix %>repeat-end-type-date">
            <&|/l&>End by</&>: <& /Elements/SelectDate, Name => 'repeat-end-date', id => "${InputIdPrefix}repeat-end-date_Date", ShowTime => 0, Default => $ARGSRef->{'repeat-end-date'} || '' &>
          </label>
        </div>

      </div>
    </div>
  </div>

  <div class="<% $ARGSRef->{'repeat-enabled'} && $ReadOnly && $preview_num ? '' : 'hidden' %>" id="tickets-preview">
    <&| /Widgets/TitleBox, title => loc("Recurrence Preview") &>
      <div class="form-row" style="text-align:left;">
        <p>This shows the next <% $preview_num %> tickets that would be created with the current recurrence configuration.</p>

        <p>If the recurrence configuration uses the concurrent active tickets option or the create new task after task is complete option the preview may not be accurate as it depends on whether previously created tickets are still active.</p>
      </div>
      <div class="form-row" style="text-align:center;">
        <div class="col-6">
          <span><% loc('Starts') . ( $ARGSRef->{'repeat-create-on-recurring-date'} ? ' - ' . loc('Recurring Date') : '' ) %></span>
        </div>
        <div class="col-6">
          <span><% loc('Due') . ( $ARGSRef->{'repeat-create-on-recurring-date'} ? '' : ' - ' . loc('Recurring Date') ) %></span>
        </div>
      </div>
% foreach my $preview ( @preview_tickets ) {
      <div class="form-row" style="text-align:center;">
        <div class="col-6">
          <span><% $preview->[0] %></span>
        </div>
        <div class="col-6">
          <span><% $preview->[1] %></span>
        </div>
      </div>
% }
    </&>
    </div>

</div>

<%init>
my @week_labels = qw(Sun Mon Tue Wed Thu Fri Sat); # loc_qw
my @week_values = qw(su mo tu we th fr sa);
my @week_number_labels = qw(First Second Third Fourth Last); # loc_qw
my @month_labels = qw(January February March April  May June July August September October November December); # loc_qw

my $lead_time_tooltip_simple     = loc('Ticket will be due this many days after the recurring date.');
my $lead_time_tooltip_concurrent = loc('Ticket will be created this many days before the recurring date.');

my $repeat;
if ( $Ticket ) {
    ($repeat) = $Ticket->Attributes->Named('RepeatTicketSettings');
    if ( $repeat ) {
        $ARGSRef = $repeat->Content if $repeat;
    }
}

if ( not $ARGSRef ){
     $Initial = 1;
}

$ARGSRef->{'repeat-type'} ||= 'daily';
$ARGSRef->{'repeat-details-daily'} ||= 'day';
$ARGSRef->{'repeat-details-weekly'} ||= 'week';
$ARGSRef->{'repeat-details-monthly'} ||= 'day';
$ARGSRef->{'repeat-details-yearly'} ||= 'day';
$ARGSRef->{'repeat-end'} ||= 'none';
$ARGSRef->{'repeat-lead-time'} //= RT->Config->Get('RepeatTicketLeadTime') // 14;
$ARGSRef->{'repeat-create-on-recurring-date'} //= 1;

if ( $ARGSRef->{'repeat-create-on-recurring-date'} ) {
    $ARGSRef->{'repeat-coexistent-number'} = 0;
}
else {
    # 0 is not a valid value for concurrent tickets mode
    if ( not $ARGSRef->{'repeat-coexistent-number'} ){
        $ARGSRef->{'repeat-coexistent-number'} = RT->Config->Get('RepeatTicketCoexistentNumber') || 1;
    }
}

my $input = sub {
    my ($name, $width, $default) = (@_);
    $width ||= 4; $default ||= 1;
    my $escaped = $m->interp->apply_escapes($name, "h");
    return qq|<input name="$escaped" type="text" size="$width" class="form-control" value="|
         . $m->interp->apply_escapes($ARGSRef->{$name} || $default, "h")
         . qq|" />|;
};

my $nth = sub {
    my ($name) = @_;
    my $escaped = $m->interp->apply_escapes($name, "h");
    my $str = qq|<select class="form-control selectpicker" name="$escaped">|;
    for my $number ( 1 .. 4, -1 ) {
        $str .= qq|<option value="$number" |
              . (($ARGSRef->{$name} || '') eq $number ? 'selected="selected"' : '') . ">"
              . $m->interp->apply_escapes(loc($week_number_labels[$number > 0 ? $number-1 : -1]), "h")
              . "</option>";
    }
    $str .= "</select>";
    return $str;
};
my $wday = sub {
    my ($name) = @_;
    my $escaped = $m->interp->apply_escapes($name, "h");
    my $str = qq|<select class="form-control selectpicker" name="$escaped">|;
    for my $number ( 0 .. 6 ) {
        $str .= qq|<option value="$week_values[$number]" |
              . (($ARGSRef->{$name} || '') eq $week_values[$number] ? 'selected="selected"' : '' ) . ">"
              . $m->interp->apply_escapes(loc($week_labels[$number]), "h")
              . "</option>";
    }
    $str .= "</select>";
    return $str;
};
my $month = sub {
    my ($name) = @_;
    my $escaped = $m->interp->apply_escapes($name, "h");
    my $str = qq|<select class="form-control selectpicker" name="$escaped">|;
    for my $number ( 1 .. 12 ) {
        $str .= qq|<option value="$number" |
              . (($ARGSRef->{$name} || '') eq $number ? 'selected="selected"' : '') . ">"
              . $m->interp->apply_escapes(loc($month_labels[$number-1]), "h")
              . "</option>";
    }
    $str .= "</select>";
    return $str;
};

my @preview_tickets;
my $preview_num = RT->Config->Get('RepeatTicketPreviewNumber') // 5;
unless ( $Initial ) {
  # find next X tickets to be created for preview window
    if ( $preview_num ) {
        RT::Extension::RepeatTicket::RepeatTicketPreview(1);

        my $content = $repeat->Content;

        my ( $last_due, $last_created );
        if ( $content->{'last-ticket'} ) {
            my $last_ticket = RT::Ticket->new( RT->SystemUser );
            $last_ticket->Load( $content->{'last-ticket'} );

            if ( $last_ticket->DueObj->Unix ) {
                $last_due = DateTime->from_epoch(
                    epoch     => $last_ticket->DueObj->Unix,
                    time_zone => RT->Config->Get('Timezone'),
                );
                $last_due->truncate( to => 'day' );
            }

            $last_created = DateTime->from_epoch(
                epoch     => $last_ticket->CreatedObj->Unix,
                time_zone => RT->Config->Get('Timezone'),
            );
            $last_created->truncate( to => 'day' );
        }
        my $today = DateTime->today( time_zone => RT->Config->Get('Timezone') );
        $today->truncate( to => 'day' );

        my $start_set_date;
        if ( $content->{'repeat-create-on-recurring-date'} ) {
            $start_set_date = $last_created || $today;
        }
        else {
            $start_set_date = $last_due || $last_created || $today;
        }

        my $set = RT::Extension::RepeatTicket::BuildSet( $content, $start_set_date );
        if ($set) {
            # use a counter to ensure we don't get an endless loop trying to find the next X tickets
            my $counter = 0;
            my $iter = $set->iterator;
            while ( my $dt = $iter->next ) {
                if ( !$content->{'repeat-create-on-recurring-date'} && $content->{'repeat-lead-time'} ) {
                    # the date to pass to Repeat must be the start/create date which in concurrent mode is lead time days in the past
                    $dt->add( days => -1 * $content->{'repeat-lead-time'} );
                }

                # skip dates in the past
                next if $dt->epoch < $today->epoch;

                push @preview_tickets, RT::Extension::RepeatTicket::Repeat( $repeat, $dt );
                $counter++;

                last if scalar @preview_tickets >= $preview_num || $counter > $preview_num * 2;
            }
        }

        RT::Extension::RepeatTicket::RepeatTicketPreview(0);
    }
}
</%init>
<%args>
$ARGSRef => undef
$Ticket => undef
$ReadOnly => undef
$Initial => undef
$InputIdPrefix => ''
</%args>