Bugzilla – Attachment 188204 Details for
Bug 41061
No longer need to validate dates manually
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41061: Remove unused calendar JS functions
Bug-41061-Remove-unused-calendar-JS-functions.patch (text/plain), 6.83 KB, created by
Jonathan Druart
on 2025-10-21 09:27:04 UTC
(
hide
)
Description:
Bug 41061: Remove unused calendar JS functions
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-10-21 09:27:04 UTC
Size:
6.83 KB
patch
obsolete
>From 44b7c70bedeab46036e434b7e3ab381b39dfa919 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 21 Oct 2025 11:19:40 +0200 >Subject: [PATCH] Bug 41061: Remove unused calendar JS functions > >Since the introduction of Maskito by bug 33703 we do no longer need to >valid dates when the flatpickr widget is closed. > >This patch removes the following JS function from staff and OPAC: >* is_valid_date >* validate_date >* get_dateformat_str > >Test plan: >0. Do not apply this patch and confirm that the date string received by > those functions has already been correctly formatted >1. Apply the patch and git grep to make sure no occurrence exists in the > code >2. Confirm that you are still able to select dates with flatpickr >--- > .../prog/en/includes/calendar.inc | 1 - > koha-tmpl/intranet-tmpl/prog/js/calendar.js | 47 ------------------ > koha-tmpl/intranet-tmpl/prog/js/onboarding.js | 1 - > .../bootstrap/en/includes/calendar.inc | 48 ------------------- > 4 files changed, 97 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >index 1437f2e157f..f134dcdc912 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >@@ -144,7 +144,6 @@ > } > }, > onClose: function( selectedDates, dateText, instance) { >- validate_date( dateText, instance ); > var thisInput = instance.input; > if ( thisInput.hasAttribute('data-date_to') ) { > var endPicker = document.querySelector("#"+thisInput.dataset.date_to)._flatpickr; >diff --git a/koha-tmpl/intranet-tmpl/prog/js/calendar.js b/koha-tmpl/intranet-tmpl/prog/js/calendar.js >index e1637b2ba71..7d35b680d49 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/calendar.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/calendar.js >@@ -9,53 +9,6 @@ if (debug > 1) { > ); > } > >-function is_valid_date(date) { >- // An empty string is considered as a valid date for convenient reasons. >- if (date === "") return 1; >- var dateformat = flatpickr_dateformat_string; >- if (dateformat == "us") { >- if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; >- dateformat = "m/d/Y"; >- } else if (dateformat == "metric") { >- if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; >- dateformat = "d/m/Y"; >- } else if (dateformat == "iso") { >- if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0; >- dateformat = "Y-m-d"; >- } else if (dateformat == "dmydot") { >- if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0; >- dateformat = "d.m.Y"; >- } >- 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) { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/onboarding.js b/koha-tmpl/intranet-tmpl/prog/js/onboarding.js >index 31937eca685..339b341d990 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/onboarding.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/onboarding.js >@@ -130,7 +130,6 @@ $(document).ready(function () { > return $("#enrolmentperiod").val() === ""; > }, > enrollment_period: true, >- // is_valid_date ($(#"enrolementperioddate").val()); > }, > dateofbirthrequired: { > digits: true, >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >index 240fa9953c3..3f9d1dd78bb 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc >@@ -42,20 +42,6 @@ > altinput_dateformat = 'yyyy/mm/dd'; > delimiter = "-"; > } >- >- 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; >- } > </script> > [% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %] > [% Asset.js("lib/maskito/maskito.core.js") | $raw %] >@@ -117,7 +103,6 @@ > new Maskito(instance.altInput, options); > }, > onClose: function (selectedDates, dateText, instance) { >- validate_date(dateText, instance); > var thisInput = instance.input; > if (thisInput.hasAttribute("data-start_for")) { > var endPicker = document.querySelector("#" + thisInput.dataset.start_for)._flatpickr; >@@ -128,39 +113,6 @@ > > var MSG_PLEASE_ENTER_A_VALID_DATE = _("Please enter a valid date (should match %s)."); > >- function is_valid_date(date) { >- // An empty string is considered as a valid date for convenient reasons. >- if (date === "") return 1; >- var dateformat = flatpickr_dateformat_string; >- switch (dateformat_pref) { >- case "us": >- flatpickr_dateformat_string = "m/d/Y"; >- break; >- case "metric": >- flatpickr_dateformat_string = "d/m/Y"; >- break; >- case "dmydot": >- flatpickr_dateformat_string = "d.m.Y"; >- break; >- default: >- flatpickr_dateformat_string = "Y-m-d"; >- } >- try { >- flatpickr.parseDate(date, dateformat); >- } catch (e) { >- return 0; >- } >- return 1; >- } >- >- 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(); >- } >- } >- > $(document).ready(function () { > $(".flatpickr").each(function () { > let options = {}; >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41061
: 188204