From bcfd3849a9f8ac91ab9a0b90c1e5cdf9d7b360bc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Nov 2021 10:54:10 +0100 Subject: [PATCH] Bug 29394: Remove flatpickr instantiations from most of the tt files We must reduce the instantiations as much as possible to take advantages of the default values and specific behaviours we have defined in calendar.inc This patch is suggesting to have a .flatpickr class and using the data attributes: - flatpickr-futuredate - flatpickr-pastdate - flatpickr-enable-time - flatpickr-on-close-focus Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- .../prog/en/includes/borrower_debarments.inc | 2 +- .../prog/en/includes/calendar.inc | 13 ++++++++-- .../prog/en/includes/holds_table.inc | 4 +-- .../prog/en/modules/circ/circulation.tt | 2 +- .../circ/circulation_batch_checkouts.tt | 14 ++++------- .../prog/en/modules/circ/renew.tt | 25 ++++++------------- .../prog/en/modules/circ/returns.tt | 11 +------- .../prog/en/modules/ill/ill-requests.tt | 7 +----- .../prog/en/modules/members/moremember.tt | 2 +- .../prog/en/modules/reports/borrowers_out.tt | 2 +- .../prog/en/modules/reserve/request.tt | 9 +------ .../prog/en/modules/tools/scheduler.tt | 2 +- 12 files changed, 33 insertions(+), 60 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc index b1aa6d1f61..bd224f6a73 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc @@ -62,7 +62,7 @@
  • - +
  • Cancel
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 117dbd9960..f67bffe313 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -78,19 +78,28 @@ var endPicker = document.querySelector("#"+thisInput.dataset.date_to)._flatpickr; endPicker.set('minDate', selectedDates[0]); } + + let = on_close_focus = $(thisInput).data('flatpickr-on-close-focus'); + if ( on_close_focus ) { + $(on_close_focus).focus(); + } }, }); $(document).ready(function(){ $(".flatpickr").each(function(){ let options = {}; - if( $(this).hasClass("futuredate") ) { + if( $(this).data("flatpickr-futuredate") === true ) { options['minDate'] = new Date().fp_incr(1); options['allowInvalidPreload'] = true; } - if( $(this).hasClass("pastdate") ) { + if( $(this).data("flatpickr-pastdate") === true ) { options['maxDate'] = new Date().fp_incr(-1); } + if ( $(this).data('flatpickr-enable-time') === true ) { + options['enableTime'] = true; + } + $(this).flatpickr(options); }); }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc index dfddd9c75c..99a6bef496 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -114,7 +114,7 @@ [% END %] - + [%- IF ( hold.found ) -%] @@ -211,7 +211,7 @@ [% IF Koha.Preference('AutoResumeSuspendedHolds') %] - + [%- ELSE -%] [%- END -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index bc8a32e631..1196a16425 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -875,7 +875,7 @@ [% IF Koha.Preference('AutoResumeSuspendedHolds') %] - + Specify date on which to resume [% INCLUDE 'date-format.inc' %]: [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt index 41679237bc..dc584eabdc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation_batch_checkouts.tt @@ -112,7 +112,11 @@
    Due date: - + [% IF Koha.Preference('SpecifyDueDate') %] + + [% ELSE %] + + [% END %]
    [% END %] @@ -357,14 +361,6 @@ ], "bPaginate": false })); - - [% IF Koha.Preference('SpecifyDueDate') %] - $("#duedatespec").flatpickr({ - enableTime: true, - dateFormat: flatpickr_dateformat_string + " " + flatpickr_timeformat_string, - defaultDate: new Date().setHours(23, 59, 0, 0) /* Today a 11:59PM */ - }); - [% END %] }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt index e126144991..499c09bd27 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt @@ -147,7 +147,8 @@
    - + +
    @@ -170,7 +171,11 @@ [% END %]
    - + [% IF Koha.Preference('SpecifyDueDate') %] + + [% ELSE %] + + [% END %]
    @@ -251,22 +256,6 @@ }); [% END %] - [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index b3d8c04e59..c234bd64ca 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -808,7 +808,7 @@
    Specify return date [% INCLUDE 'date-format.inc' %]:
    - +
    [% IF ( return_date_override_remember ) %] @@ -1038,15 +1038,6 @@ "dom": 'B<"clearfix">t', }, columns_settings); - $("#return_date_override").flatpickr({ - enableTime: true, - dateFormat: flatpickr_dateformat_string + " " + flatpickr_timeformat_string, - maxDate: "today", - onClose: function() { - $("#barcode").focus(); - } - }); - $("#exemptcheck").change(function () { if (this.checked == true) { $("#barcode").addClass("input-warning"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt index a5889a10e6..74545dc119 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -248,7 +248,7 @@
  • - [% INCLUDE 'date-format.inc' %] + [% INCLUDE 'date-format.inc' %]
    If you do not specify a due date, it will be set according to circulation rules

  • @@ -840,11 +840,6 @@ // Set column settings var columns_settings = [% TablesSettings.GetColumns( 'illrequests', 'ill-requests', 'ill-requests', 'json' ) %]; - $("#ill_checkout_duedate_input").flatpickr({ - enableTime: true, - dateFormat: flatpickr_dateformat_string + " " + flatpickr_timeformat_string, - }); - [% IF services_json.length > 0 %] var services = [% services_json | $raw %]; [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 91bc3db21f..8f7263b1dd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -812,7 +812,7 @@ [% IF Koha.Preference('AutoResumeSuspendedHolds') %] - + Specify date on which to resume [% INCLUDE 'date-format.inc' %]: [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt index f32f1f3ba4..f3dba0031d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt @@ -68,7 +68,7 @@ [% END %] -
  • +
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 59ff7e6e9f..3611e0864f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -518,7 +518,7 @@ [% IF ( reserve_in_future ) %]
  • - +
  • [% END %] @@ -1209,13 +1209,6 @@ }); [% END %] - [% IF AutoResumeSuspendedHolds %] - $(".suspend_until_datepicker").flatpickr({ - minDate: new Date().fp_incr(1) /* Require that "until date" be in the future */ - }); - [% END %] - - var my_table = $("#requestspecific").dataTable($.extend(true, {}, dataTablesDefaults, { 'bPaginate': false, "sDom": '<"top pager"ilf>t', diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tt index bf144309e2..2ffd7b0868 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tt @@ -46,7 +46,7 @@
  • - +
    [% INCLUDE 'date-format.inc' %]
  • -- 2.39.5