From: Joe Hunt Date: Thu, 8 Mar 2018 14:24:10 +0000 (+0100) Subject: Ajax Inquiry Fixes (Braatwaate). X-Git-Tag: v2.4.4~6 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=9738f7d64641df18b688f0d03a3b62c93f40e0c7 Ajax Inquiry Fixes (Braatwaate). --- diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 37c17432..b65339ef 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -1546,3 +1546,44 @@ function trans_editor_link($type, $trans_no) (is_closed_trans($type, $trans_no) ? set_icon(ICON_CLOSED, _('Closed')) : pager_link(_("Edit"), sprintf($editor_url[$type], $trans_no, $type), ICON_EDIT)); } + +// This script updates the browser history when +// any of the passed variables change. +// This way, if the user changes these variables, +// then uses the back button to return, it returns to the page +// as the user modified it. +function get_js_history(...$vars) +{ + $js = ' + function changeVar() { + var stateObj = { foo: "bar" }; + var state = ""; +'; + + $first = true; + foreach ( $vars as $var ) { + $js .= ' + var element = document.getElementsByName("' . $var. '"); + if (element[0])'; + if ($first) { + $first = false; + $js .= ' + state += "' . basename($_SERVER['SCRIPT_NAME']) . "?"; + } else + $js .= ' + state += "&'; + $js .= $var .'="' . ' + element[0].value;'; + } + + $js .= ' + history.replaceState(stateObj, "page 2", state); + }'; + return $js; +} + +function set_posts(...$vars) +{ + foreach ( $vars as $var ) + if (isset($_GET[$var])) + $_POST[$var] = $_GET[$var]; +} diff --git a/js/inserts.js b/js/inserts.js index 17b71143..de9e8d4a 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -153,6 +153,8 @@ function _set_combo_select(e) { var sname = '_'+s.name+'_update'; var update = document.getElementsByName(sname)[0]; if(update) { + if (typeof changeVar === "function") + changeVar(); JsHttpRequest.request(update); } } @@ -335,6 +337,9 @@ var inserts = { function(e) { e.onclick = function() { if (validate(e)) { + if (typeof changeVar === "function") + changeVar(); + save_focus(e); var asp = e.getAttribute('aspect') if (asp && (asp.indexOf('process') !== -1))