Index: trunk/core/admin_templates/js/ajax.js =================================================================== diff -u -N -r6656 -r7391 --- trunk/core/admin_templates/js/ajax.js (.../ajax.js) (revision 6656) +++ trunk/core/admin_templates/js/ajax.js (.../ajax.js) (revision 7391) @@ -1,7 +1,20 @@ +function preg_print_pre(obj, reg) +{ + if (!reg) reg = /.*/; + var p = '' + for (var prop in obj) { + if (prop.match(reg) ) { + p += prop + ': '+obj[prop] + '\n' + } + } + alert(p) +} + + // Main AJAX classs function Request() {} -Request.timeout = 5000; //5 seconds +Request.timeout = 15000; //5 seconds Request.method = 'GET'; Request.headers = new Array(); Request.params = null; @@ -24,12 +37,18 @@ if (req.readyState == 4) { p_busyReq = false; window.clearTimeout(toId); - if (req.status == 200) { - p_successCallBack(req, p_pass, p_object); - } else { - p_errorCallBack(req, p_pass, p_object); + try { + if (req.status == 200) { + // preg_print_pre(req) + p_successCallBack(req, p_pass, p_object); + } else { + p_errorCallBack(req, p_pass, p_object); + } + Request.hideProgress(p_progId); } - Request.hideProgress(p_progId); + catch (e) { +// alert('AJAX error') + } } } var $ajax_mark = (p_url.indexOf('?') ? '&' : '?') + 'ajax=yes'; @@ -201,6 +220,7 @@ } AjaxProgressBar.prototype.Query = function() { +// prompt('requestinng', this.URL); Request.makeRequest(this.URL, this.BusyRequest, '', this.successCallback, this.errorCallback, '', this); } @@ -254,4 +274,51 @@ document.getElementById('progress_bar[done]').style.width = $display_progress + '%'; document.getElementById('progress_bar[left]').style.width = (100 - $display_progress) + '%'; return $percent < 100 ? true : false; +} + +// AJAX PopupManager class +function AjaxPopupManager($url) { + this.URL = $url; + this.ResponceFunction = null; + this.PopupSizes = new Array(); +} + +AjaxPopupManager.prototype.GetSize = function ($template) { + if (typeof this.ResponceFunction != 'function') { + alert ('Please define responce function first'); + } + + if (!isset(this.PopupSizes[$template])) { + var $url = this.URL + '&type=GetPopupSize&template_name=' + $template; +// alert('from ajax: '+$url); + Request.makeRequest($url, this.BusyRequest, '', this.successCallback, this.errorCallback, ['GetSize', $template], this); + } + else { +// alert('from cache'); + this.ResponceFunction(this.PopupSizes[$template]); + } +} + +AjaxPopupManager.prototype.successCallback = function($request, $params, $object) { + var $responce = $request.responseText; + var $match_redirect = new RegExp('^#redirect#(.*)').exec($responce); + if ($match_redirect != null) { + // redirect to external template requested + window.location.href = $match_redirect[1]; + return false; + } + + switch ($params[0]) { + case 'GetSize': + // store responce to cache for future use + $object.PopupSizes[ $params[1] ] = $responce; + break; + } + + $object.ResponceFunction($responce); + $object.ResponceFunction = null; // reset responce function +} + +AjaxPopupManager.prototype.errorCallback = function($request, $params, $object) { + alert('AJAX Error; class: AjaxPopupManager; ' + Request.getErrorHtml($request)); } \ No newline at end of file