| 1 | /** |
---|
| 2 | * @AUTHOR: Alexandre Correia - alexandrecorreia [.at.] celepar [.dot.] pr [.dot.] gov [.dot.] br |
---|
| 3 | * @AUTHOR: Rodrigo Souza - rodrigosouzadossantos [.at.] gmail [.dot.] com |
---|
| 4 | * @COPYLEFT: GPL - http://www.gnu.org/copyleft/gpl.html |
---|
| 5 | * @DATE: 07/11/2007 |
---|
| 6 | * @LAST CHANGE: |
---|
| 7 | * @BRIEF: |
---|
| 8 | **/ |
---|
| 9 | |
---|
| 10 | function build_win() |
---|
| 11 | { |
---|
| 12 | this.window = []; |
---|
| 13 | this.position = {"x":100, "y":10}; |
---|
| 14 | this.focus = 100; |
---|
| 15 | this.xtools = new XTools(); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | build_win.prototype = { |
---|
| 19 | |
---|
| 20 | "elementB" : function(pId) |
---|
| 21 | { |
---|
| 22 | return document.getElementById(pId + '_window_body'); |
---|
| 23 | }, |
---|
| 24 | |
---|
| 25 | "elementC" : function(pId) |
---|
| 26 | { |
---|
| 27 | return document.getElementById(pId + '_window_body_content'); |
---|
| 28 | }, |
---|
| 29 | |
---|
| 30 | "elementM" : function(pId) |
---|
| 31 | { |
---|
| 32 | return document.getElementById(pId + '_window_master'); |
---|
| 33 | }, |
---|
| 34 | |
---|
| 35 | "load" : function(pId, pParentId, pXml, pXsl, pWidth, pButMin, pButMax, pButClose) |
---|
| 36 | { |
---|
| 37 | try{ |
---|
| 38 | if( document.getElementById(pId + '_window_master') == null) |
---|
| 39 | { |
---|
| 40 | pXml = '<window>' + pXml ; |
---|
| 41 | pXml += '<name>' + pId + '</name>'; |
---|
| 42 | pXml += (pWidth) ? '<width>' + pWidth + 'px</width>' : '<width>200px</width>' ; |
---|
| 43 | pXml += (pButMin) ? '<pButMin>block</pButMin>' : '<pButMin>none</pButMin>'; |
---|
| 44 | pXml += (pButMax) ? '<pButMax>block</pButMax>' : '<pButMax>none</pButMax>'; |
---|
| 45 | pXml += (pButClose) ? '<pButClose>block</pButClose>' : '<pButClose>none</pButClose>'; |
---|
| 46 | pXml += '</window>'; |
---|
| 47 | |
---|
| 48 | var div = document.createElement("div"); |
---|
| 49 | div.innerHTML = this.xtools.parse(pXml,pXsl); |
---|
| 50 | document.getElementById(pParentId).appendChild(div); |
---|
| 51 | |
---|
| 52 | this.window_position(pId, this.elementM(pId)); |
---|
| 53 | this.window_state(pId, 'nm'); |
---|
| 54 | this.window_focus(this.elementM(pId)); |
---|
| 55 | } |
---|
| 56 | else |
---|
| 57 | { |
---|
| 58 | this.window_visible(pId); |
---|
| 59 | this.window_state(pId, 'nm'); |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | catch(e) |
---|
| 63 | { |
---|
| 64 | alert("Error : \n\n" + e + "\n\n" + e.description); |
---|
| 65 | } |
---|
| 66 | }, |
---|
| 67 | |
---|
| 68 | "window_close" : function(pId) |
---|
| 69 | { |
---|
| 70 | this.window_state(pId, 'cl'); |
---|
| 71 | this.elementM(pId).parentNode.removeChild(this.elementM(pId)); |
---|
| 72 | }, |
---|
| 73 | |
---|
| 74 | "window_focus" : function(pElement) |
---|
| 75 | { |
---|
| 76 | pElement.style.zIndex = ++this.focus; |
---|
| 77 | }, |
---|
| 78 | |
---|
| 79 | "window_maximize" : function(pId) |
---|
| 80 | { |
---|
| 81 | this.window_state(pId, 'max'); |
---|
| 82 | |
---|
| 83 | // _button_maximize |
---|
| 84 | var button_maximize = document.getElementById(pId + '_button_maximize'); |
---|
| 85 | button_maximize.onclick = function(){im_window.window_normal(button_maximize, pId, 'window_maximize');}; |
---|
| 86 | |
---|
| 87 | // _window_master |
---|
| 88 | this.elementM(pId).style.top = "0px"; |
---|
| 89 | this.elementM(pId).style.left = "0px"; |
---|
| 90 | this.elementM(pId).style.width = window.screen.availWidth - 24; |
---|
| 91 | this.elementM(pId).style.height = window.screen.availHeight - 60; |
---|
| 92 | |
---|
| 93 | // _window_body |
---|
| 94 | this.elementB(pId).style.width = 'auto'; |
---|
| 95 | this.elementB(pId).style.height = '100%'; |
---|
| 96 | |
---|
| 97 | // _window_body_content |
---|
| 98 | this.elementC(pId).style.height = '100%'; |
---|
| 99 | }, |
---|
| 100 | |
---|
| 101 | "window_minimize" : function(pId) |
---|
| 102 | { |
---|
| 103 | this.window_state(pId, 'min'); |
---|
| 104 | |
---|
| 105 | // _window_master |
---|
| 106 | this.elementM(pId).style.display = 'none'; |
---|
| 107 | }, |
---|
| 108 | |
---|
| 109 | "window_normal" : function(pButton, pId, pFunction) |
---|
| 110 | { |
---|
| 111 | this.elementM(pId).style.top = this.window[pId].y; |
---|
| 112 | this.elementM(pId).style.left = this.window[pId].x; |
---|
| 113 | this.elementM(pId).style.width = this.window[pId].w; |
---|
| 114 | this.elementM(pId).style.height = 'auto'; |
---|
| 115 | pButton.onclick = function(){eval('im_window.' + pFunction + '("' + pId + '")');}; |
---|
| 116 | this.window_state(pId, 'max'); |
---|
| 117 | }, |
---|
| 118 | |
---|
| 119 | "window_object" : function( pId, pState) |
---|
| 120 | { |
---|
| 121 | this.window[pId] = { |
---|
| 122 | "x": this.elementM(pId).offsetLeft, |
---|
| 123 | "y": this.elementM(pId).offsetTop, |
---|
| 124 | "w": this.elementM(pId).clientWidth, |
---|
| 125 | "h": this.elementM(pId).clientHeight, |
---|
| 126 | "s": pState |
---|
| 127 | }; |
---|
| 128 | }, |
---|
| 129 | |
---|
| 130 | "window_position" : function( pId, pElement ) |
---|
| 131 | { |
---|
| 132 | pElement.style.position = 'absolute'; |
---|
| 133 | |
---|
| 134 | if ( this.window[pId] ) |
---|
| 135 | { |
---|
| 136 | pElement.style.left = this.window[pId].x + "px"; |
---|
| 137 | pElement.style.top = this.window[pId].y + "px"; |
---|
| 138 | } |
---|
| 139 | else |
---|
| 140 | { |
---|
| 141 | pElement.style.left = parseInt( this.position.x += 10 ) + "px"; |
---|
| 142 | pElement.style.top = parseInt( this.position.y += 10 ) + "px"; |
---|
| 143 | } |
---|
| 144 | }, |
---|
| 145 | |
---|
| 146 | "window_state" : function(pId, pState) |
---|
| 147 | { |
---|
| 148 | |
---|
| 149 | if(this.window[pId]) |
---|
| 150 | { |
---|
| 151 | if(pState == 'max') |
---|
| 152 | { |
---|
| 153 | if(this.window[pId].s == 'max') |
---|
| 154 | this.window_object( pId, pState); |
---|
| 155 | else |
---|
| 156 | this.window_object( pId, pState); |
---|
| 157 | } |
---|
| 158 | else if( pState == 'cl') |
---|
| 159 | this.window_object( pId, pState); |
---|
| 160 | } |
---|
| 161 | else |
---|
| 162 | this.window_object( pId, pState); |
---|
| 163 | }, |
---|
| 164 | |
---|
| 165 | "window_visible" : function(pId) |
---|
| 166 | { |
---|
| 167 | if ( this.elementM(pId).style.display == 'none' ) |
---|
| 168 | this.elementM(pId).style.display = 'block'; |
---|
| 169 | } |
---|
| 170 | }; |
---|
| 171 | |
---|
| 172 | var im_window = new build_win(); |
---|