/****************************************\ * Author: Batman * * Date: 31-07-2008 * * Email: batman@gmail.com * * * \****************************************/ /** * This class has the responsability to manage popup * instances, and the data related to them * It requires DynamicLoader to work properly * * Usage: * var MyPopup = PopupManager.create() * PopupManager.close(MyPopup.n) * * PopupManager.save(MyPopup) * PopupManager.get(MyPopup.n) * */ /* Single instance */ if (typeof PopupManager == 'undefined'){ var PopupManager = {}; /** * An asociative array. * This list contains popups, indexed by it's corresponding 'n' */ PopupManager.array = new Array(); PopupManager.tpl = new Array(); PopupManager.n = 0; PopupManager.active = null; /* Create new popup, register it and return the instance */ PopupManager.create = function(){ do{ PopupManager.n += 1; }while($('.popup-window[@n="' + PopupManager.n + '"]').size() > 0); var n = PopupManager.n; var p = new Popup(n); PopupManager.array[n] = p; return p; } /* Load configured templates files */ PopupManager.loadTemplates = function(){ /* $.ajax({ async: true, cache: false, url: 'include.so?tpl=listFilterTemplate', success: function(data){ PopupManager.tpl['listfilter'] = data; } }); */ } /* Destroy indicated popup. Return false in case of error */ PopupManager.close = function(n){ try{ var p = PopupManager.array[n]; p.close(); delete PopupManager.array[n]; return true; } catch(error){ return false; } } /* Get the active popup, if it exists */ PopupManager.getActive = function(){ return PopupManager.active; } /* Set active popup */ PopupManager.setActive = function(p){ PopupManager.active = p; } /* Return indicated popup, if it exists. Return null in case of error */ PopupManager.get = function(n){ try{ var p = PopupManager.array[n]; return p; } catch(error){ return null; } } /* Replace the indicated popup */ PopupManager.save = function(p){ PopupManager.array[p.n] = p; } PopupManager.loadTemplates(); }