00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 if (typeof Debug == 'undefined')
00016 console.log('ERROR: Debug is undefined! Must include Debug.js before Desktop.js');
00017
00018 if (typeof Desktop == 'undefined')
00019 console.log('ERROR: Desktop is undefined! Must include Desktop.js before DesktopWindow.js');
00020 else {
00021
00022
00025
00028 Desktop.createWindow = function(id,z,name,subname,url,w,h,x,y) {
00029
00030 if(false === (this instanceof Desktop.createWindow)) {
00031
00032
00033 return new Desktop.createWindow(id,z,name,subname,url,w,h,x,y);
00034 }
00035
00036
00037
00038
00039
00040
00041
00042
00043 var _defaultWindowMinWidth = 100;
00044 var _defaultWindowMinHeight = 100;
00045
00046 var _defaultHeaderHeight = 30;
00047 var _defaultHeaderLeftMargin = 10;
00048 var _defaultHeaderFontSize = 16;
00049 var _defaultButtonSize = 20;
00050 var _defaultButtonLeftMargin = 2;
00051 var _defaultButtonTopMargin = 1;
00052
00053 var _defaultFrameBorder = 6;
00054
00055 var _name;
00056 var _subname;
00057 var _url = url;
00058 var _id = id;
00059
00060 var _winhdr,_winfrm,_winfrmHolder;
00061
00062 var _w,_h,_x,_y;
00063 var _isMaximized = false;
00064 var _isMinimized = false;
00065 var _z = z;
00066
00067
00068
00069
00070 this.windiv;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 var _refreshHeader = function() {
00081 var hdrW = _w-2*_defaultHeaderLeftMargin-4*(_defaultButtonSize+_defaultButtonLeftMargin);
00082 _winhdr.style.width = hdrW +"px";
00083 _winhdr.innerHTML = _name + (_subname==""?"":" - ") + _subname;
00084 while(_winhdr.scrollWidth > hdrW && _winhdr.innerHTML.length > 4)
00085 _winhdr.innerHTML = _winhdr.innerHTML.substr(0,_winhdr.innerHTML.length-4)+"...";
00086 }
00087
00088 var _handleWindowContentLoading = function() {
00089
00090 if(_winfrmHolder.childNodes.length > 1)
00091 _winfrmHolder.removeChild(
00092 document.getElementById("DesktopWindowFrameLoadingDiv-"+_id));
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 this.getWindowName = function() { return _name; }
00106 this.getWindowSubName = function() { return _subname; }
00107 this.getWindowUrl = function() { return _url; }
00108 this.getWindowId = function() { return _id; }
00109 this.getWindowX = function() { return _x; }
00110 this.getWindowY = function() { return _y; }
00111 this.getWindowZ = function() { return parseInt(this.windiv.style.zIndex);}
00112 this.getWindowWidth = function() { return _w; }
00113 this.getWindowHeight = function() { return _h; }
00114 this.getWindowHeaderHeight = function() { return _defaultHeaderHeight; }
00115 this.isMaximized = function() {return _isMaximized && !_isMinimized;}
00116 this.isMinimized = function() {return _isMinimized;}
00117
00118 this.setWindowZ = function(z) { _z = z; this.windiv.style.zIndex = _z; }
00119
00120 this.showFrame = function() { _winfrm.style.display = "inline"; }
00121 this.hideFrame = function() { _winfrm.style.display = "none"; }
00122
00123
00124
00125 this.setWindowNameAndSubName = function(name,subname) {
00126 _name = name; _subname = subname;
00127 _refreshHeader();
00128 Debug.log("Desktop Window name=" + name + " and subname=" + subname,Debug.LOW_PRIORITY);
00129 }
00130
00131
00132
00133 this.setWindowSizeAndPosition = function(x,y,w,h) {
00134 x = parseInt(x);
00135 y = parseInt(y);
00136 w = parseInt(w);
00137 h = parseInt(h);
00138
00139
00140 _w = _isMaximized?Desktop.desktop.getDesktopContentWidth():(w < _defaultWindowMinWidth?_defaultWindowMinWidth:w);
00141 _h = _isMaximized?Desktop.desktop.getDesktopContentHeight():(h < _defaultWindowMinHeight?_defaultWindowMinHeight:h);
00142 _x = _isMaximized?Desktop.desktop.getDesktopContentX():x;
00143 _y = _isMaximized?Desktop.desktop.getDesktopContentY():y;
00144
00145
00146 if(_x + _w > Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth())
00147 _x = Desktop.desktop.getDesktopContentX() + Desktop.desktop.getDesktopContentWidth() - _w;
00148 if(_y + _h > Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight())
00149 _y = Desktop.desktop.getDesktopContentY() + Desktop.desktop.getDesktopContentHeight() - _h;
00150
00151 this.windiv.style.width = _w +"px";
00152 this.windiv.style.height = _h+"px";
00153 this.windiv.style.left = _x+"px";
00154 this.windiv.style.top = _y+"px";
00155
00156 _refreshHeader();
00157
00158 _winfrm.style.width = (_w-2*_defaultFrameBorder-2)+"px";
00159 _winfrm.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+"px";
00160 _winfrmHolder.style.width = (_w-2*_defaultFrameBorder-2)+"px";
00161 _winfrmHolder.style.height = (_h-_defaultHeaderHeight-_defaultFrameBorder-2)+"px";
00162
00163
00164
00165
00166 if(_isMaximized){
00167 _winfrm.style.position = "absolute";
00168 _winfrm.style.zIndex = _z + 1;
00169 _winfrm.style.width = _w + "px";
00170 _winfrm.style.height = _h + "px";
00171 _winfrm.style.left ="-1px";
00172 _winfrm.style.top = "-1px";
00173 _winfrmHolder.style.position = "absolute";
00174 _winfrmHolder.style.width = (_w)+"px";
00175 _winfrmHolder.style.height = (_h)+"px";
00176 _winfrmHolder.style.left =(-_defaultFrameBorder-2) + "px";
00177 _winfrmHolder.style.top = "-1px";
00178
00179
00180 _w = w < _defaultWindowMinWidth?_defaultWindowMinWidth:w;
00181 _h = h < _defaultWindowMinHeight?_defaultWindowMinHeight:h;
00182 _x = x;
00183 _y = y;
00184
00185
00186 var hdrs = this.windiv.getElementsByClassName("DesktopWindowButton");
00187 for(var h=0;hdrs && h<hdrs.length;++h)
00188 hdrs[h].style.display = "none";
00189 hdrs = this.windiv.getElementsByClassName("DesktopWindowHeader");
00190 for(var h=0;hdrs && h<hdrs.length;++h)
00191 hdrs[h].style.display = "none";
00192 }
00193 else {
00194 _winfrm.style.zIndex = _z;
00195 _winfrm.style.position = "static";
00196 _winfrmHolder.style.position = "static";
00197
00198
00199 var hdrs = this.windiv.getElementsByClassName("DesktopWindowButton");
00200 for(var h=0;hdrs && h<hdrs.length;++h)
00201 hdrs[h].style.display = "block";
00202 hdrs = this.windiv.getElementsByClassName("DesktopWindowHeader");
00203 for(var h=0;hdrs && h<hdrs.length;++h)
00204 hdrs[h].style.display = "block";
00205 }
00206
00207 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
00208 }
00209
00210
00211 this.moveWindowByOffset = function(dx,dy) {
00212 _x += dx;
00213 _y += dy;
00214
00215 if(_y < Desktop.desktop.getDesktopContentY()) _y = Desktop.desktop.getDesktopContentY();
00216 this.windiv.style.left = _x+"px";
00217 this.windiv.style.top = _y+"px";
00218
00219
00220
00221
00222
00223 Desktop.desktop.login.resetCurrentLayoutUpdateTimer();
00224 }
00225
00226
00227
00228 this.resizeAndPositionWindow = function(x,y,w,h) {
00229 if((w <= _defaultWindowMinWidth && x > _x) ||
00230 (h <= _defaultWindowMinHeight && y > _y)) return;
00231 if(x < Desktop.desktop.getDesktopContentX()) x = Desktop.desktop.getDesktopContentX();
00232 if(y < Desktop.desktop.getDesktopContentY()) y = Desktop.desktop.getDesktopContentY();
00233 this.setWindowSizeAndPosition(x,y,w,h);
00234 }
00235
00236
00237
00238 this.maximize = function() {
00239
00240 if(_isMinimized) this.unminimize();
00241 _isMaximized = true;
00242
00243 this.windiv.style.display = "inline";
00244 this.setWindowSizeAndPosition(_x+10,_y,_w,_h);
00245 window.parent.document.title= _name;
00246 console.log(document.title, _name, "Maximize()");
00247
00248 }
00249
00250 this.unmaximize = function() {
00251
00252 _isMaximized = false;
00253
00254 this.windiv.style.display = "inline";
00255 this.setWindowSizeAndPosition(_x,_y,_w,_h);
00256 window.parent.document.title = Desktop.isWizardMode()?"ots wiz":"ots";
00257 }
00258
00259
00260
00261 this.minimize = function() {
00262
00263 if(_isMaximized)
00264 window.parent.document.title = _name;
00265 else
00266 window.parent.document.title = Desktop.isWizardMode()?"ots wiz":"ots";
00267
00268 _isMinimized = true;
00269 this.windiv.style.display = "none";
00270 Debug.log("-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
00271 }
00272
00273 this.unminimize = function() {
00274
00275 if(_isMaximized)
00276 window.parent.document.title = _name;
00277 else
00278 window.parent.document.title = Desktop.isWizardMode()?"ots wiz":"ots";
00279
00280 _isMinimized = false;
00281 this.windiv.style.display = "inline";
00282 Debug.log("-----------Chat this.windiv.style.display now is " + this.windiv.style.display);
00283 }
00284
00285
00286
00287
00288
00289
00290 this.windiv = document.createElement("div");
00291 this.windiv.setAttribute("class", "DesktopWindow");
00292 this.windiv.setAttribute("id", "DesktopWindow-" + _id);
00293 this.windiv.style.backgroundColor = Desktop.desktop.defaultWindowFrameColor;
00294 this.windiv.style.position = "absolute";
00295 this.windiv.style.zIndex = _z;
00296
00297
00298 _winhdr = document.createElement("div");
00299 _winhdr.setAttribute("class", "DesktopWindowHeader");
00300 _winhdr.setAttribute("id", "DesktopWindowHeader-" + _id);
00301 _winhdr.style.height = _defaultHeaderHeight+"px";
00302 _winhdr.style.marginLeft = _defaultHeaderLeftMargin+"px";
00303 _winhdr.style.fontSize = _defaultHeaderFontSize+"px";
00304 this.setWindowNameAndSubName(name, subname);
00305 this.windiv.appendChild(_winhdr);
00306
00307
00308 var tmpBtn = document.createElement("div");
00309 tmpBtn.setAttribute("class", "DesktopWindowButton");
00310 tmpBtn.setAttribute("id", "DesktopWindowButtonRefresh-" + _id);
00311 tmpBtn.style.width = (_defaultButtonSize) +"px";
00312 tmpBtn.style.height = (_defaultButtonSize) +"px";
00313 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +"px";
00314 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +"px";
00315 tmpBtn.onmouseup = Desktop.handleWindowRefresh;
00316 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
00317 var tmpEl = document.createElement("div");
00318 tmpEl.setAttribute("class", "DesktopWindowButtonGraphicRefresh");
00319 tmpEl.innerHTML = "↻";
00320 tmpBtn.appendChild(tmpEl);
00321 this.windiv.appendChild(tmpBtn);
00322
00323 var tmpBtn = document.createElement("div");
00324 tmpBtn.setAttribute("class", "DesktopWindowButton");
00325 tmpBtn.setAttribute("id", "DesktopWindowButtonMin-" + _id);
00326 tmpBtn.style.width = (_defaultButtonSize) +"px";
00327 tmpBtn.style.height = (_defaultButtonSize) +"px";
00328 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +"px";
00329 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +"px";
00330 tmpBtn.onmouseup = Desktop.handleWindowMinimize;
00331 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
00332 var tmpEl = document.createElement("div");
00333 tmpEl.setAttribute("class", "DesktopWindowButtonGraphicMin");
00334 tmpBtn.appendChild(tmpEl);
00335 this.windiv.appendChild(tmpBtn);
00336
00337 tmpBtn = document.createElement("div");
00338 tmpBtn.setAttribute("class", "DesktopWindowButton");
00339 tmpBtn.setAttribute("id", "DesktopWindowButtonMax-" + _id);
00340 tmpBtn.style.width = (_defaultButtonSize) +"px";
00341 tmpBtn.style.height = (_defaultButtonSize) +"px";
00342 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +"px";
00343 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +"px";
00344 tmpBtn.onmouseup = Desktop.handleWindowMaximize;
00345 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
00346 var tmpEl = document.createElement("div");
00347 tmpEl.setAttribute("class", "DesktopWindowButtonGraphicMax");
00348 tmpBtn.appendChild(tmpEl);
00349 this.windiv.appendChild(tmpBtn);
00350
00351 tmpBtn = document.createElement("div");
00352 tmpBtn.setAttribute("class", "DesktopWindowButton");
00353 tmpBtn.setAttribute("id", "DesktopWindowButtonClose-" + _id);
00354 tmpBtn.style.width = (_defaultButtonSize) +"px";
00355 tmpBtn.style.height = (_defaultButtonSize) +"px";
00356 tmpBtn.style.marginLeft = (_defaultButtonLeftMargin) +"px";
00357 tmpBtn.style.marginTop = (_defaultButtonTopMargin) +"px";
00358 tmpBtn.onmouseup = Desktop.handleWindowClose;
00359 tmpBtn.onmousedown = Desktop.handleWindowButtonDown;
00360 var tmpEl = document.createElement("div");
00361 tmpEl.setAttribute("class", "DesktopWindowButtonGraphicClose");
00362 tmpEl.innerHTML = "x";
00363 tmpBtn.appendChild(tmpEl);
00364 this.windiv.appendChild(tmpBtn);
00365
00366
00367 _winfrmHolder = document.createElement("div");
00368 _winfrmHolder.setAttribute("class", "DesktopWindowFrameHolder");
00369 _winfrmHolder.setAttribute("id", "DesktopWindowFrameHolder-" + _id);
00370 _winfrmHolder.style.marginLeft = _defaultFrameBorder+"px";
00371 _winfrmHolder.innerHTML =
00372 "<div class='DesktopWindowHeader' id='DesktopWindowFrameLoadingDiv-"+
00373 _id + "' style='width:100px;height:50px;position:relative;top:50%;left:50%;margin-top:-25px;margin-left:-50px;text-align:center;margin-bottom:-50px;'>" +
00374 "Loading..." + "</div>";
00375
00376
00377 _winfrm = document.createElement("iframe");
00378 _winfrm.setAttribute("class", "DesktopWindowFrame");
00379 _winfrm.setAttribute("id", "DesktopWindowFrame-" + _id);
00380 _winfrm.setAttribute("name", "DesktopWindowFrame-" + _id);
00381 _winfrm.onload = _handleWindowContentLoading;
00382 _winfrm.setAttribute("src", _url);
00383 _winfrmHolder.appendChild(_winfrm);
00384 this.windiv.appendChild(_winfrmHolder);
00385
00386 this.setWindowSizeAndPosition(x,y,w,h);
00387
00388
00389 this.windiv.onmousedown = Desktop.handleWindowMouseDown;
00390 this.windiv.onmouseup = Desktop.handleWindowMouseUp;
00391 this.windiv.onmousemove = Desktop.handleWindowMouseMove;
00392 this.windiv.ondblclick = Desktop.handleWindowMaximize;
00393
00394
00395 this.windiv.addEventListener('touchstart',Desktop.handleTouchStart);
00396 this.windiv.addEventListener('touchend',Desktop.handleTouchEnd);
00397 this.windiv.addEventListener('touchmove',Desktop.handleTouchMove);
00398
00399 Debug.log("Desktop Window Created",Debug.LOW_PRIORITY);
00400
00401 }
00402 }