Owen Leonard
de2d8ba3e4
This patch updates templates to include the new version of jQueryUI. It removes some references to the now unused datepicker widget as well as the jQuery timepicker addon. Some minor JavaScript and style updates to fix issues resulting from the upgrade. To test, apply the patch and update the CSS in the staff interface AND in the OPAC (https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client). IN THE OPAC: - The OPAC only uses the tabs jQueryUI widget. - View pages where tabs are used: Bibliographic details, user summary, advanced search. IN THE STAFF INTERFACE: - The staff interface uses four jQueryUI widgets: accordion, autocomplete, sortable, and tabs - Test the accordion widget on two pages: Administration -> Table settings and Patrons -> Patrons requesting modifications. - Test autocomplete (requires PatronAutoComplete to be enabled) on various pages. For example: - From the "Check out" tab in the header search box. - From the "Search patrons" tab in the header search box, e.g. from the main Patrons page. - Place hold -> Search patrons. - Tools -> Patron lists -> Add patrons to list -> Patron search. - Test sortable: - Administration -> System preferences -> Language. - With more than one language installed you should be able to drag to re-order the enabled languages. Confirm that your change is saved successfully. - Administration -> MARC bibliographic framework -> MARC structure -> Edit subfields on a tag with multiple subfields. You should be able to drag to re-order the tabs at the top of the subfield constraints edit page. Confirm that your changes are saved successfully. - Cataloging -> New record. Test that you can re-order subfields under a tag with multiple subfields and that your changes are saved. - Tabs: View various pages with tabs: Check out, bibliographic details, basic MARC editor. They're everywhere. Also confirm that the removal of the leftover datepicker doesn't affect pages which use the calendar include: Test various pages which use Flatpickr, e.g. check out, renew, reports, etc. Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
145 lines
4.8 KiB
JavaScript
145 lines
4.8 KiB
JavaScript
/* global debug sentmsg __ dateformat_pref dateformat_string bidi calendarFirstDayOfWeek */
|
|
/* exported DateTime_from_syspref flatpickr_weekdays flatpickr_months */
|
|
var MSG_PLEASE_ENTER_A_VALID_DATE = ( __("Please enter a valid date (should match %s).") );
|
|
if (debug > 1) {
|
|
alert("dateformat: " + dateformat_pref + "\ndebug is on (level " + debug + ")");
|
|
}
|
|
|
|
function is_valid_date(date) {
|
|
// An empty string is considered as a valid date for convenient reasons.
|
|
if (date === '') return 1;
|
|
var dateformat = dateformat_string;
|
|
if (dateformat == 'us') {
|
|
if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
|
|
dateformat = 'mm/dd/yy';
|
|
} else if (dateformat == 'metric') {
|
|
if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
|
|
dateformat = 'dd/mm/yy';
|
|
} else if (dateformat == 'iso') {
|
|
if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0;
|
|
dateformat = 'yy-mm-dd';
|
|
} else if (dateformat == 'dmydot') {
|
|
if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0;
|
|
dateformat = 'dd.mm.yy';
|
|
}
|
|
try {
|
|
flatpickr.parseDate(date, dateformat);
|
|
} catch (e) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
function get_dateformat_str(dateformat) {
|
|
var dateformat_str;
|
|
if (dateformat == 'us') {
|
|
dateformat_str = 'mm/dd/yyyy';
|
|
} else if (dateformat == 'metric') {
|
|
dateformat_str = 'dd/mm/yyyy';
|
|
} else if (dateformat == 'iso') {
|
|
dateformat_str = 'yyyy-mm-dd';
|
|
} else if (dateformat == 'dmydot') {
|
|
dateformat_str = 'dd.mm.yyyy';
|
|
}
|
|
return dateformat_str;
|
|
}
|
|
|
|
function validate_date(dateText, inst) {
|
|
if (!is_valid_date(dateText)) {
|
|
var dateformat_str = get_dateformat_str( dateformat_pref );
|
|
alert(MSG_PLEASE_ENTER_A_VALID_DATE.format(dateformat_str));
|
|
inst.clear();
|
|
}
|
|
}
|
|
|
|
function Date_from_syspref(dstring) {
|
|
var dateX = dstring.split(/[-/.]/);
|
|
if (debug > 1 && sentmsg < 1) {
|
|
sentmsg++;
|
|
alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));
|
|
}
|
|
if (dateformat_pref === "iso") {
|
|
return new Date(dateX[0], (dateX[1] - 1), dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d)
|
|
} else if (dateformat_pref === "us") {
|
|
return new Date(dateX[2], (dateX[0] - 1), dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d)
|
|
} else if (dateformat_pref === "metric") {
|
|
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d)
|
|
} else if (dateformat_pref === "dmydot") {
|
|
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD.MM.YYYY to (YYYY,m(0-11),d)
|
|
} else {
|
|
if (debug > 0) {
|
|
alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
function DateTime_from_syspref(date_time) {
|
|
var parts = date_time.split(" ");
|
|
var date = parts[0];
|
|
var time = parts[1];
|
|
parts = time.split(":");
|
|
var hour = parts[0];
|
|
var minute = parts[1];
|
|
|
|
if (hour < 0 || hour > 23) {
|
|
return 0;
|
|
}
|
|
if (minute < 0 || minute > 59) {
|
|
return 0;
|
|
}
|
|
|
|
var datetime = Date_from_syspref(date);
|
|
|
|
if (isNaN(datetime.getTime())) {
|
|
return 0;
|
|
}
|
|
|
|
datetime.setHours(hour);
|
|
datetime.setMinutes(minute);
|
|
|
|
return datetime;
|
|
}
|
|
|
|
/* jQuery Validator plugin custom method
|
|
This allows you to check that a given date falls after another.
|
|
It is required that a message be defined.
|
|
|
|
Syntax:
|
|
$("#form_id").validate({
|
|
rules: {
|
|
input_name_of_later_date_field: {
|
|
is_date_after: "#input_id_of_earlier_date_field"
|
|
},
|
|
},
|
|
messages: {
|
|
input_name_of_later_date_field: {
|
|
is_date_after: _("Validation error to be shown, i.e. End date must come after start date")
|
|
}
|
|
}
|
|
});
|
|
*/
|
|
|
|
jQuery.validator.addMethod("is_date_after",
|
|
function (value, element, params) {
|
|
var from = Date_from_syspref($(params).val());
|
|
var to = Date_from_syspref(value);
|
|
return to > from;
|
|
});
|
|
|
|
jQuery.validator.addMethod("date_on_or_after",
|
|
function (value, element, params) {
|
|
var from = Date_from_syspref($(params).val());
|
|
var to = Date_from_syspref(value);
|
|
return to >= from;
|
|
});
|
|
|
|
var flatpickr_weekdays = {
|
|
shorthand: [ __("Sun"), __("Mon"), __("Tue"), __("Wed"), __("Thu"), __("Fri"), __("Sat")],
|
|
longhand: [ __("Sunday"), __("Monday"), __("Tuesday"), __("Wednesday"), __("Thursday"), __("Friday"), __("Saturday") ]
|
|
};
|
|
|
|
var flatpickr_months = {
|
|
shorthand: [ __("Jan"), __("Feb"), __("Mar"), __("Apr"), __("May"), __("Jun"), __("Jul"), __("Aug"), __("Sep"), __("Oct"), __("Nov"), __("Dec")],
|
|
longhand: [ __("January"), __("February"), __("March"), __("April"), __("May"), __("June"), __("July"), __("August"), __("September"), __("October"), __("November"), __("December")]
|
|
};
|