From: Janusz Dobrowolski Date: Mon, 20 Apr 2009 08:25:39 +0000 (+0000) Subject: Added retry after ajax request timeout, preparation for client-side X-Git-Tag: 2.3-final~1276 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=10dced7e75209f8158e4e1fa250bfbf91cfaa182;hp=f3b8f779e700711cf786386d71e7cde766398ba6;p=fa-stable.git Added retry after ajax request timeout, preparation for client-side entry validaton. --- diff --git a/includes/current_user.inc b/includes/current_user.inc index 023591d3..f0aa525c 100644 --- a/includes/current_user.inc +++ b/includes/current_user.inc @@ -318,14 +318,13 @@ function add_user_js_data() { $ts = $thoseps[user_tho_sep()]; $ds = $decseps[user_dec_sep()]; - $js = "\n"; + . "pdec : " . user_price_dec() . "}\n"; add_js_source($js); } diff --git a/includes/page/footer.inc b/includes/page/footer.inc index 2ce07a29..29900c7d 100644 --- a/includes/page/footer.inc +++ b/includes/page/footer.inc @@ -11,7 +11,7 @@ ***********************************************************************/ function page_footer($no_menu=false, $is_index=false) { - global $path_to_root; + global $path_to_root, $js_lib; if (in_ajax()) return;// just for speed up @@ -21,6 +21,14 @@ function page_footer($no_menu=false, $is_index=false) include_once($path_to_root."/themes/".user_theme()."/renderer.php"); $rend = new renderer(); $rend->menu_footer($no_menu, $is_index); + + add_user_js_data(); + echo "\n\n"; echo "\n"; } diff --git a/includes/page/header.inc b/includes/page/header.inc index 6abf7c93..197f27fb 100644 --- a/includes/page/header.inc +++ b/includes/page/header.inc @@ -41,8 +41,6 @@ function send_scripts() global $js_lib, $js_static, $js_path, $js_userlib, $comp_path, $path_to_root, $go_debug; - add_user_js_data(); - $js =''; foreach($js_static as $jsfile) { @@ -60,10 +58,6 @@ function send_scripts() $jsfile . '">'; } - foreach($js_lib as $text) - { - $js .= $text; - } echo $js; } @@ -75,6 +69,11 @@ function page_header($title, $no_menu=false, $is_index=false, $onload="", $js="" if (in_ajax()) return; // just for speed up +// $jsext = substr_replace($_SERVER['PHP_SELF'], '.js', -4); + +// if (file_exists($_SERVER['DOCUMENT_ROOT'].$jsext)) +// add_js_ufile($jsext); + $theme = user_theme(); $local_path_to_root = $path_to_root; diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 1d4f1fc1..1e43fdf9 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -650,16 +650,12 @@ function display_quick_entries(&$cart, $id, $base, $type, $descr='') function get_js_open_window($width, $height) { - $js = "\n\n"; + . "}\n"; return $js; } @@ -683,8 +679,7 @@ function default_focus($name, $form_no=0) { function get_js_png_fix() { - $js = "\n"; + . "}\n"; return $js; } diff --git a/js/inserts.js b/js/inserts.js index 8e18e5c3..4dfa2009 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -13,22 +13,13 @@ var _hotkeys = { 'alt': false, // whether is the Alt key pressed 'focus': -1 // currently selected indeks of document.links }; +var _validate = {}; // validation functions function debug(msg) { box = document.getElementById('msgbox') box.innerHTML= box.innerHTML+'
'+msg } -function progbar() { - box = document.getElementById('msgbox'); - box.innerHTML= "
" - +"
" - +""
-		+user.loadtxt+"

"; - box.style.display = 'block'; -} - function save_focus(e) { _focus = e.name||e.id; var h = document.getElementById('hints'); @@ -215,15 +206,34 @@ var inserts = { e.style.display = 'block'; }, // '.ajaxsubmit,.editbutton,.navibutton': // much slower on IE7 - 'button.ajaxsubmit,input.ajaxsubmit,input.editbutton,button.navibutton': + 'button.ajaxsubmit,input.ajaxsubmit,input.editbutton,button.editbutton,button.navibutton': function(e) { - e.onclick = function() { - if (this.getAttribute('aspect') == 'process') - progbar(); - save_focus(this); - JsHttpRequest.request(this); - return false; - } + e.onclick = function() { + save_focus(e); + if (e.getAttribute('aspect') == 'process') + JsHttpRequest.request(this, null, 30000); + else + JsHttpRequest.request(this); + return false; + } + }, + 'button': function(e) { + if (e.name) { + var func = eval("_validate."+e.name); + var old = e.onclick; + if(func) { + if (typeof old != 'function') { + e.onclick = func; + } else { + e.onclick = function() { + if(func()) + { old(); return true;} + else + return false; + } + } + } + } }, '.amount': function(e) { if(e.onblur==undefined) { diff --git a/js/utils.js b/js/utils.js index 98733d66..b8055c99 100644 --- a/js/utils.js +++ b/js/utils.js @@ -8,6 +8,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +function set_mark(img) { + var box = document.getElementById('ajaxmark'); + if(img) box.src = user.theme+'images/'+ img; + box.style.visibility = img ? 'visible' : 'hidden' +} + // // JsHttpRequest class extensions. // @@ -18,9 +24,14 @@ // if form parameter exists also form values are submited, otherwise // request is directed to current location // - JsHttpRequest.request= function(trigger, form) { - var mark = document.getElementById('ajaxmark'); - if(mark) mark.style.visibility = 'visible'; +JsHttpRequest.request= function(trigger, form, tout) { + tout = tout | 3000; // default timeout value + set_mark(tout>5000 ? 'progressbar.gif' : 'ajax-loader.gif'); + JsHttpRequest._request(trigger, form, tout, 2); +} + +JsHttpRequest._request = function(trigger, form, tout, retry) { + if (trigger.tagName=='A') { var content = {}; var upload = 0; @@ -41,12 +52,29 @@ if (!form) url = url.substring(0, url.indexOf('?')); - if (!submitObj) + if (!submitObj) { content[trigger] = 1; - + } } // this is to avoid caching problems content['_random'] = Math.random()*1234567; + + var tcheck = setTimeout( + function() { + for(var id in JsHttpRequest.PENDING) { + var call = JsHttpRequest.PENDING[id]; + if (call != false) { + if (call._ldObj.xr) // needed for gecko + call._ldObj.xr.onreadystatechange = function(){}; + call.abort(); // why this doesn't kill request in firebug? +// call._ldObj.xr.abort(); + delete JsHttpRequest.PENDING[id]; + } + } + set_mark(retry ? 'ajax-loader2.gif':'warning.png' ); + if(retry) + JsHttpRequest._request(trigger, form, tout, retry-1); + }, tout ); JsHttpRequest.query( (upload ? "form." : "")+"POST "+url, // force form loader @@ -91,11 +119,11 @@ errors = errors+'
Unknown ajax function: '+cmd; } } - + if(tcheck) + JsHttpRequest.clearTimeout(tcheck); // Write errors to the debug div. document.getElementById('msgbox').innerHTML = errors; - var mark = document.getElementById('ajaxmark'); - if(mark) mark.style.visibility = 'hidden'; + set_mark(); Behaviour.apply(); @@ -108,9 +136,9 @@ } } }, - false // do not disable caching + false // do not disable caching ); - } + } // collect all form input values plus inp trigger value JsHttpRequest.formInputs = function(inp, objForm, upload) {