bugfix: advanced search

- date i18n : non standard date formating was totally wrong, full rewrite of date parsing (in getter and setter) relying on datepicker and datetimepicker parsers (they are awfull)
- date "now" button do no more close the criteria
- ie9 compat. : use history.replaceState only if available in order to prevent bugs with ie9

SVN:trunk[5710]
This commit is contained in:
Bruno Da Silva
2018-04-20 14:32:32 +00:00
parent ef7a9ff02e
commit ed3665b8c5
4 changed files with 71 additions and 11 deletions

View File

@@ -22,12 +22,14 @@ $(function()
"x_picker" : 'datepicker',
"value_index": 0,
"onclose_show" : "until",
"has_time": false,
},
{
"code": "until",
"code_uc_first":"Until",
"x_picker" : 'datepicker',
"value_index": 1,
"has_time": false,
}
]
},

View File

@@ -33,6 +33,7 @@ $(function()
// "code_uc_first":"From", => the code used in the translations
// "onclose_show" : "until", => on x_picker close, should we open another one (on "from" close shall we show "until")
// "value_index": 0, => the widget communicate with an array of values, the index 0 is "from" the index 1 is "until"
// "has_time": true, => wether this field need the time (ie: in its formatting)
// Date_time widget specific settings :
// > Beware : a lot of those parameters are unused (the intial dev. tested several different UI before the final choice)
@@ -189,7 +190,7 @@ $(function()
buttonText: "",
showOn:'button',
changeMonth:true,
changeYear:true
changeYear:true,
};
for (var i = 0; i < aInputsParamLength; i++) {
var oInputParam = aInputsParam[i];
@@ -241,18 +242,31 @@ $(function()
for (var i = 0; i < aInputsParamLength; i++) {
var oInputParam = aInputsParam[i];
var oDate = oOpElem.find('input[name="'+oInputParam.code+'"]').datepicker( "getDate" ); //.val();
var sLabel = '';
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 = oOpElem.find('input[name="'+oInputParam.code+'"]').val();
if (typeof oInputParam.show_on_advanced == 'undefined' || bAdvancedMode == oInputParam.show_on_advanced)
{
if (typeof oInputParam.getter_code != 'undefined')
{
sValue = oOpElem.find('input[name="'+oInputParam.getter_code+'"]').val();
}
else if (sLabel != "" && typeof oInputParam.getter_suffix != 'undefined')
{
sValue = sLabel + oInputParam.getter_suffix;
sValue = sLabel; //oOpElem.find('input[name="'+oInputParam.getter_code+'"]').datepicker( "getDate" ); //.val();
//sValue = (sValue == null) ? '' : $.datepicker.formatDate(me.options.datepicker.timeFormat ,sValue);
}
else
{
@@ -282,8 +296,46 @@ $(function()
var sDate = aValues[oInputParam.value_index].value;
if (sDate.trim() != '')
{
var oDate = new Date(sDate);
oInputElem[oInputParam.x_picker]('setDate', oDate);
try
{
if (oInputParam.has_time)
{
var iSpacePos = sDate.indexOf(' ');
if (iSpacePos)
{
var sParsableDate = sDate.substring(0, iSpacePos);
var sParsableTime = sDate.substring(iSpacePos + 1);
}
else
{
var sParsableDate = sDate
var sParsableTime = ''
}
var oDate = $.datepicker.parseDate( me.options.datepicker.dateFormat, sParsableDate );
if ('' != sParsableTime)
{
var oTime = $.datepicker.parseTime( me.options.datepicker.timeFormat, sParsableTime );
oDate.setHours(oTime.hour);
oDate.setMinutes(oTime.minute);
oDate.setSeconds(oTime.second);
}
}
else
{
var oDate = $.datepicker.parseDate( me.options.datepicker.dateFormat, sDate );
}
oInputElem[oInputParam.x_picker]('setDate', oDate);
}
catch (e) {
//the date is not formated (ie : it is the first arrival)
var oDate = new Date(sDate);
oInputElem[oInputParam.x_picker]('setDate', oDate);
}
}
else
{

View File

@@ -69,6 +69,7 @@ $(function()
"default_time_add": 0,
"value_index": 0,
"onclose_show" : "until_time",
"has_time": true,
},
{
"code": "until_time",
@@ -81,6 +82,7 @@ $(function()
"second":59
},
"value_index": 1,
"has_time": true,
}
]
},

View File

@@ -192,7 +192,11 @@ $(function()
sNewUrl = sNewUrl + '&debug='+me._extractURLParameter(window.location.href, "debug");
}
history.replaceState(null, null, sNewUrl);
if (typeof history.replaceState != "undefined")
{
history.replaceState(null, null, sNewUrl);
}
$('#itop-breadcrumb')
.breadcrumb('destroy')
@@ -459,7 +463,7 @@ $(function()
{
// TODO: Try to put this back in the date widget as it introduced a non necessary coupling.
// If using the datetimepicker, do not close anything
if (oEventTargetElem.closest('#ui-datepicker-div, .ui-datepicker-prev, .ui-datepicker-next').length > 0 )
if (oEventTargetElem.closest('#ui-datepicker-div, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-current').length > 0 )
{
// No closing in this case
}