advanced search: update history and breadcrumb on search

SVN:trunk[5628]
This commit is contained in:
Bruno Da Silva
2018-04-09 14:25:41 +00:00
parent 234b0e6825
commit df8b73999f
6 changed files with 118 additions and 36 deletions

View File

@@ -174,6 +174,13 @@ class DataTable
}
$sJSOptions = json_encode($aOptions);
$oPage->add_ready_script("$('#datatable_{$this->iListId}').datatable($sJSOptions);");
if (isset($aExtraParams['update_history']) && true == $aExtraParams['update_history'])
{
$sFilter = json_encode(array('filter' => $this->oSet->GetFilter()->serialize()));
$oPage->add_ready_script("$('body').trigger('update_history.itop', [$sFilter])");
}
return $sHtml;
}

View File

@@ -26,7 +26,7 @@ $(function()
{
$(window).bind( 'hashchange', function(e)
{
me._RefreshLatestEntry();
me.RefreshLatestEntry();
});
aBreadCrumb = this._Read();
@@ -129,17 +129,23 @@ $(function()
sessionStorage.setItem(sBreadCrumbStorageKey, sBreadCrumbData);
},
// Refresh the latest entry (navigating to a tab)
_RefreshLatestEntry: function()
RefreshLatestEntry: function(sRefreshHrefTo)
{
aBreadCrumb = this._Read();
var iDisplayableItems = aBreadCrumb.length;
if (this.options.new_entry !== null) {
if (sRefreshHrefTo == undefined)
{
sRefreshHrefTo = window.location.href;
}
// The current page is the last entry in the breadcrumb, let's refresh it
aBreadCrumb[aBreadCrumb.length - 1].url = window.location.href;
$('#itop-breadcrumb .breadcrumb-current:last-of-type a').attr('href', window.location.href);
aBreadCrumb[aBreadCrumb.length - 1].url = sRefreshHrefTo;
$('#itop-breadcrumb .breadcrumb-current:last-of-type a').attr('href', sRefreshHrefTo);
}
this._Write(aBreadCrumb);
}
},
});
});

View File

@@ -189,7 +189,7 @@ $(function()
var odatetimepickerOptions = $.extend({}, odatetimepickerOptionsDefault, me.options.datepicker, {
var odatetimepickerOptions = $.extend({}, oInputParam.picker_extra_params, odatetimepickerOptionsDefault, me.options.datepicker, {
onSelect: function() {
fHandleSynchCallback(this, false);
$(this).focus();

View File

@@ -15,50 +15,72 @@ $(function()
// 'available_operators': {
//
// },
// aInputsParam: [
// {
// "code": "from",
// "code_uc_first":"From",
// "x_picker" : 'datepicker',
// "default_time_add": false,
// "show_on_advanced": false,
// "value_index": 0,
// "onclose_show" : "until",
// "synced_with": "from_time",
// //"getter_code":"from_time",
// "getter_suffix":" 00:00:00",
// },
// {
// "code": "from_time",
// "code_uc_first":"FromTime",
// "x_picker" : 'datetimepicker',
// "default_time_add": 0,
// "show_on_advanced": true,
// "value_index": 0,
// "onclose_show" : "until_time",
// "synced_with": "from",
// "title_getter_code":"from",
// },
// {
// "code": "until",
// "code_uc_first":"Until",
// "x_picker" : 'datepicker',
// "default_time_add": false,
// "show_on_advanced": false,
// "value_index": 1,
// "synced_with": "until_time",
// //"getter_code":"until_time",
// "getter_suffix":" 23:59:59",
// },
// {
// "code": "until_time",
// "code_uc_first":"UntilTime",
// "x_picker" : 'datetimepicker',
// "default_time_add": 86399, // 24 * 60 * 60 - 1
// "show_on_advanced": true,
// "value_index": 1,
// "synced_with": "until",
// "title_getter_code":"until",
// }
// ]
aInputsParam: [
{
"code": "from",
"code_uc_first":"From",
"x_picker" : 'datepicker',
"default_time_add": false,
"show_on_advanced": false,
"value_index": 0,
"onclose_show" : "until",
"synced_with": "from_time",
//"getter_code":"from_time",
"getter_suffix":" 00:00:00",
},
{
"code": "from_time",
"code_uc_first":"FromTime",
"x_picker" : 'datetimepicker',
"default_time_add": 0,
"show_on_advanced": true,
"value_index": 0,
"onclose_show" : "until_time",
"synced_with": "from",
"title_getter_code":"from",
},
{
"code": "until",
"code_uc_first":"Until",
"x_picker" : 'datepicker',
"default_time_add": false,
"show_on_advanced": false,
"value_index": 1,
"synced_with": "until_time",
//"getter_code":"until_time",
"getter_suffix":" 23:59:59",
},
{
"code": "until_time",
"code_uc_first":"UntilTime",
"x_picker" : 'datetimepicker',
"default_time_add": 86399, // 24 * 60 * 60 - 1
"show_on_advanced": true,
// "default_time_add": 86399, // 24 * 60 * 60 - 1
"picker_extra_params": {
"hour": 23,
"minute":59,
"second":59
},
"value_index": 1,
"synced_with": "until",
"title_getter_code":"until",
}
]
},

View File

@@ -168,6 +168,52 @@ $(function()
this.element.on('itop.search.criteria.error_occured', function(oEvent, oData){
me._onCriteriaErrorOccured(oData);
});
$('body').on('update_history.itop', function(event, filter) {
if (! me.element.is(':visible'))
{
return;
}
if ($(':itop-search_form_handler:visible').length != 1)
{
me._trace('history not updated because several search widget are visible');
return;
}
me._trace('history update', filter);
var newUrl = GetAbsoluteUrlAppRoot()+'pages/UI.php?operation=search';
newUrl = newUrl + '&filter='+filter['filter'];
newUrl = newUrl + '&c[menu]='+me._extractURLParameter(window.location.href, "c[menu]");
history.replaceState(null, null, newUrl);
$('#itop-breadcrumb').breadcrumb('RefreshLatestEntry', newUrl);
});
},
_extractURLParameter: function(url, parameter) {
//prefer to use l.search if you have a location/link object
var urlparts= url.split('?');
if (urlparts.length>=2) {
var prefix = [
parameter+'=',
encodeURIComponent(parameter)+'='
];
var pars = urlparts[1].split(/[&;]/g);
for (var i = 0; i < pars.length; i++) {
for (var j = 0; j < prefix.length; j++) {
var pos = pars[i].lastIndexOf(prefix[j], 0);
if (pos !== -1) {
return pars[i].substring(pos);
}
}
}
}
return null;
},
// - Update search option of the widget
_updateSearch: function()

View File

@@ -106,6 +106,7 @@ try
$aExtraParams['display_limit'] = true;
$aExtraParams['truncated'] = true;
$aExtraParams['update_history'] = true;
if (isset($sListId))
{
$oDisplayBlock->Display($oPage, $sListId, $aExtraParams);