diff --git a/CRM/Sepa/Form/CreateMandate.php b/CRM/Sepa/Form/CreateMandate.php index 77395528..a6eba8a5 100644 --- a/CRM/Sepa/Form/CreateMandate.php +++ b/CRM/Sepa/Form/CreateMandate.php @@ -211,11 +211,12 @@ public function buildQuickForm() { $this->add('hidden', 'replace', $this->replace_id); // add the replace date - $this->addDate( + $this->add('datepicker', 'rpl_end_date', E::ts("Replacement Date"), + ['formatType' => 'activityDate'], $this->replace_id, - array('formatType' => 'activityDate')); + ['time' => FALSE]); // add the replacement/cancel reason $this->add( @@ -227,19 +228,21 @@ public function buildQuickForm() { // add OOFF fields // add collection date - $this->addDate( + $this->add('datepicker', 'ooff_date', E::ts("Collection Date"), + ['formatType' => 'activityDate'], FALSE, - array('formatType' => 'activityDate')); + ['time' => FALSE]); // add RCUR fields // add start date - $this->addDate( + $this->add('datepicker', 'rcur_start_date', E::ts("Start Date"), + ['formatType' => 'activityDate'], FALSE, - array('formatType' => 'activityDate')); + ['time' => FALSE]); // add collection day $this->add( @@ -262,15 +265,15 @@ public function buildQuickForm() { ); // add end_date - $this->addDate( + $this->add('datepicker', 'rcur_end_date', E::ts("End Date"), + ['formatType' => 'activityDate'], FALSE, - array('formatType' => 'activityDate')); + ['time' => FALSE]); // finally, add a date field just as a converter - $this->addDate('sdd_converter', 'just for date conversion', FALSE, array('formatType' => 'activityDate')); - + $this->add('datepicker', 'sdd_converter', 'just for date conversion', ['formatType' => 'activityDate'], FALSE, ['time' => FALSE]); // inject JS logic CRM_Core_Resources::singleton()->addScriptFile('org.project60.sepa', 'js/CreateMandate.js'); diff --git a/js/CreateMandate.js b/js/CreateMandate.js index 9756548c..bb2b3882 100644 --- a/js/CreateMandate.js +++ b/js/CreateMandate.js @@ -12,7 +12,8 @@ | written permission from the original author(s). | +--------------------------------------------------------*/ -cj(document).ready(function() { +(function($, _, ts) { + $(document).ready(function($) { /** * Identify and get the jQuery field for the given value */ @@ -24,13 +25,15 @@ cj(document).ready(function() { * Utility function to set the date on the %^$W#$&$&% datepicker elements * PRs welcome :) **/ - function sdd_setDate(fieldname, date) { + function sdd_setDate(fieldname, date, recalculate = true) { let dp_element = cj("#sdd-create-mandate").find("[name^=" + fieldname + "].hasDatepicker"); dp_element.datepicker('setDate', date); // flash the field a little bit to indicate change sdd_getF(fieldname).parent().fadeOut(50).fadeIn(50); - sdd_recalculate_fields(); + if (recalculate) { + sdd_recalculate_fields(); + } } /** @@ -38,15 +41,9 @@ cj(document).ready(function() { * using the sdd_converter element */ function sdd_formatDate(date) { - cj("#sdd-create-mandate") - .find("[name^=sdd_converter].hasDatepicker") - .datepicker('setDate', date); - - return cj("#sdd-create-mandate") - .find("[name^=sdd_converter_display]").val(); + return CRM.utils.formatDate(date); } - // logic to hide OOFF/RCUR fields function sdd_change_type() { let interval = sdd_getF('interval').val(); @@ -134,11 +131,11 @@ cj(document).ready(function() { // parse date and overwrite only if too early let ooff_current = Date.parse(ooff_current_value); if (ooff_earliest > ooff_current) { - sdd_setDate('ooff_date', ooff_earliest); + sdd_setDate('ooff_date', ooff_earliest, false); } } else { // no date set yet? - sdd_setDate('ooff_date', ooff_earliest); + sdd_setDate('ooff_date', ooff_earliest, false); } cj("#sdd_ooff_earliest") .attr('date', ooff_earliest) @@ -156,15 +153,16 @@ cj(document).ready(function() { // parse date and overwrite only if too early let rcur_current = new Date(rcur_current_value); if (rcur_earliest > rcur_current) { - sdd_setDate('rcur_start_date', rcur_earliest); + sdd_setDate('rcur_start_date', rcur_earliest, false); } } else { // no date set yet? - sdd_setDate('rcur_start_date', rcur_earliest); + sdd_setDate('rcur_start_date', rcur_earliest, false); } + cj("#sdd_rcur_earliest") - .attr('date', rcur_earliest) - .text(ts("earliest: %1", {1: sdd_formatDate(rcur_earliest), domain: 'org.project60.sepa'})); + .data('date', rcur_earliest) + .text(ts("earliest: %1", {1: CRM.utils.formatDate(rcur_earliest)})); // CALCULATE SUMMARY TEXT let text = ts("Not enough information", {'domain':'org.project60.sepa'}); @@ -285,10 +283,11 @@ cj(document).ready(function() { // attach earliest link handlers cj("#sdd-create-mandate").find("a.sdd-earliest").click(function() { +console.log('DATE', cj(this).data('date')); if (cj(this).attr('id') == 'sdd_rcur_earliest') { - sdd_setDate('rcur_start_date', new Date(cj(this).attr('date'))); + sdd_setDate('rcur_start_date', $(this).data('date')); } else { - sdd_setDate('ooff_date', new Date(cj(this).attr('date'))); + sdd_setDate('ooff_date', $(this).data('date')); } }); @@ -299,4 +298,5 @@ cj(document).ready(function() { // trigger the whole thing once sdd_creditor_changed(); -}); + }); +})(CRM.$, CRM._, CRM.ts('org.project60.sepa')); diff --git a/templates/CRM/Sepa/Form/CreateMandate.tpl b/templates/CRM/Sepa/Form/CreateMandate.tpl index 2aba54b6..f49cd87a 100644 --- a/templates/CRM/Sepa/Form/CreateMandate.tpl +++ b/templates/CRM/Sepa/Form/CreateMandate.tpl @@ -29,7 +29,7 @@