|
278 | 278 | {% endmacro %} |
279 | 279 |
|
280 | 280 | {% macro flatpickrHtmlInput(name, value, label = '', options = {}) %} |
| 281 | + {% set options = { |
| 282 | + 'readonly': false, |
| 283 | + 'disabled': false, |
| 284 | + }|merge(options) %} |
| 285 | + |
| 286 | + {% set editable = not options.readonly and not options.disabled %} |
| 287 | + |
281 | 288 | {% if options.fields_template.isMandatoryField(name) %} |
282 | 289 | {% set options = {'required': true}|merge(options) %} |
283 | 290 | {% endif %} |
284 | 291 |
|
285 | 292 | {% if value == 'NULL' %} |
286 | 293 | {% set value = null %} |
287 | 294 | {% endif %} |
| 295 | + |
288 | 296 | {% if options.checkIsExpired %} |
289 | 297 | {% if value|date('Y-m-d H:i:s') < "now"|date('Y-m-d H:i:s') %} |
290 | 298 | {% set class = 'warn' %} |
|
305 | 313 | {{ options.required ? 'required' : '' }} |
306 | 314 | {{ options.readonly ? 'readonly' : '' }} |
307 | 315 | {{ options.disabled ? 'disabled' : '' }} /> |
308 | | - {% if not options.readonly %} |
| 316 | + {% if editable %} |
309 | 317 | <i class="input-group-text far fa-calendar-alt" data-toggle role="button"></i> |
310 | 318 | {% endif %} |
311 | 319 | </div> |
|
346 | 354 | {% endmacro %} |
347 | 355 |
|
348 | 356 | {% macro datetimeField(name, value, label = '', options = {}) %} |
349 | | - {% set options = {'rand': random()}|merge(options) %} |
| 357 | + {% set options = { |
| 358 | + 'rand': random(), |
| 359 | + 'readonly': false, |
| 360 | + 'disabled': false, |
| 361 | + }|merge(options) %} |
350 | 362 | {% set options = {'id': name|slug ~ '_' ~ options.rand}|merge(options) %} |
| 363 | + |
351 | 364 | {% set locale = get_current_locale() %} |
| 365 | + {% set editable = not options.readonly and not options.disabled %} |
352 | 366 |
|
353 | 367 | {% set field %} |
354 | | - {{ _self.flatpickrHtmlInput(name, value, label, options) }} |
355 | | - <script> |
356 | | - $(function() { |
357 | | - $('#{{ options.id }}').flatpickr({ |
358 | | - altInput: true, |
359 | | - dateFormat: 'Y-m-d H:i:S', |
360 | | - altFormat: '{{ call('Toolbox::getDateFormat', ['js']) }} H:i:S', |
361 | | - enableTime: true, |
362 | | - wrap: true, |
363 | | - enableSeconds: true, |
364 | | - weekNumbers: true, |
365 | | - time_24hr: true, |
366 | | - allowInput: {{ options.readonly ? 'false' : 'true' }}, |
367 | | - clickOpens: {{ options.readonly ? 'false' : 'true' }}, |
368 | | - locale: getFlatPickerLocale('{{ locale['language'] }}', '{{ locale['region'] }}'), |
369 | | - onClose(dates, currentdatestring, picker) { |
370 | | - picker.setDate(picker.altInput.value, true, picker.config.altFormat) |
371 | | - }, |
372 | | - plugins: [ |
373 | | - CustomFlatpickrButtons() |
374 | | - ] |
375 | | - }); |
376 | | - }); |
377 | | - </script> |
| 368 | + {{ _self.flatpickrHtmlInput(name, value, label, options) }} |
| 369 | + {% if editable %} |
| 370 | + <script> |
| 371 | + $(function () { |
| 372 | + $('#{{ options.id }}').flatpickr({ |
| 373 | + altInput: true, |
| 374 | + dateFormat: 'Y-m-d H:i:S', |
| 375 | + altFormat: '{{ call('Toolbox::getDateFormat', ['js']) }} H:i:S', |
| 376 | + enableTime: true, |
| 377 | + wrap: true, |
| 378 | + enableSeconds: true, |
| 379 | + weekNumbers: true, |
| 380 | + time_24hr: true, |
| 381 | + allowInput: {{ editable ? 'true' : 'false' }}, |
| 382 | + clickOpens: {{ editable ? 'true' : 'false' }}, |
| 383 | + locale: getFlatPickerLocale('{{ locale['language'] }}', '{{ locale['region'] }}'), |
| 384 | + onClose(dates, currentdatestring, picker) { |
| 385 | + picker.setDate(picker.altInput.value, true, picker.config.altFormat) |
| 386 | + }, |
| 387 | + plugins: [ |
| 388 | + CustomFlatpickrButtons() |
| 389 | + ] |
| 390 | + }); |
| 391 | + }); |
| 392 | + </script> |
| 393 | + {% endif %} |
378 | 394 | {% endset %} |
379 | 395 |
|
380 | 396 | {{ _self.field(name, field, label, options) }} |
|
0 commit comments