Koha/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
Owen Leonard 09f011493c Bug 28949: Use Flatpickr on reports pages
This patch replaces the use of jQueryUI's datepicker on reports pages.

To test, apply the patch and test the following reports pages to confirm
that datepickers work correctly. "Linked" date fields should prevent a
"to" selection which preceeds the selected "from" date.

- Acquisitions statistic wizard: Linked pairs of fields for
  "placed on" and "received on."
- Patrons with the most checkouts: Linked pairs of fields for
  "Checkout date from" and "Check-in date from"
- Patrons who haven't checked out: "Not checked out since"
  field.
- Cash register statistics wizard: Linked "From" and "To"
  fields.
- Most-circulated items: Linked pairs of fields for
  "Checkout date from" and "Check-in date from"
- Catalog statistics wizard: Linked pairs of fields for "Date acquired
  (item)" and "Date deleted (item)" The latter is shown by checking the
  "Count deleted items" radio button.
- View dictionary -> New definition:
  - Enter a definition name
  - Select table Circulation
  - Choose a date column, e.g. "Date of birth" or "Registration date"
  - Select "Date range"
    - Test that the "Start of date range" and "End of date range" fields
      are linked correctly.
- Create guided report:
  - Module: catalog
  - Type: Tabular
  - Select columns (any)
  - Select criteria to limit on: There should be three pairs of linked
    fields, "Creation date," "Modification date," and "Due date."
  - Confirm that the report is saved correctly with the dates you chose.
- Create from SQL -> Test a report with one or more date
  fields, e.g. https://wiki.koha-community.org/wiki/SQL_Reports_Library#Items_added_by_Collection
- Average loan time: Linke pairs of fields for "Checkout
  date" and "Returns."
- Reports -> Circulation statistics wizard: Linked "Period" fields.
- Reports -> Holds statistics wizard: Linked pairs of fields "Hold
  date," "Notification date," "Reminder date," "Waiting date," and
  "Cancellation date."

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-10-05 10:58:13 +02:00

80 lines
3.6 KiB
PHP

[% USE Asset %]
[% USE Koha %]
[% USE raw %]
<!-- calendar.inc -->
[% FILTER collapse %]
<script>
var debug = "[% debug | html %]";
var dateformat_pref = "[% Koha.Preference('dateformat ') | html %]";
var dateformat_string = [% IF ( dateformat == "us" ) %]"mm/dd/yy"[% ELSIF ( dateformat == "metric" ) %]"dd/mm/yy"[% ELSIF ( dateformat == "dmydot" ) %]"dd.mm.yy"[% ELSE %]"yy-mm-dd"[% END %];
var flatpickr_dateformat_string = [% IF ( dateformat == "us" ) %]"m/d/Y"[% ELSIF ( dateformat == "metric" ) %]"d/m/Y"[% ELSIF ( dateformat == "dmydot" ) %]"d.m.Y"[% ELSE %]"Y-m-d"[% END %];
var sentmsg = 0;
var bidi = [% IF(bidi) %] true[% ELSE %] false[% END %];
var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
var flatpickr_timeformat_string = [% IF Koha.Preference('TimeFormat') == '12hr' %]"G:i K"[% ELSE %]"H:i"[% END %];
var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %];
</script>
<!-- / calendar.inc -->
[% Asset.js("js/calendar.js") | $raw %]
[% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %]
<script>
flatpickr.l10ns.default.weekdays = flatpickr_weekdays;
flatpickr.l10ns.default.months = flatpickr_months;
flatpickr.setDefaults({
allowInput: true,
dateFormat: flatpickr_dateformat_string,
nextArrow: '<i class="fa fa-fw fa-arrow-right"></i>',
prevArrow: '<i class="fa fa-fw fa-arrow-left"></i>',
time_24hr: flatpickr_timeformat,
locale: {
"firstDayOfWeek": calendarFirstDayOfWeek
},
onReady: function( selectedDates, dateStr, instance ){
/* When flatpickr instance is created, automatically append a "clear date" link */
if( $(instance.input).hasClass("futuredate") ){
instance.set("minDate", new Date().fp_incr(1));
}
if( $(instance.input).hasClass("pastdate") ){
instance.set("maxDate", new Date().fp_incr(-1));
}
$(instance.input)
/* Add a wrapper element so that we can prevent the clear button from wrapping */
.wrap("<span class='flatpickr_wrapper'></span>")
.after( $("<a/>")
.attr("href","#")
.addClass("clear_date")
.on("click", function(e){
e.preventDefault();
instance.clear();
})
.addClass("fa fa-fw fa-remove")
.attr("aria-hidden", true)
.attr("aria-label", _("Clear date") )
).keydown(function(e) {
var key = (event.keyCode ? event.keyCode : event.which);
if ( key == 40 ) {
instance.set('allowInput',false);
}
});
},
onClose: function( selectedDates, dateText, instance) {
validate_date( selectedDates, instance );
},
});
$(document).ready(function(){
$(".flatpickr").flatpickr();
var startPicker = $(".flatpickrfrom").flatpickr({
onClose: function( selectedDates, dateText, instance) {
validate_date( selectedDates, instance );
endPicker.set('minDate', selectedDates[0]);
}
});
var endPicker = $(".flatpickrto").flatpickr({
onClose: function( selectedDates, dateText, instance) {
validate_date( selectedDates, instance );
},
});
});
</script>
[% END %]