Index: branches/unlabeled/unlabeled-1.1.2/core/admin_templates/js/ajax.js =================================================================== diff -u -r6734 -r6899 --- branches/unlabeled/unlabeled-1.1.2/core/admin_templates/js/ajax.js (.../ajax.js) (revision 6734) +++ branches/unlabeled/unlabeled-1.1.2/core/admin_templates/js/ajax.js (.../ajax.js) (revision 6899) @@ -254,4 +254,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])) { +// alert('from ajax'); + var $url = this.URL + '&type=GetPopupSize&template_name=' + $template; + 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