[317] | 1 | function modal(id, type) |
---|
| 2 | { |
---|
| 3 | try{ |
---|
| 4 | content = Element(id).cloneNode(true); |
---|
[5133] | 5 | //Acrescentado para eliminar bug do IE que deixa um formulario inválido, |
---|
| 6 | //se for inserido outro na mesma página com o mesmo ID, ficando ambos inválidos |
---|
[1975] | 7 | content_code = content.innerHTML; |
---|
| 8 | content.innerHTML = content_code.replace("_template",""); |
---|
[317] | 9 | title = Element(id + '_title').value; |
---|
| 10 | width = Element(id + '_width').value; |
---|
| 11 | height = Element(id + '_height').value; |
---|
| 12 | close_action = Element(id + '_close_action').value; |
---|
| 13 | create_action = Element(id + '_create_action').value; |
---|
| 14 | save_action = Element(id + '_save_action').value; |
---|
| 15 | onload_action = Element(id + '_onload_action').value |
---|
| 16 | } |
---|
| 17 | catch(e){} |
---|
| 18 | |
---|
| 19 | var objBody = document.getElementsByTagName("body").item(0); |
---|
| 20 | |
---|
| 21 | /* the Overlay */ // create overlay div and hardcode some functional styles |
---|
| 22 | var objOverlay = document.createElement("div"); |
---|
| 23 | objOverlay.setAttribute('id','overlay'); |
---|
| 24 | objOverlay.style.position = 'absolute'; |
---|
| 25 | objOverlay.style.top = '0'; |
---|
| 26 | objOverlay.style.left = '0'; |
---|
| 27 | objOverlay.style.zIndex = '90'; |
---|
| 28 | objOverlay.style.width = '100%'; |
---|
| 29 | |
---|
| 30 | var arrayPageSize = getPageSize(); |
---|
| 31 | var arrayPageScroll = getPageScroll(); |
---|
| 32 | |
---|
| 33 | // set height of Overlay to take up whole page and insert. Show at the end of this function. |
---|
| 34 | objOverlay.style.height = (arrayPageSize[1] + 'px'); |
---|
| 35 | objOverlay.style.display = 'none'; |
---|
| 36 | objBody.insertBefore(objOverlay, objBody.firstChild); |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | /* the div */ // create lightbox div, same note about styles as above |
---|
| 40 | |
---|
| 41 | var objLightbox = document.createElement("div"); |
---|
| 42 | objLightbox.setAttribute('id','lightbox'); |
---|
| 43 | |
---|
| 44 | objLightbox.style.position = 'absolute'; |
---|
| 45 | objLightbox.style.display = 'none'; |
---|
| 46 | objLightbox.style.zIndex = '100'; |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | var objLightbox_height = height; |
---|
| 50 | var objLightbox_width = width; |
---|
| 51 | |
---|
| 52 | objLightbox.style.height = objLightbox_height + "px"; |
---|
| 53 | objLightbox.style.width = objLightbox_width + "px"; |
---|
| 54 | |
---|
| 55 | var lightboxTop = ((arrayPageSize[3] - objLightbox_height) / 2); |
---|
| 56 | var lightboxLeft = ((arrayPageSize[0] - objLightbox_width) / 2 ); |
---|
| 57 | |
---|
| 58 | objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px"; |
---|
| 59 | objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px"; |
---|
| 60 | |
---|
| 61 | objBody.insertBefore(objLightbox, objOverlay.nextSibling); |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | // create caption |
---|
| 65 | var objCaption = document.createElement("div"); |
---|
| 66 | objCaption.setAttribute('id','lightboxCaption'); |
---|
| 67 | objCaption.innerHTML = title; |
---|
| 68 | objLightbox.appendChild(objCaption); |
---|
| 69 | |
---|
| 70 | // create warnings |
---|
| 71 | var objWarning = document.createElement("div"); |
---|
| 72 | objWarning.setAttribute('id','lightboxWarning'); |
---|
| 73 | objWarning.style.height = '21px'; |
---|
| 74 | objLightbox.appendChild(objWarning); |
---|
| 75 | |
---|
| 76 | // Create Content |
---|
| 77 | var objContent = document.createElement("div"); |
---|
| 78 | objContent.setAttribute('id','lightboxContent'); |
---|
| 79 | objContent.style.height = (objLightbox_height - 65) + "px"; |
---|
| 80 | objContent.innerHTML = content.innerHTML; |
---|
| 81 | objLightbox.appendChild(objContent); |
---|
| 82 | |
---|
| 83 | // create foot |
---|
| 84 | var objCaption = document.createElement("div"); |
---|
| 85 | objCaption.setAttribute('id','lightboxFoot'); |
---|
[493] | 86 | |
---|
| 87 | var close_button = '<input type=button value="'+get_lang('close')+'" onClick='+close_action+'>'; |
---|
[317] | 88 | if (type == 'create') |
---|
[493] | 89 | var create_save_button = '<input type=button value="'+get_lang('create')+'" onClick='+create_action+'>'; |
---|
[317] | 90 | else if(type == 'save') |
---|
[493] | 91 | var create_save_button = '<input type=button value="'+get_lang('save')+'" onClick='+save_action+'>'; |
---|
[317] | 92 | objCaption.innerHTML = '<table width=100% cellspacing="0" cellpadding="0"><tr><td align=left>'+close_button+'</td><td align=right>'+create_save_button+'</td></tr></table>' |
---|
| 93 | |
---|
| 94 | objLightbox.appendChild(objCaption); |
---|
| 95 | |
---|
| 96 | if (onload_action) |
---|
| 97 | { |
---|
| 98 | eval(onload_action); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | //Show the modal. |
---|
| 102 | objOverlay.style.display = 'block'; |
---|
| 103 | objLightbox.style.display = ''; |
---|
[6953] | 104 | |
---|
| 105 | //SETA REGRAS DOS CHECKBOX's |
---|
| 106 | |
---|
| 107 | var checkboxes = $(objLightbox).find("input:checkbox"); |
---|
| 108 | checkboxes.filter(".shared-required").change(function(e){ |
---|
| 109 | if(!$("#ea_select_owners option:selected").length){ |
---|
| 110 | return; |
---|
| 111 | } |
---|
| 112 | var check = $(this).attr("checked") == undefined ? false : true; |
---|
| 113 | if(check){ |
---|
| 114 | checkboxes.removeAttr("disabled"); |
---|
| 115 | }else{ |
---|
| 116 | checkboxes.not(".shared-required").attr("disabled", "disabled"); |
---|
| 117 | checkboxes.removeAttr("checked"); |
---|
| 118 | } |
---|
| 119 | }); |
---|
| 120 | |
---|
| 121 | |
---|
[317] | 122 | } |
---|
| 123 | |
---|
| 124 | function close_lightbox() |
---|
| 125 | { |
---|
| 126 | var objBody = document.getElementsByTagName("body").item(0); |
---|
| 127 | var lightbox = document.getElementById('overlay'); |
---|
| 128 | lightbox_div = document.getElementById('lightbox'); |
---|
| 129 | objBody.removeChild(lightbox); |
---|
| 130 | objBody.removeChild(lightbox_div); |
---|
| 131 | return; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | function getPageSize(){ |
---|
| 135 | |
---|
| 136 | var xScroll, yScroll; |
---|
| 137 | |
---|
| 138 | if (window.innerHeight && window.scrollMaxY) { |
---|
| 139 | xScroll = document.body.scrollWidth; |
---|
| 140 | yScroll = window.innerHeight + window.scrollMaxY; |
---|
| 141 | } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac |
---|
| 142 | xScroll = document.body.scrollWidth; |
---|
| 143 | yScroll = document.body.scrollHeight; |
---|
| 144 | } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari |
---|
| 145 | xScroll = document.body.offsetWidth; |
---|
| 146 | yScroll = document.body.offsetHeight; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | var windowWidth, windowHeight; |
---|
| 150 | if (self.innerHeight) { // all except Explorer |
---|
| 151 | windowWidth = self.innerWidth; |
---|
| 152 | windowHeight = self.innerHeight; |
---|
| 153 | } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode |
---|
| 154 | windowWidth = document.documentElement.clientWidth; |
---|
| 155 | windowHeight = document.documentElement.clientHeight; |
---|
| 156 | } else if (document.body) { // other Explorers |
---|
| 157 | windowWidth = document.body.clientWidth; |
---|
| 158 | windowHeight = document.body.clientHeight; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // for small pages with total height less then height of the viewport |
---|
| 162 | if(yScroll < windowHeight){ |
---|
| 163 | pageHeight = windowHeight; |
---|
| 164 | } else { |
---|
| 165 | pageHeight = yScroll; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // for small pages with total width less then width of the viewport |
---|
| 169 | if(xScroll < windowWidth){ |
---|
| 170 | pageWidth = windowWidth; |
---|
| 171 | } else { |
---|
| 172 | pageWidth = xScroll; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) |
---|
| 176 | return arrayPageSize; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | function getPageScroll(){ |
---|
| 180 | |
---|
| 181 | var yScroll; |
---|
| 182 | |
---|
| 183 | if (self.pageYOffset) { |
---|
| 184 | yScroll = self.pageYOffset; |
---|
| 185 | } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict |
---|
| 186 | yScroll = document.documentElement.scrollTop; |
---|
| 187 | } else if (document.body) {// all other Explorers |
---|
| 188 | yScroll = document.body.scrollTop; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | arrayPageScroll = new Array('',yScroll) |
---|
| 192 | return arrayPageScroll; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | function Element(id) |
---|
| 196 | { |
---|
| 197 | return document.getElementById(id); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | function add_css(){ |
---|
| 201 | var headID = document.getElementsByTagName("head")[0]; |
---|
| 202 | var cssNode = document.createElement('link'); |
---|
| 203 | cssNode.type = 'text/css'; |
---|
| 204 | cssNode.rel = 'stylesheet'; |
---|
| 205 | if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) |
---|
| 206 | cssNode.href = "./expressoAdmin1_2/js/modal/css/modal_ie.css"; |
---|
| 207 | else |
---|
| 208 | cssNode.href = "./expressoAdmin1_2/js/modal/css/modal_fx.css"; |
---|
| 209 | |
---|
| 210 | cssNode.media = 'screen'; |
---|
| 211 | headID.appendChild(cssNode); |
---|
| 212 | return; |
---|
| 213 | } |
---|
[414] | 214 | /* |
---|
[317] | 215 | function load_lang(){ |
---|
| 216 | cExecute ('$this/js/modal/inc/load_lang', handler_load_lang); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | var global_langs = new Array(); |
---|
| 220 | function handler_load_lang(data) |
---|
| 221 | { |
---|
| 222 | global_langs = eval(data); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | function get_lang(key_raw) |
---|
| 226 | { |
---|
| 227 | key = key_raw.replace(/ /g,"_"); |
---|
| 228 | |
---|
| 229 | try{ |
---|
| 230 | lang = eval("global_langs."+key.toLowerCase()); |
---|
| 231 | return lang; |
---|
| 232 | } |
---|
| 233 | catch(e){ |
---|
| 234 | return key_raw + '*'; |
---|
| 235 | } |
---|
[414] | 236 | }*/ |
---|
[317] | 237 | |
---|
| 238 | function make_msg(msg, type) |
---|
| 239 | { |
---|
| 240 | var html_msg = |
---|
| 241 | '<table cellspacing="0" cellpadding="0" border="0"><tbody>'+ |
---|
| 242 | '<tr><td class="zIVQRb_'+type+'"/><td class="Ptde9b_'+type+'"/><td class="Qrjz3e_'+type+'"/></tr>'+ |
---|
| 243 | '<tr><td class="Ptde9b_'+type+'"/><td class="m14Grb_'+type+'">' + msg + '</td><td class="Ptde9b_'+type+'"/></tr>' + |
---|
| 244 | '<tr><td class="Gbtri_'+type+'"/><td class="Ptde9b_'+type+'"/><td class="gmNpMd_'+type+'"/></tr></tbody></table>'; |
---|
| 245 | return html_msg; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | function write_msg(msg, type) |
---|
| 249 | { |
---|
| 250 | try |
---|
| 251 | { |
---|
| 252 | clearTimeout(setTimeout_write_msg); |
---|
| 253 | } |
---|
| 254 | catch(e){} |
---|
| 255 | |
---|
| 256 | var objLightbox = Element("lightbox"); |
---|
| 257 | if (objLightbox != null) |
---|
| 258 | { |
---|
| 259 | var old_divStatusBar = Element("lightboxWarning"); |
---|
| 260 | var bgColor = "#EEEEEE"; |
---|
| 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | var old_divStatusBar = Element("divStatusBar"); |
---|
| 265 | var bgColor = "#f7f8fa"; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | var msg_div = Element('em_div_write_msg'); |
---|
| 269 | if(!msg_div) { |
---|
| 270 | msg_div = document.createElement('DIV'); |
---|
| 271 | msg_div.id = 'em_div_write_msg'; |
---|
| 272 | //msg_div.style.height = '2px'; |
---|
| 273 | msg_div.style.background = bgColor; |
---|
| 274 | msg_div.style.display = 'none'; |
---|
| 275 | msg_div.align = "center"; |
---|
| 276 | msg_div.valign = "middle"; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | msg_div.innerHTML = make_msg(msg, type); |
---|
| 280 | |
---|
| 281 | clean_msg(); |
---|
| 282 | old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar); |
---|
| 283 | |
---|
| 284 | old_divStatusBar.style.display = 'none'; |
---|
| 285 | msg_div.style.display = ''; |
---|
| 286 | |
---|
| 287 | setTimeout_write_msg = setTimeout("clean_msg();", 4000); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | function clean_msg() |
---|
| 291 | { |
---|
| 292 | var msg_div = Element('em_div_write_msg'); |
---|
| 293 | if ( (msg_div) && (msg_div.style.display != 'none') ) |
---|
| 294 | { |
---|
| 295 | // Msg esta em outra tela. Precisa apaga-la. |
---|
| 296 | /* |
---|
| 297 | if ( (Element("lightbox") != null) && (msg_div.nextSibling.id == 'lightboxWarning') ) {} |
---|
| 298 | else if ( (Element("lightbox") == null) && (msg_div.nextSibling.id == 'divStatusBar') ) {} |
---|
| 299 | else |
---|
| 300 | {*/ |
---|
| 301 | msg_div.style.display = 'none'; |
---|
| 302 | msg_div.nextSibling.style.display = ''; |
---|
| 303 | // } |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | if (document.all) |
---|
| 308 | { |
---|
| 309 | navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false; |
---|
| 310 | is_ie = true; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | add_css(); |
---|
[414] | 314 | //load_lang(); |
---|