1 /* 2 * Naos Framework 3 * 4 * LICENSE 5 * http://www.naos-framework.com/website.naos.framework/en/license 6 * 7 * Copyright (c) 2008 Jupiter GmbH 8 */ 9 10 /** 11 * Creates a new dialog object which allows you to display 12 * dialogs in an easy and standardized way.<br/><br/> 13 * 14 * The following types are provided at the moment:<br/><br/> 15 * 16 * <strong>replace:</strong> This allows you to define the place of the dialog by an ID 17 * in the DOM tree of your browser. The attribute "position" has to be 18 * conform to the format "id:<DOM ID>".<br/><br/> 19 * 20 * <strong>modalbox:</strong> Uses Modalbox to display the dialog. The attribute "position" 21 * is not used at the moment.<br/><br/> 22 * 23 * Please use the {@link NaosDialog.openDialog} and 24 * {@link NaosDialog.closeDialog} methods for opening and closing dialogs. 25 * 26 * @param moduleId ID of the assigned module 27 * @param dialogId ID of the dialog 28 * @param type Type of the dialog. See description of types above. 29 * @param position Position of the dialog. See description above. 30 * @param output An HTML string for the dialog output. 31 * 32 * @constructor 33 * @private 34 */ 35 function NaosDialog(/**String*/ moduleId, /**String*/ dialogId, /**String*/ type, /**String*/ position, /**String*/ output) { 36 37 /** 38 * @see NaosDialog 39 * @private 40 */ 41 this.moduleId = moduleId; 42 43 /** 44 * @see NaosDialog 45 * @private 46 */ 47 this.dialogId = dialogId; 48 49 /** 50 * @see NaosDialog 51 * @private 52 */ 53 this.type = type; 54 55 /** 56 * @see NaosDialog 57 * @private 58 */ 59 this.position = position; 60 61 /** 62 * @see NaosDialog 63 * @private 64 */ 65 this.output = output; 66 67 /** 68 * This cache stores a pointer to the DOM element in case 69 * we have type="replace". 70 * @private 71 */ 72 this.cacheTypeReplaceElement = null; 73 74 /** 75 * This cache stores all removed children the DOM element in case 76 * we have type="replace". These are restored when we hide the dialog. 77 * @private 78 */ 79 this.cacheTypeReplaceChildren = null; 80 81 /** 82 * Displays the dialog described by the NaosDialog object. 83 * @private 84 */ 85 this.show = function() { 86 87 if(this.type == 'replace') { 88 89 var id = this.position.split(':'); 90 if(id.length != 2 || id[0] != 'id') { 91 NaosDebug.debug('[NaosDialog]: Invalid position for dialog defined. Note: id mode supported only at the moment.'); 92 return; 93 } 94 95 this.cacheTypeReplaceElement = $(id[1]); 96 if(!this.cacheTypeReplaceElement) { 97 NaosDebug.debug('[NaosDialog]: Element id not found.'); 98 return; 99 } 100 101 this.cacheTypeReplaceChildren = new Array(); 102 103 $A(this.cacheTypeReplaceElement.childNodes).each(function(item) { 104 this.cacheTypeReplaceElement.removeChild(item); 105 this.cacheTypeReplaceChildren.push(item); 106 }.bind(this)); 107 108 this.cacheTypeReplaceElement.innerHTML = this.output; 109 110 } else if(this.type == 'modalbox') { 111 Modalbox.show('<div>'+this.output+'</div>', {title: naosConfig.application.title}); 112 } 113 } 114 115 /** 116 * Hides the dialog described by the NaosDialog object. 117 * @param temporary Indicates a temporary hide operation on this dialog. 118 * @private 119 */ 120 this.hide = function(/**boolean*/ temporary) { 121 122 if(this.type == 'replace') { 123 124 this.cacheTypeReplaceElement.innerHTML = ''; 125 126 this.cacheTypeReplaceChildren.each(function(item) { 127 this.cacheTypeReplaceElement.appendChild(item); 128 }.bind(this)); 129 130 this.cacheTypeReplaceChildren = null; 131 this.cacheTypeReplaceElement = null; 132 133 } else if(this.type == 'modalbox') { 134 if(temporary == false && Modalbox.initialized == true) 135 Modalbox.hide(); 136 } 137 } 138 } 139 140 /** 141 * Array of all dialog instances 142 * @type Array 143 * @private 144 */ 145 NaosDialog._dialogs = new Array(); 146 147 /** 148 * Opens a new dialog. 149 * 150 * See {@link NaosDialog} for a detailed description of the 151 * parameters. 152 * 153 * @param moduleId See {@link NaosDialog}. 154 * @param dialogId See {@link NaosDialog}. 155 * @param type See {@link NaosDialog}. 156 * @param position See {@link NaosDialog}. 157 * @param ouput See {@link NaosDialog}. 158 * @type NaosDialog See {@link NaosDialog}. 159 */ 160 NaosDialog.openDialog = function(/**String*/ moduleId, /**String*/ dialogId, /**String*/ type, /**String*/ position, /**String*/ output) { 161 162 for(var i=0; i < NaosDialog._dialogs.length; ++i) 163 { 164 if(NaosDialog._dialogs[i].moduleId == moduleId && NaosDialog._dialogs[i].dialogId == dialogId) 165 { 166 NaosDialog._dialogs[i].hide(true); 167 NaosDialog._dialogs[i] = new NaosDialog(moduleId, dialogId, type, position, output); 168 NaosDialog._dialogs[i].show(); 169 170 return NaosDialog._dialogs[i]; 171 } 172 } 173 174 NaosDialog._dialogs.push(new NaosDialog(moduleId, dialogId, type, position, output)); 175 NaosDialog._dialogs[NaosDialog._dialogs.length-1].show(); 176 177 return NaosDialog._dialogs[NaosDialog._dialogs.length-1]; 178 } 179 180 /** 181 * Closes an existing dialog. 182 * 183 * See {@link NaosDialog} for a detailed description of the 184 * parameters. 185 * 186 * @param moduleId See {@link NaosDialog}. 187 * @param dialogId See {@link NaosDialog}. 188 */ 189 NaosDialog.closeDialog = function(/**String*/ moduleId, /**String*/ dialogId) { 190 for(var i=0; i < NaosDialog._dialogs.length; ++i) 191 { 192 if(NaosDialog._dialogs[i].moduleId == moduleId && NaosDialog._dialogs[i].dialogId == dialogId) 193 { 194 NaosDialog._dialogs[i].hide(false); 195 NaosDialog._dialogs.splice(i, 1); 196 } 197 } 198 } 199