diff --git a/application/datatable.class.inc.php b/application/datatable.class.inc.php index 86f13aada..c12e03183 100644 --- a/application/datatable.class.inc.php +++ b/application/datatable.class.inc.php @@ -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; } diff --git a/js/breadcrumb.js b/js/breadcrumb.js index d18cfc217..e8fc88a6f 100644 --- a/js/breadcrumb.js +++ b/js/breadcrumb.js @@ -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); - } + }, + }); }); diff --git a/js/search/search_form_criteria_date_abstract.js b/js/search/search_form_criteria_date_abstract.js index b1e84c67a..d3bba1cf6 100644 --- a/js/search/search_form_criteria_date_abstract.js +++ b/js/search/search_form_criteria_date_abstract.js @@ -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(); diff --git a/js/search/search_form_criteria_date_time.js b/js/search/search_form_criteria_date_time.js index e849f50d3..6c5a955f5 100644 --- a/js/search/search_form_criteria_date_time.js +++ b/js/search/search_form_criteria_date_time.js @@ -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", } ] }, diff --git a/js/search/search_form_handler.js b/js/search/search_form_handler.js index 90ebb933c..a3681afe0 100644 --- a/js/search/search_form_handler.js +++ b/js/search/search_form_handler.js @@ -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() diff --git a/pages/ajax.searchform.php b/pages/ajax.searchform.php index faa25a183..ec161ae48 100644 --- a/pages/ajax.searchform.php +++ b/pages/ajax.searchform.php @@ -106,6 +106,7 @@ try $aExtraParams['display_limit'] = true; $aExtraParams['truncated'] = true; + $aExtraParams['update_history'] = true; if (isset($sListId)) { $oDisplayBlock->Display($oPage, $sListId, $aExtraParams);