From 9797021511bf35e86bf6dcc2efd64dea439020ce Mon Sep 17 00:00:00 2001 From: Bruno Da Silva Date: Mon, 23 Apr 2018 12:20:48 +0000 Subject: [PATCH] bugfix: advanced search - dates has to handle two format : the user's current and the system storage yyy-mm-dd. the system is now only handled on load ans=d converted to the user's one. - if the date is not parsable, the fallback is now the current date. - removal of a no more needed date setter (leaved in the comments since it may be nescessary to re-add this if the UI changes again and if the less panel has to display the dates without time - factorisatoin of the date/time formating into a function SVN:trunk[5720] --- .../search_form_criteria_date_abstract.js | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/js/search/search_form_criteria_date_abstract.js b/js/search/search_form_criteria_date_abstract.js index 6e638951d..756acf8e5 100644 --- a/js/search/search_form_criteria_date_abstract.js +++ b/js/search/search_form_criteria_date_abstract.js @@ -114,9 +114,15 @@ $(function() .attr('for', oInputElem.attr('id')) ; - if (oInputParam.value_index in aValues && typeof aValues[oInputParam.value_index].value != 'undefined') + //no arrivla, the date is always formated yyy-mm-dd, we need to apply the user's formating and to write it into both the dom and the values array. + if (oInputParam.value_index in aValues && typeof aValues[oInputParam.value_index].value != 'undefined' && aValues[oInputParam.value_index].value != '') { - oInputElem.val(aValues[oInputParam.value_index].value); + var oDate = new Date(aValues[oInputParam.value_index].value); + var sDate = me._formatDate(oDate); + + oInputElem.val(sDate); + this.options.values[oInputParam.value_index].value = sDate; + aValues = me._getValues(); } oContentElem = oContentElem.add(oOpContentElem); @@ -138,7 +144,8 @@ $(function() // Apply if enter key if(oEvent.key === 'Enter') { - me.val(me.val().trim()); + var inputElem = $(this).find('input[type="text"]'); + inputElem.val(inputElem.val().trim()); me._apply(); } }); @@ -249,6 +256,22 @@ $(function() }, + _formatDate: function(oDate, bWithTime = true) + { + var me = this; + + var sLabel = $.datepicker.formatDate(me.options.datepicker.dateFormat , oDate); + if (bWithTime) + { + sLabel = sLabel + ' ' + $.datepicker.formatTime(me.options.datepicker.timeFormat , { + hour: oDate.getHours(), + minute: oDate.getMinutes(), + second: oDate.getSeconds() + }); + } + return sLabel; + }, + _getBetweenDaysOperatorValues: function(oOpElem) { @@ -269,15 +292,16 @@ $(function() if (oDate != null) { - sLabel = $.datepicker.formatDate(me.options.datepicker.dateFormat , oDate); - if (oInputParam.has_time) - { - sLabel = sLabel + ' ' + $.datepicker.formatTime(me.options.datepicker.timeFormat , { - hour: oDate.getHours(), - minute: oDate.getMinutes(), - second: oDate.getSeconds() - }); - } + sLabel = me._formatDate(oDate, oInputParam.has_time); + // sLabel = $.datepicker.formatDate(me.options.datepicker.dateFormat , oDate); + // if (oInputParam.has_time) + // { + // sLabel = sLabel + ' ' + $.datepicker.formatTime(me.options.datepicker.timeFormat , { + // hour: oDate.getHours(), + // minute: oDate.getMinutes(), + // second: oDate.getSeconds() + // }); + // } } @@ -352,8 +376,8 @@ $(function() oInputElem[oInputParam.x_picker]('setDate', oDate); } catch (e) { - //the date is not formated (ie : it is the first arrival) - var oDate = new Date(sDate); + //in theorie, this should not happen, but hey, it do not harm! + var oDate = new Date(); //sDate); oInputElem[oInputParam.x_picker]('setDate', oDate); }