/****************************************\ * Author: Fabio R. Panettieri * * Date: 13-07-2008 * * Email: frenzo.panettieri@concatel.com * * CVT Argentina * * -------------------------------------- * * Class used to draw Popups * \****************************************/ /** * Generic popup * * Usage: * pop = new PopUp({[configuration]}); * * @return: * Popup instance * * Parameters: * @type: * String indicating the type of popup that must be constructed * Ex.: type: "ListFilter" * * @modal: * Boolean * Indicates if other actions should be blocked * * @bg: * String ('transparent','light','dark') * Indicates the type of background that should be used * Notice, that this background is only displayed in modal popups * * @width: * String (px / %) * Required width * Default: 100px * ex.: width: 100px / 40% * * @height: * String (px / %) * Required height * Default: 100px * ex.: height: 100px / 40% * * @top: * String (px / %) * Required top * Default: 100px * ex.: top: 100px / 40% * * @left: * String (px / %) * Required left * Default: 100px * ex.: left: 100px / 40% * * * All other parameters are passed to the real popup implementation * */ function Popup(n){ this.drawed = false; this.visible = false; this.configured = false; this.n = n; /* * Read configuration parameters * Options must be passed as a single JSON object */ this.configure = function(options){ /* set default parameters */ if (typeof options == "undefined") { var opt = {}; } else { opt = options; } // TODO: Remove this in production! if (typeof opt.type == "undefined") { //alert("ERROR!, a type must be expecified for the current popup"); return false; } if (typeof opt.modal == "undefined") { opt.modal = false; } if (typeof opt.bg == "undefined") { opt.bg = 'light'; } if (typeof opt.width == "undefined") { opt.width = '100px'; } if (typeof opt.height == "undefined") { opt.height = '100px'; } if(typeof opt.top == "undefined"){ opt.top = "centered"; } if(typeof opt.left == "undefined"){ opt.left = "centered"; } this.type = opt.type.toLowerCase(); this.modal = opt.modal; this.bg = opt.bg.toLowerCase(); /* Create the real implementation and configure it */ this.imp = PopupFactory.get(this.type); this.imp.configure(options); this.imp.n = this.n; /* Position and size */ this.width = opt.width; this.height = opt.height; this.left = opt.left; this.top = opt.top; this.configured = true; } /* Create DOM element, and make the request for it's real contents */ this.draw = function(){ if($('.popup-container').size() == 0){ $('body').append(''); } if(this.drawed == false){ str =''; /* Create main container */ $('.popup-container').append(str); /* Set the new popup as active */ PopupManager.setActive(this); /* Tell the implementation to load it's contents */ this.imp.load(); this.bindEvents(); this.drawed = true; Common.centerPopup(); } else{ this.show(); } } this.refresh = function(){ try{ this.imp.refresh(); } catch(error){ //TODO: ERROR HANDLING? } } this.bindEvents = function(){ $(this.getSelector() + ' .popup-body').mouseover(function(){ var n = $(this).parents('.popup-window').attr('n'); PopupManager.setActive(PopupManager.get(n)); } ); } this.getSelector = function(){ return '.popup-window[@n="' + this.n + '"]'; } /* Show hidden Popup */ this.show = function(){ var obj = $(this.getSelector()); if(obj.size() > 0){ obj.show(); } this.visible = true; } /* Hide visible Popup */ this.hide = function(){ var obj = $(this.getSelector()); if(obj.size() > 0){ obj.hide(); } this.visible = false; } /* Remove DOM element */ this.close = function(){ var obj = $(this.getSelector()); if(obj.size() > 0){ //obj.unbind(); obj.remove(); } if($('.popup-window').size() == 0){ $('.popup-container').remove(); } this.drawed = false; this.visible = false; } }