00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 var Desktop = Desktop || {};
00016
00017 if (typeof Debug == 'undefined')
00018 console.log('ERROR: Debug is undefined! Must include Debug.js before Desktop.js');
00019 else if (typeof Globals == 'undefined')
00020 console.log('ERROR: Globals is undefined! Must include Globals.js before Desktop.js');
00021 else
00022 Desktop.desktop;
00023
00024 Desktop.init = function(security) {
00025
00026 Desktop.desktop = Desktop.createDesktop(security);
00027 if(Desktop.desktop)
00028 Debug.log("Desktop.desktop Initalized Successfully",Debug.LOW_PRIORITY);
00029 }
00030
00031 Desktop.SECURITY_TYPE_NONE = "NoSecurity";
00032 Desktop.SECURITY_TYPE_DIGEST_ACCESS = "DigestAccessAuthentication";
00033
00036
00039 Desktop.createDesktop = function(security) {
00040
00041 if (typeof Debug == 'undefined') return 0;
00042
00043 if(false === (this instanceof Desktop.createDesktop)) {
00044
00045
00046 return new Desktop.createDesktop(security);
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 var _defaultWindowMinZindex = 10;
00132 var _defaultWindowMaxZindex = 10000;
00133 var _defaultDashboardZindex = 11000;
00134 var _defaultWidth = 620;
00135 var _defaultHeight = 580;
00136 var _defaultLeft = 200;
00137 var _defaultTop = 70;
00138 var _defaultLeftOffset = 50;
00139 var _defaultTopOffset = 25;
00140 var _defaultOffsetTimes = 5;
00141 var _currentLeft = _defaultLeft;
00142 var _currentTop = _defaultTop;
00143
00144 var _windows = new Array();
00145 var _desktopElement;
00146 var _dashboard, _icons, _windowZmailbox, _mouseOverXmailbox, _mouseOverYmailbox;
00147 var _needToLoginMailbox, _updateTimeMailbox, _updateSettingsMailbox, _settingsLayoutMailbox, _openWindowMailbox, _blockSystemCheckMailbox;
00148 var _windowColorPostbox;
00149 var _MAILBOX_TIMER_PERIOD = 500;
00150 var _sysMsgId = 0;
00151 var _SYS_MSG_SOUND_PATH = "/WebPath/sounds/fx-System-Message.wav";
00152 var _sysMsgSound = new Audio(_SYS_MSG_SOUND_PATH);
00153
00154 var _winId = 1000;
00155
00156 var _login;
00157
00158
00159 var _sysMsgCounter = 0;
00160 var _SYS_MSG_MAX_COUNT = 10;
00161
00162 var _firstCheckOfMailboxes = true;
00163
00164
00165
00166
00167 this.dashboard;
00168 this.login;
00169 this.icons;
00170 this.checkMailboxTimer;
00171 this.serverConnected = true;
00172 this.security = security;
00173
00174 this.defaultWindowFrameColor = "rgba(196,229,255,.9)";
00175
00176
00177
00178
00179
00180 var _handleDesktopResize = function(event) {
00181 _desktopElement.style.height = (window.innerHeight-_desktopElement.offsetTop) + "px";
00182 _desktopElement.style.width = (window.innerWidth-_desktopElement.offsetLeft) + "px";
00183 if(!_dashboard) return;
00184 _dashboard.redrawDashboard();
00185 if(_login) _login.redrawLogin();
00186 if(_icons) _icons.redrawIcons();
00187
00188
00189 if(_windows.length && _windows[_windows.length-1].isMaximized()) {
00190 var w = _windows[_windows.length-1];
00191 w.setWindowSizeAndPosition(w.getWindowX(),w.getWindowY(),w.getWindowWidth(),w.getWindowHeight());
00192 }
00193
00194
00195
00196 }
00197
00198
00199
00200
00201 var _getWindowLayoutStr = function() {
00202 var dw = Desktop.desktop.getDesktopContentWidth()/10000.0;
00203 var dh = Desktop.desktop.getDesktopContentHeight()/10000.0;
00204 var dx = Desktop.desktop.getDesktopContentX();
00205 var dy = Desktop.desktop.getDesktopContentY();
00206
00207 var layout = "";
00208 for(var i=0;i<_windows.length;++i)
00209 {
00210 if(_windows[i].getWindowName() == "Settings") continue;
00211
00212 layout += (i?",":"") +
00213 encodeURIComponent(_windows[i].getWindowName())
00214 + "," + encodeURIComponent(_windows[i].getWindowSubName())
00215 + "," + encodeURIComponent(_windows[i].getWindowUrl())
00216 + "," + (((_windows[i].getWindowX()-dx)/dw)|0)
00217 + "," + (((_windows[i].getWindowY()-dy)/dh)|0)
00218 + "," + ((_windows[i].getWindowWidth()/dw)|0)
00219 + "," + ((_windows[i].getWindowHeight()/dh)|0)
00220 + "," + (_windows[i].isMinimized()?"0":(_windows[i].isMaximized()?"2":"1"));
00221
00222 }
00223
00224 return layout;
00225 }
00226
00227
00228 var _scrambleEggs = function(u) { return u; }
00229
00230 var _getForeWindow = function() { return _windows.length?_windows[_windows.length-1]:0; }
00231
00232 var _closeWindow = function(win) {
00233 Desktop.desktop.setForeWindow(win);
00234 win.windiv.parentNode.removeChild(win.windiv);
00235
00236
00237
00238 _windows.splice(_windows.length-1,1);
00239
00240
00241 _dashboard.updateWindows();
00242 }
00243
00244
00245
00246
00247
00248
00249 var _checkMailboxes = function(win)
00250 {
00251
00252
00253 if(_firstCheckOfMailboxes)
00254 {
00255 Debug.log("First check of mailboxes!");
00256
00257 Debug.log("Checking for any shortcut work from get parameters...",Debug.LOW_PRIORITY);
00258 _firstCheckOfMailboxes = false;
00259 Desktop.desktop.actOnParameterAction();
00260
00261 }
00262
00263
00264 if(_blockSystemCheckMailbox.innerHTML == "1")
00265 {
00266 Desktop.desktop.login.blackout(true);
00267 }
00268 else
00269 {
00270 Desktop.desktop.login.blackout(false);
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280 if(_openWindowMailbox.innerHTML != "")
00281 {
00282 Debug.log("_openWindowMailbox.textContent=" + _openWindowMailbox.textContent);
00283
00284
00285 var paramsStr = _openWindowMailbox.textContent;
00286 var params = [];
00287 var paramCnt = 5 ;
00288 var spliti, splitiOld = 0;
00289 for(var i=0;i<paramCnt;++i)
00290 {
00291 if(i == paramCnt-1)
00292 {
00293 params.push(paramsStr.substr(splitiOld));
00294 break;
00295 }
00296
00297 spliti = paramsStr.indexOf('&', splitiOld);
00298 params.push(paramsStr.substr(splitiOld,spliti-splitiOld))
00299 splitiOld = spliti+1;
00300 }
00301
00302 var varPair;
00303 var requestingWindowId = "", windowPath = "";
00304 var windowName, windowSubname, windowUnique;
00305 for(var i=0;i<params.length;++i)
00306 {
00307 spliti = params[i].indexOf('=');
00308 varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
00309 if(varPair[0] == "requestingWindowId")
00310 requestingWindowId = varPair[1];
00311 else if(varPair[0] == "windowPath")
00312 windowPath = varPair[1];
00313 else if(varPair[0] == "windowName")
00314 windowName = varPair[1];
00315 else if(varPair[0] == "windowSubname")
00316 windowSubname = varPair[1];
00317 else if(varPair[0] == "windowUnique")
00318 windowUnique = varPair[1];
00319 }
00320 if(requestingWindowId != "" && windowPath != "")
00321 {
00322
00323
00324 Debug.log("_openWindowMailbox.innerHTML=" + _openWindowMailbox.innerHTML);
00325 Debug.log("requestingWindowId=" + requestingWindowId);
00326 Debug.log("windowPath=" + windowPath);
00327 Debug.log("windowName=" + windowName);
00328 Debug.log("windowSubname=" + windowSubname);
00329 Debug.log("windowUnique=" + windowUnique);
00330
00331 var newWin;
00332
00333
00334
00335 if(windowSubname == "undefined" &&
00336 windowUnique == "undefined")
00337 {
00338 Debug.log("Opening desktop window... " + windowName);
00339
00340 var pathUniquePair = Desktop.desktop.icons.iconNameToPathMap[windowName];
00341 console.log("Desktop.desktop.icons.iconNameToPathMap",
00342 Desktop.desktop.icons.iconNameToPathMap);
00343
00344 if(pathUniquePair ===
00345 undefined)
00346 {
00347 Debug.log("An error occurred opening the window named '" +
00348 windowName + "' - it was not found in the Desktop icons. " +
00349 "Do you have permissions to access this window? Notify admins if the problem persists.",
00350 Debug.HIGH_PRIORITY);
00351
00352
00353 var str = "requestingWindowId=" + requestingWindowId;
00354 str += "&done=1";
00355 _openWindowMailbox.innerHTML = str;
00356
00357 return;
00358 }
00359
00360 var pathStr = pathUniquePair[0];
00361
00362 if(windowPath != "undefined")
00363 {
00364 Debug.log("Adding parameter path " + windowPath);
00365 if(pathStr.indexOf('&') > 0)
00366 pathStr += "&";
00367 else if(pathStr.length &&
00368 pathStr[pathStr.lengh-1] != '?')
00369 pathStr += '?';
00370 windowPath = pathStr + windowPath;
00371 }
00372 else
00373 windowPath = pathStr;
00374
00375 newWin = Desktop.desktop.addWindow(
00376 windowName,
00377 "",
00378 windowPath,
00379 eval(pathUniquePair[1]));
00380 }
00381 else
00382 {
00383 newWin = Desktop.desktop.addWindow(
00384 windowName,
00385 windowSubname,
00386 windowPath,
00387 eval(windowUnique));
00388 }
00389
00390
00391 setTimeout(function(){ Desktop.desktop.setForeWindow(newWin); }, 200);
00392
00393 var str = "requestingWindowId=" + requestingWindowId;
00394 str += "&done=1";
00395 _openWindowMailbox.innerHTML = str;
00396 }
00397 }
00398
00399
00400
00401
00402
00403 if(!Desktop.desktop.login || !Desktop.desktop.login.getCookieCode(true))
00404 {
00405 if(_needToLoginMailbox.innerHTML == "1")
00406 _needToLoginMailbox.innerHTML = "";
00407
00408 return;
00409 }
00410
00411
00412 if(_windowZmailbox.innerHTML > _defaultWindowMaxZindex)
00413 {
00414 Desktop.desktop.setForeWindow(0);
00415
00416 }
00417
00418
00419 if(_needToLoginMailbox.innerHTML == "1")
00420 {
00421 _needToLoginMailbox.innerHTML = "";
00422 if(!document.getElementById("Desktop-loginDiv") &&
00423 !Desktop.desktop.login.isBlackout())
00424 {
00425
00426 Debug.log("DesktopContent signaled new login needed!",Debug.HIGH_PRIORITY);
00427 Desktop.logout();
00428 }
00429 else
00430 Debug.log("Ignoring desktop content need for login signal due to blackout.");
00431 }
00432
00433
00434 if(parseInt(_updateTimeMailbox.innerHTML) > parseInt(Desktop.desktop.login.getCookieTime()))
00435 Desktop.desktop.login.updateCookieFromContent(parseInt(_updateTimeMailbox.innerHTML));
00436
00437
00438 if(_updateSettingsMailbox.innerHTML != "")
00439 {
00440
00441
00442
00443
00444 if(_updateSettingsMailbox.innerHTML == "LAYOUT")
00445 {
00446
00447 var layout = _getWindowLayoutStr();
00448 _settingsLayoutMailbox.innerHTML = layout;
00449 Debug.log("Desktop _updateSettingsMailbox " + layout,Debug.LOW_PRIORITY);
00450 }
00451 else
00452 {
00453
00454 var xml = _updateSettingsMailbox.innerHTML;
00455 var req = req || {};
00456 req.responseXML = ( new window.DOMParser() ).parseFromString(xml, "text/xml");
00457 _login.applyUserPreferences(req);
00458 }
00459
00460 _updateSettingsMailbox.innerHTML = "";
00461 }
00462
00463
00464 ++_sysMsgCounter;
00465 if(_sysMsgCounter == _SYS_MSG_MAX_COUNT)
00466 {
00467
00468 if(_blockSystemCheckMailbox.innerHTML == "1" ||
00469 Desktop.desktop.login.isBlackout())
00470 {
00471 Debug.log("System blackout (likely rebooting)...");
00472 _sysMsgCounter = 0;
00473 }
00474 else
00475 Desktop.XMLHttpRequest("Request?RequestType=getSystemMessages","",_handleSystemMessages);
00476 }
00477 }
00478
00479
00480 var _lastSystemMessage = "";
00481
00482
00483 var _handleSystemMessages = function(req) {
00484
00485
00486 _sysMsgCounter = 0;
00487
00488 if(!req) return;
00489
00490 var userLock;
00491 userLock = Desktop.getXMLValue(req,"username_with_lock");
00492 Desktop.desktop.dashboard.displayUserLock(userLock);
00493
00494 var tmp = Desktop.getXMLValue(req,"systemMessages");
00495 if(!tmp) return;
00496
00497
00498
00499
00500 var tmpi;
00501 if((tmpi = tmp.indexOf(_lastSystemMessage)) >= 0)
00502 {
00503 Debug.log("Desktop pretmp " + tmp);
00504 Debug.log("Desktop _lastSystemMessage " + _lastSystemMessage);
00505 Debug.log("Desktop tmp " + tmp.substr(tmpi+_lastSystemMessage.length+1));
00506 tmp = tmp.substr(tmpi+_lastSystemMessage.length+1);
00507 }
00508
00509
00510
00511
00512 var msgArr = tmp.split("|");
00513 Debug.log("Desktop msgArr.length " + msgArr.length);
00514
00515 if(msgArr.length < 2) return;
00516
00517 Debug.log("Desktop _handleSystemMessages ========================== " + Desktop.formatTime(msgArr[0]) +
00518 " - " + msgArr[1]
00519 ,Debug.LOW_PRIORITY);
00520
00521 ++_sysMsgId;
00522 var sysMsgEl = document.createElement("div");
00523 sysMsgEl.setAttribute("class", "Desktop-systemMessageBox");
00524 sysMsgEl.setAttribute("id", "Desktop-systemMessageBox-" + _sysMsgId);
00525 sysMsgEl.style.left = (50 + _sysMsgId % 5 * 10) + "px";
00526 sysMsgEl.style.top = (50 + _sysMsgId % 5 * 10) + "px";
00527 _desktopElement.appendChild(sysMsgEl);
00528
00529 var str = "";
00530
00531 for(var i=0;i<msgArr.length;i+=2)
00532 {
00533 str += "<div style='font-size:12px'>System Message Received at " + Desktop.formatTime(msgArr[i]) + "</div>";
00534 str += "<div>" + msgArr[i+1] + "</div><br>";
00535 _lastSystemMessage = msgArr[i] + "|" + msgArr[i+1];
00536 }
00537
00538
00539 str += "<div style='float:right; margin-left:30px'>";
00540 str += "<a href='Javascript:Desktop.closeSystemMessage(" + _sysMsgId + ");' " +
00541 "title='Click here to dismiss system message'>Dismiss</a></div>";
00542
00543 sysMsgEl.innerHTML = str;
00544
00545 if(sysMsgEl.clientHeight > 300)
00546 sysMsgEl.style.height = 300 + "px";
00547
00548
00549
00550
00551 }
00552
00553
00554
00555
00556 this.getDesktopWidth = function() { return _desktopElement.clientWidth;}
00557 this.getDesktopHeight = function() { return _desktopElement.clientHeight;}
00558 this.getDesktopX = function() { return _desktopElement.offsetLeft;}
00559 this.getDesktopY = function() { return _desktopElement.offsetTop;}
00560 this.getDesktopContentX = function() { return _desktopElement.offsetLeft+_dashboard.getDashboardWidth();}
00561 this.getDesktopContentY = function() { return _desktopElement.offsetTop+_dashboard.getDashboardHeight();}
00562 this.getDesktopContentWidth = function() { return _desktopElement.clientWidth-_dashboard.getDashboardWidth();}
00563 this.getDesktopContentHeight = function() { return _desktopElement.clientHeight-_dashboard.getDashboardHeight();}
00564 this.getNumberOfWindows = function() { return _windows.length;}
00565 this.getWindowNameByIndex = function(i) { return _windows[i].getWindowName();}
00566 this.getWindowSubNameByIndex = function(i) { return _windows[i].getWindowSubName();}
00567 this.getWindowByIndex = function(i) { return _windows[i];}
00568 this.getForeWindow = _getForeWindow;
00569 this.redrawDesktop = _handleDesktopResize;
00570 this.getLastFrameMouseX = function() { return parseInt(_mouseOverXmailbox.innerHTML);}
00571 this.getLastFrameMouseY = function() { return parseInt(_mouseOverYmailbox.innerHTML);}
00572 this.resetFrameMouse = function() { _mouseOverXmailbox.innerHTML = -1;_mouseOverYmailbox.innerHTML = -1;}
00573 this.getWindowLayoutStr = _getWindowLayoutStr;
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587 this.addWindow = function(name,subname,url,unique,extraStep) {
00588 Debug.log(name + " - " + subname + " - " + url + " - " + unique,Debug.LOW_PRIORITY);
00589
00590 if(unique) {
00591 Debug.log("Adding window uniquely",Debug.LOW_PRIORITY);
00592 for(var i=0;i<_windows.length;++i)
00593 if(_windows[i].getWindowName() == name && _windows[i].getWindowSubName() == subname) {
00594 Debug.log("Window creation failed. Not unique.",Debug.LOW_PRIORITY);
00595 if(_windows[i].isMinimized()) {
00596 Debug.log(_windows[i].getWindowSubName() + "was minimized but will now be restored!");
00597 _windows[i].unminimize();
00598 }
00599 else
00600 Desktop.desktop.setForeWindow(_windows[i]);
00601 return;
00602 }
00603 }
00604
00605 if(_windows.length + _defaultWindowMinZindex >= _defaultWindowMaxZindex) {
00606 Debug.log("FAILED -- Desktop Window Added - too many windows!",Debug.HIGH_PRIORITY);
00607 return;
00608 }
00609
00610 if(name == "Security Settings") {
00611 window_width = 730;
00612 window_height = 410;
00613 }
00614 else if(name == "Edit User Data") {
00615 window_width = 730;
00616 window_height = 730;
00617 }
00618 else {
00619 window_width = _defaultWidth;
00620 window_height = _defaultHeight;
00621 }
00622
00623
00624
00625 var newWin = Desktop.createWindow(_winId++,_windows.length + _defaultWindowMinZindex,name,subname,url,
00626 window_width,window_height,_dashboard.getDashboardWidth() + _currentLeft,_currentTop);
00627
00628
00629 if(_currentLeft > _defaultLeft+_defaultOffsetTimes*_defaultLeftOffset) {
00630 _currentLeft = _defaultLeft;
00631 if(_currentTop > _defaultTop + (_defaultOffsetTimes+1)*_defaultTopOffset)
00632 _currentTop = _defaultTop;
00633 else
00634 _currentTop = _defaultTop + _defaultTopOffset;
00635 }
00636 else
00637 {
00638 _currentLeft += _defaultLeftOffset;
00639 _currentTop += _defaultTopOffset;
00640 }
00641
00642 _windows.push(newWin);
00643
00644 _desktopElement.appendChild(newWin.windiv);
00645
00646 Debug.log("Desktop Window Added with id " + _windows[_windows.length-1].getWindowId(),Debug.LOW_PRIORITY);
00647
00648 _dashboard.updateWindows();
00649
00650
00651
00652
00653 setTimeout(function(){
00654 Desktop.desktop.setForeWindow(newWin);
00655 Debug.log("extraStep=" + extraStep);
00656 switch(extraStep)
00657 {
00658 case 1:
00659 Desktop.desktop.dashboard.windowDashboardOrganize();
00660 break;
00661 case 2:
00662 Desktop.desktop.toggleFullScreen();
00663 break;
00664 default:;
00665 }
00666
00667 }, 200);
00668
00669
00670
00671 return newWin;
00672 }
00673
00674
00675
00676 this.getWindowById = function(id) {
00677 for(var i=0;i<_windows.length;++i) {
00678 if(_windows[i].getWindowId() == id) return _windows[i];
00679 }
00680 return -1;
00681 }
00682
00683
00684
00685
00686
00687
00688
00689 this.setForeWindow = function(win) {
00690
00691
00692 var tmp;
00693 for(var i=0;i<_windows.length-1;++i) {
00694 var min = i;
00695 for(var j=i+1;j<_windows.length;++j)
00696 if(_windows[j].getWindowZ() < _windows[min].getWindowZ())
00697 min = j;
00698
00699
00700 tmp = _windows[i];
00701 _windows[i] = _windows[min];
00702 _windows[min] = tmp;
00703 _windows[i].setWindowZ(i+_defaultWindowMinZindex);
00704 }
00705 _windows[_windows.length-1].setWindowZ(_windows.length-1+_defaultWindowMinZindex);
00706 _windowZmailbox.innerHTML = _defaultWindowMaxZindex;
00707
00708
00709
00710 var found = 0;
00711 for(var i=0;win && i<=_windows.length;++i) {
00712 if(found)
00713 {
00714 var winToMov = i<_windows.length?_windows[i]:win;
00715 winToMov.setWindowZ(i-1 + _defaultWindowMinZindex);
00716 _windows[i-1] = winToMov;
00717 }
00718 else if(_windows[i] == win) found = 1;
00719 }
00720
00721 if(!found && win)
00722 Debug.log("Desktop Foreground window not Found!! Window: " +
00723 win.getWindowSubName());
00724
00725 _dashboard.updateWindows();
00726
00727
00728
00729 }
00730
00731
00732
00733 this.closeWindowById = function(id) {
00734 var win = this.getWindowById(id);
00735 if(win == -1) return -1;
00736 _closeWindow(win);
00737 }
00738
00739
00740
00741 this.maximizeWindowById = function(id) {
00742 var win = this.getWindowById(id);
00743 if(win == -1) return -1;
00744 this.setForeWindow(win);
00745 this.toggleFullScreen();
00746 }
00747
00748
00749
00750 this.toggleFullScreen = function(e) {
00751 if(!_getForeWindow()) return;
00752
00753 _getForeWindow().isMaximized() ? _getForeWindow().unmaximize(): _getForeWindow().maximize();
00754
00755 Desktop.desktop.redrawDashboardWindowButtons();
00756
00757
00758
00759 Debug.log("Full Screen Toggled",Debug.LOW_PRIORITY);
00760 }
00761
00762 this.redrawDashboardWindowButtons = function() {
00763 _dashboard.redrawFullScreenButton();
00764 _dashboard.redrawRefreshButton();
00765 _dashboard.redrawShowDesktopButton();
00766 }
00767
00768 this.refreshWindowById = function(id) {
00769 var win = this.getWindowById(id);
00770 if(win == -1) return -1;
00771
00772 this.setForeWindow(win);
00773 this.refreshWindow();
00774 console.log("Finished refreshWindow() " + id);
00775 }
00776
00777 this.refreshWindow = function(e) {
00778 if(!_getForeWindow()) return;
00779
00780
00781 var window = _getForeWindow();
00782 var id = window.getWindowId();
00783 var z = window.getWindowZ();
00784 var name = window.getWindowName();
00785 var subname = window.getWindowSubName();
00786 var url = window.getWindowUrl();
00787 var width = window.getWindowWidth();
00788 var height = window.getWindowHeight();
00789 var x = window.getWindowX();
00790 var y = window.getWindowY();
00791 var isMax = window.isMaximized();
00792 var isMin = window.isMinimized();
00793
00794 _closeWindow(window);
00795 console.log(window, id, z, name, width, height);
00796
00797 var newWindow = this.addWindow(name,subname,url);
00798 newWindow.setWindowSizeAndPosition(x,y,width,height);
00799
00800 if(isMax)
00801 newWindow.maximize();
00802 if(isMin)
00803 newWindow.minimize();
00804
00805
00806 }
00807
00808
00809
00810 this.minimizeWindowById = function(id) {
00811 var win = this.getWindowById(id);
00812 if(win == -1) return -1;
00813
00814 this.setForeWindow(win);
00815 this.toggleMinimize();
00816 }
00817
00818
00819
00820 this.toggleMinimize = function(e) {
00821 if(!_getForeWindow()) return;
00822
00823 if(_getForeWindow().isMinimized())
00824 _getForeWindow().unminimize();
00825 else
00826 _getForeWindow().minimize();
00827 Debug.log("Minimize Toggled",Debug.LOW_PRIORITY);
00828
00829
00830 }
00831
00832
00833 this.clickedWindowDashboard = function(id) {
00834 var win = this.getWindowById(id);
00835 if(win == -1) return -1;
00836 if(_getForeWindow() != win) {
00837 if(_getForeWindow().isMaximized()) this.toggleFullScreen();
00838 this.setForeWindow(win);
00839 if(_getForeWindow().isMinimized()) this.toggleMinimize();
00840 return;
00841 }
00842
00843 this.toggleMinimize();
00844 }
00845
00846
00847
00848 this.setDefaultWindowColor = function(color) {
00849 this.defaultWindowFrameColor = color;
00850 _windowColorPostbox.innerHTML = this.defaultWindowFrameColor;
00851
00852 for(var i=0;i<_windows.length;++i)
00853 _windows[i].windiv.style.backgroundColor = this.defaultWindowFrameColor;
00854 }
00855
00856
00857
00858
00859
00860
00861 this.defaultLayoutSelect = function(i) {
00862 Debug.log("Desktop defaultLayoutSelect " + i,Debug.LOW_PRIORITY);
00863
00864 var layoutStr;
00865 var numOfUserLayouts = 5;
00866 var numOfSystemLayouts = 5;
00867 if(i >= numOfSystemLayouts+1 &&
00868 i <= numOfSystemLayouts+1+numOfUserLayouts)
00869 layoutStr = _login.getUserDefaultLayout(i-(numOfSystemLayouts+1));
00870 else if(i >= 0 && i <= numOfSystemLayouts)
00871 layoutStr = _login.getSystemDefaultLayout(i);
00872 else
00873 {
00874 Debug.log("Invalid layout index: " + i, Debug.HIGH_PRIORITY);
00875 return;
00876 }
00877 var layoutArr = layoutStr.split(",");
00878
00879 var numOfFields = 8;
00880 var numOfWins = parseInt(layoutArr.length/numOfFields);
00881
00882 Debug.log("Desktop defaultLayoutSelect layout numOfFields=" + numOfFields);
00883 Debug.log("Desktop defaultLayoutSelect layout " + numOfWins +
00884 " windows - " + layoutStr);
00885
00886
00887 Desktop.desktop.closeAllWindows();
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902 var dw = Desktop.desktop.getDesktopContentWidth()/10000.0;
00903 var dh = Desktop.desktop.getDesktopContentHeight()/10000.0;
00904 var dx = Desktop.desktop.getDesktopContentX();
00905 var dy = Desktop.desktop.getDesktopContentY();
00906 for(i=0;i<numOfWins;++i)
00907 {
00908 Debug.log("adding " + layoutArr[i*numOfFields].substr(1) + "-" + layoutArr[i*numOfFields+1],Debug.LOW_PRIORITY);
00909 this.addWindow(
00910 decodeURIComponent(layoutArr[i*numOfFields]),
00911 decodeURIComponent(layoutArr[i*numOfFields+1]),
00912 decodeURIComponent(layoutArr[i*numOfFields+2]),
00913 false);
00914 _windows[_windows.length-1].setWindowSizeAndPosition(
00915 layoutArr[i*numOfFields+3]*dw + dx,
00916 layoutArr[i*numOfFields+4]*dh + dy,
00917 layoutArr[i*numOfFields+5]*dw,
00918 layoutArr[i*numOfFields+6]*dh);
00919
00920 if((layoutArr[i*numOfFields+7]|0) == 0)
00921 _windows[_windows.length-1].minimize();
00922 else if((layoutArr[i*numOfFields+7]|0) == 2)
00923 _windows[_windows.length-1].maximize();
00924 }
00925 }
00926
00927
00928
00929 this.closeAllWindows = function() {
00930 Debug.log("Desktop closeAllWindows",Debug.LOW_PRIORITY);
00931
00932 while(_windows.length) _closeWindow(_windows[_windows.length-1]);
00933 }
00934
00935
00936
00937 this.resetDesktop = function(permissions) {
00938
00939 _needToLoginMailbox.innerHTML = "";
00940 _blockSystemCheckMailbox.innerHTML = "";
00941 _sysMsgCounter = 0;
00942
00943 if(permissions !== undefined)
00944 Desktop.desktop.icons.resetWithPermissions(permissions);
00945
00947 if(!Desktop.desktop.login || !Desktop.desktop.login.getCookieCode(true))
00948 {
00949 Desktop.desktop.login.setupLogin();
00950
00951 window.clearInterval(Desktop.desktop.checkMailboxTimer);
00952 Desktop.desktop.checkMailboxTimer = setInterval(_checkMailboxes,
00953 _MAILBOX_TIMER_PERIOD);
00954 }
00955
00956
00957
00958
00959
00960
00961
00962
00963 }
00964
00965 this.refreshDesktop = function() {
00966
00967
00968 for(var i=0; i<Desktop.desktop.getNumberOfWindows();++i)
00969 {
00970 Desktop.desktop.refreshWindowById(Desktop.desktop.getWindowByIndex(i));
00971 }
00972
00973
00974 }
00975
00976
00977
00978 this.actOnParameterAction = function() {
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988 var paramsStr = window.parent.window.location.search.substr(1);
00989 var params = [];
00990 var paramCnt = 5 + (Desktop.isWizardMode()?1:0);
00991 var spliti, splitiOld = 0;
00992 for(var i=0;i<paramCnt;++i)
00993 {
00994 if(i == paramCnt-1)
00995 {
00996 params.push(paramsStr.substr(splitiOld));
00997 break;
00998 }
00999
01000 spliti = paramsStr.indexOf('&', splitiOld);
01001 params.push(paramsStr.substr(splitiOld,spliti-splitiOld))
01002 splitiOld = spliti+1;
01003 }
01004
01005 var varPair;
01006 var requestingWindowId = "", windowPath = "";
01007 var windowName, windowSubname, windowUnique, newWindowOps;
01008 for(var i=0;i<params.length;++i)
01009 {
01010 spliti = params[i].indexOf('=');
01011 varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
01012 if(varPair[0] == "requestingWindowId")
01013 requestingWindowId = varPair[1];
01014 else if(varPair[0] == "windowPath")
01015 windowPath = decodeURIComponent(varPair[1]);
01016 else if(varPair[0] == "windowName")
01017 windowName = varPair[1];
01018 else if(varPair[0] == "windowSubname")
01019 windowSubname = varPair[1];
01020 else if(varPair[0] == "windowUnique")
01021 windowUnique = varPair[1];
01022 }
01023
01024 if(windowPath.indexOf("newWindowOps") >= 0)
01025 {
01026
01027 newWindowOps = windowPath.split('&')[1].split('=')[1];
01028 windowPath = windowPath.split('&')[0];
01029 }
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050 if(requestingWindowId != "" && windowPath != "")
01051 {
01052
01053 Debug.log("_openWindowMailbox.innerHTML=" + _openWindowMailbox.innerHTML);
01054 Debug.log("requestingWindowId=" + requestingWindowId);
01055 Debug.log("windowPath=" + windowPath);
01056 if(newWindowOps) newWindowOps = newWindowOps.replace(/%22/g, "\"");
01057 Debug.log("newWindowOps=" + newWindowOps);
01058 windowName = windowName.replace(/%20/g, " ");
01059 Debug.log("windowName=" + windowName);
01060 windowSubname = windowSubname.replace(/%20/g, " ");
01061 Debug.log("windowSubname=" + windowSubname);
01062 Debug.log("windowUnique=" + windowUnique);
01063
01064 var newWin;
01065
01066
01067
01068 if(windowName.indexOf("Desktop.openLayout(") == 0)
01069 {
01070 var layoutIndex = windowName.substr(("Desktop.openLayout(").length,
01071 windowName.length-1-("Desktop.openLayout(").length) | 0;
01072 Debug.log("Opening layout... " + layoutIndex);
01073
01074 if(pathUniquePair ===
01075 undefined)
01076 {
01077
01078 if(_firstCheckOfMailboxes)
01079 {
01080 Debug.log("Perhaps user layout preferences have not been setup yet, try again at mailbox check.");
01081 return;
01082 }
01083 }
01084
01085
01086 _firstCheckOfMailboxes = false;
01087
01088 Desktop.desktop.dashboard.toggleWindowDashboard(0,false);
01089 Desktop.desktop.defaultLayoutSelect(layoutIndex);
01090 return;
01091 }
01092
01093
01094
01095 if(windowSubname == "undefined" &&
01096 windowUnique == "undefined")
01097 {
01098 Debug.log("Opening desktop window... " + windowName);
01099
01100
01101 var pathUniquePair = Desktop.desktop.icons.iconNameToPathMap[windowName];
01102 console.log("Desktop.desktop.icons.iconNameToPathMap",
01103 Desktop.desktop.icons.iconNameToPathMap);
01104
01105 if(pathUniquePair ===
01106 undefined)
01107 {
01108
01109 if(_firstCheckOfMailboxes)
01110 {
01111 Debug.log("Perhaps icons have not been setup yet, try again at mailbox check.");
01112 return;
01113 }
01114
01115 Debug.log("An error occurred opening the window named '" +
01116 windowName + "' - it was not found in the Desktop icons. " +
01117 "Do you have permissions to access this window? Notify admins if the problem persists.",
01118 Debug.HIGH_PRIORITY);
01119
01120
01121
01122 _openWindowMailbox.innerHTML = "";
01123 return;
01124 }
01125 var pathStr = pathUniquePair[0];
01126
01127 if(windowPath != "undefined")
01128 {
01129 Debug.log("Adding parameter path " + windowPath);
01130 if(pathStr.indexOf('&') > 0)
01131 pathStr += "&";
01132 else if(pathStr.length &&
01133 pathStr[pathStr.lengh-1] != '?')
01134 pathStr += '?';
01135 windowPath = pathStr + windowPath;
01136 }
01137 else
01138 windowPath = pathStr;
01139
01140 newWin = Desktop.desktop.addWindow(
01141 windowName,
01142 "",
01143 windowPath +
01144 ((windowPath.indexOf('?') < 0)? "?":"&") +
01145 ((newWindowOps)?"newWindowOps=" + newWindowOps:""),
01146 eval(pathUniquePair[1]));
01147 }
01148 else
01149 {
01150 _firstCheckOfMailboxes = false;
01151 newWin = Desktop.desktop.addWindow(
01152 windowName,
01153 windowSubname,
01154 windowPath +
01155 ((windowPath.indexOf('?') < 0)? "?":"&") +
01156 ((newWindowOps)?"newWindowOps=" + newWindowOps:""),
01157 eval(windowUnique));
01158 }
01159
01160
01161
01162 Desktop.desktop.dashboard.toggleWindowDashboard(0,false);
01163
01164
01165
01166 setTimeout(function(){
01167 Desktop.desktop.setForeWindow(newWin);
01168 Desktop.desktop.toggleFullScreen();
01169 }, 200);
01170
01171
01172 _openWindowMailbox.innerHTML = "";
01173 }
01174 }
01175
01176
01177
01178
01179
01180
01181 _desktopElement = document.createElement("div");
01182 _desktopElement.setAttribute("id", "Desktop");
01183 document.body.appendChild(_desktopElement);
01184 document.body.onmousemove = Desktop.handleBodyMouseMove;
01185 window.onmouseup = Desktop.handleWindowMouseUp;
01186 document.body.addEventListener('touchmove',Desktop.handleBodyTouchMove);
01187 document.body.addEventListener('touchend',Desktop.handleBodyTouchEnd);
01188 window.onresize = _handleDesktopResize;
01189 Desktop.desktop = this;
01190
01191
01192 _windowZmailbox = document.createElement("div");
01193 _windowZmailbox.setAttribute("id", "Desktop-windowZmailbox");
01194 _windowZmailbox.innerHTML = _defaultWindowMaxZindex;
01195 _windowZmailbox.style.display = "none";
01196 _desktopElement.appendChild(_windowZmailbox);
01197
01198
01199 _mouseOverXmailbox = document.createElement("div");
01200 _mouseOverXmailbox.setAttribute("id", "Desktop-mouseOverXmailbox");
01201 _mouseOverXmailbox.style.display = "none";
01202 _desktopElement.appendChild(_mouseOverXmailbox);
01203
01204
01205 _mouseOverYmailbox = document.createElement("div");
01206 _mouseOverYmailbox.setAttribute("id", "Desktop-mouseOverYmailbox");
01207 _mouseOverYmailbox.style.display = "none";
01208 _desktopElement.appendChild(_mouseOverYmailbox);
01209 this.resetFrameMouse();
01210
01211
01212 var tmpHiddenDiv = document.createElement("div");
01213 tmpHiddenDiv.setAttribute("id", "DesktopContent-cookieCodeMailbox");
01214 tmpHiddenDiv.style.display = "none";
01215 _desktopElement.appendChild(tmpHiddenDiv);
01216 _updateTimeMailbox = document.createElement("div");
01217 _updateTimeMailbox.setAttribute("id", "DesktopContent-updateTimeMailbox");
01218 _updateTimeMailbox.style.display = "none";
01219 _desktopElement.appendChild(_updateTimeMailbox);
01220 _needToLoginMailbox = document.createElement("div");
01221 _needToLoginMailbox.setAttribute("id", "DesktopContent-needToLoginMailbox");
01222 _needToLoginMailbox.style.display = "none";
01223 _desktopElement.appendChild(_needToLoginMailbox);
01224
01225 _blockSystemCheckMailbox = document.createElement("div");
01226 _blockSystemCheckMailbox.setAttribute("id", "DesktopContent-blockSystemCheckMailbox");
01227 _blockSystemCheckMailbox.style.display = "none";
01228 _desktopElement.appendChild(_blockSystemCheckMailbox);
01229
01230
01231
01232
01233 _openWindowMailbox = document.createElement("div");
01234 _openWindowMailbox.setAttribute("id", "DesktopContent-openWindowMailbox");
01235 _openWindowMailbox.style.display = "none";
01236 _desktopElement.appendChild(_openWindowMailbox);
01237
01238
01239 _updateSettingsMailbox = document.createElement("div");
01240 _updateSettingsMailbox.setAttribute("id", "DesktopContent-updateSettingsMailbox");
01241 _updateSettingsMailbox.style.display = "none";
01242 _updateSettingsMailbox.innerHTML = "";
01243 _desktopElement.appendChild(_updateSettingsMailbox);
01244 _settingsLayoutMailbox = document.createElement("div");
01245 _settingsLayoutMailbox.setAttribute("id", "DesktopContent-settingsLayoutMailbox");
01246 _settingsLayoutMailbox.style.display = "none";
01247 _settingsLayoutMailbox.innerHTML = "";
01248 _desktopElement.appendChild(_settingsLayoutMailbox);
01249
01250
01251 _windowColorPostbox = document.createElement("div");
01252 _windowColorPostbox.setAttribute("id", "DesktopContent-windowColorPostbox");
01253 _windowColorPostbox.style.display = "none";
01254 _windowColorPostbox.innerHTML = this.defaultWindowsFrameColor;
01255 _desktopElement.appendChild(_windowColorPostbox);
01256
01257
01258
01259 this.dashboard = _dashboard = Desktop.createDashboard(_defaultDashboardZindex);
01260 _desktopElement.appendChild(_dashboard.dashboardElement);
01261
01262
01263 this.icons = _icons = Desktop.createIcons(0);
01264 _desktopElement.appendChild(_icons.iconsElement);
01265
01266 _handleDesktopResize();
01267
01268 this.checkMailboxTimer = setInterval(_checkMailboxes,_MAILBOX_TIMER_PERIOD);
01269
01270
01271 this.login = _login = new Desktop.login(!(this.security == Desktop.SECURITY_TYPE_NONE));
01272 if(_login.loginDiv)
01273 _desktopElement.appendChild(_login.loginDiv);
01274
01275 Debug.log("Desktop Created",Debug.LOW_PRIORITY);
01276
01277 Debug.log("Checking for any shortcut work from get parameters...",Debug.LOW_PRIORITY);
01278 Desktop.desktop.actOnParameterAction();
01279 }
01280
01283
01286
01287 Desktop.foreWinLastMouse = [-1,-1];
01288 Desktop.winManipMode = -1;
01289 Desktop.stretchAndMoveInterval = 0;
01290 Desktop.disableMouseDown = 0;
01291
01293
01294
01295
01296
01297 Desktop.handleTouchStart = function(touchEvent) {
01298 Desktop.disableMouseDown = 1;
01299 var touch = touchEvent.targetTouches[0];
01300
01301 var winId = this.id.split('-')[1];
01302 var isDashboard = (winId == "windowDashboard");
01303 var win;
01304 if(!isDashboard){
01305 win = Desktop.desktop.getWindowById(winId);
01306 if(win == -1) return false;
01307 if(win.isMaximized()) {this.style.cursor = "default";return false;}
01308
01309
01310 if(Desktop.desktop.getForeWindow() != win)
01311 Desktop.desktop.setForeWindow(win);
01312 }
01313 else return false;
01314
01315
01316 if(Desktop.foreWinLastMouse[0] == -1) {
01317 var locX = touch.pageX - this.offsetLeft;
01318 var locY = touch.pageY - this.offsetTop;
01319
01320
01321
01322 Desktop.desktop.getForeWindow().hideFrame();
01323
01324 Desktop.foreWinLastMouse = [touch.pageX,touch.pageY];
01325
01326 if(locY < win.getWindowHeaderHeight()) {
01327 Desktop.winManipMode = 0;
01328 }
01329 }
01330
01331 return false;
01332 }
01333
01334
01335
01336 Desktop.handleBodyTouchEnd = function(touchEvent) {Desktop.handleTouchEnd(touchEvent);}
01337 Desktop.handleTouchEnd = function(touchEvent) {
01338
01339 if(Desktop.foreWinLastMouse[0] != -1)
01340 {
01341 Desktop.foreWinLastMouse = [-1,-1];
01342 Desktop.winManipMode = -1;
01343 if(Desktop.desktop.getForeWindow()) Desktop.desktop.getForeWindow().showFrame();
01344
01345 }
01346 }
01347
01348
01349
01350 Desktop.handleBodyTouchMove = function(touchEvent) {Desktop.handleTouchMove(touchEvent);}
01351 Desktop.handleTouchMove = function(touchEvent) {
01352 if(Desktop.winManipMode != -1 && Desktop.foreWinLastMouse[0] != -1)
01353 {
01354 touchEvent.preventDefault();
01355 touchEvent.cancelBubble=true;
01356
01357 var touch = touchEvent.targetTouches[0];
01358 var delta = [touch.pageX-Desktop.foreWinLastMouse[0], touch.pageY-Desktop.foreWinLastMouse[1]];
01359
01360 Desktop.desktop.getForeWindow().moveWindowByOffset(delta[0],delta[1]);
01361 Desktop.foreWinLastMouse = [touch.pageX,touch.pageY];
01362 }
01363 }
01365
01366
01367
01368 Desktop.handleWindowMouseDown = function(mouseEvent) {
01369 var winId = this.id.split('-')[1];
01370 var isDashboard = (winId == "windowDashboard");
01371 var win;
01372 if(!isDashboard) {
01373 win = Desktop.desktop.getWindowById(winId);
01374 if(win == -1) return false;
01375
01376
01377 if(Desktop.desktop.getForeWindow() != win)
01378 Desktop.desktop.setForeWindow(win);
01379 }
01380
01381
01382 if(!Desktop.disableMouseDown && Desktop.winManipMode != -1 && this.style.cursor != "default")
01383 {
01384
01385 Desktop.foreWinLastMouse = [mouseEvent.clientX,mouseEvent.clientY];
01386 if(!isDashboard) Desktop.desktop.getForeWindow().hideFrame();
01387
01388 }
01389
01390
01391
01392 return false;
01393 }
01394
01395
01396
01397 Desktop.handleWindowMouseUp = function(mouseEvent) {
01398
01399 if(Desktop.foreWinLastMouse[0] != -1)
01400 {
01401 if(Desktop.stretchAndMoveInterval) {
01402 clearInterval(Desktop.stretchAndMoveInterval);
01403 Desktop.stretchAndMoveInterval = 0;
01404 }
01405
01406 Desktop.foreWinLastMouse = [-1,-1];
01407 Desktop.winManipMode = -1;
01408 if(Desktop.desktop.getForeWindow()) Desktop.desktop.getForeWindow().showFrame();
01409
01410
01411 }
01412 Desktop.desktop.icons.closeFolder();
01413 return false;
01414 }
01415
01416
01417 Desktop.handleWindowMouseMove = function(mouseEvent) {
01418 var winId = this.id.split('-')[1];
01419 var isDashboard = (winId == "windowDashboard");
01420 var win;
01421 if(!isDashboard){
01422 win = Desktop.desktop.getWindowById(winId);
01423 if(win == -1) return false;
01424 if(win.isMaximized()) {this.style.cursor = "default";return false;}
01425 }
01426
01427
01428 if(Desktop.foreWinLastMouse[0] == -1) {
01429 var locX = mouseEvent.clientX - this.offsetLeft;
01430 var locY = mouseEvent.clientY - this.offsetTop;
01431
01432 var hotCornerSz = 7;
01433 if(isDashboard) {
01434 if(locX > Desktop.desktop.dashboard.getDashboardWidth() - hotCornerSz) {
01435 this.style.cursor = "e-resize";
01436 Desktop.winManipMode = 100;
01437 }
01438 else
01439 this.style.cursor = "default";
01440 }
01441 else {
01442 if((locX < hotCornerSz && locY < hotCornerSz) ||
01443 (locX > win.getWindowWidth() - hotCornerSz && locY > win.getWindowHeight() - hotCornerSz)) {
01444 this.style.cursor = "nw-resize";
01445 Desktop.winManipMode = locY < hotCornerSz?1:2;
01446 }
01447 else if((locX > win.getWindowWidth() - hotCornerSz && locY < hotCornerSz) ||
01448 (locX < hotCornerSz && locY > win.getWindowHeight() - hotCornerSz)) {
01449 this.style.cursor = "ne-resize";
01450 Desktop.winManipMode = locY < hotCornerSz?3:4;
01451 }
01452 else if(locX < hotCornerSz) {
01453 this.style.cursor = "w-resize";
01454 Desktop.winManipMode = 5;
01455 }
01456 else if(locX > win.getWindowWidth() - hotCornerSz) {
01457 this.style.cursor = "e-resize";
01458 Desktop.winManipMode = 6;
01459 }
01460 else if(locY < hotCornerSz) {
01461 this.style.cursor = "n-resize";
01462 Desktop.winManipMode = 7;
01463 }
01464 else if(locY > win.getWindowHeight() - hotCornerSz) {
01465 this.style.cursor = "s-resize";
01466 Desktop.winManipMode = 8;
01467 }
01468 else if(locY < win.getWindowHeaderHeight()) {
01469 this.style.cursor = "all-scroll";
01470 Desktop.winManipMode = 0;
01471 }
01472 else
01473 this.style.cursor = "default";
01474 }
01475 }
01476
01477
01478 Desktop.handleBodyMouseMove(mouseEvent);
01479
01480 return false;
01481 }
01482
01483 Desktop._mouseMoveSubscribers = [];
01484
01485 Desktop.mouseMoveSubscriber = function(newHandler) {
01486 Desktop._mouseMoveSubscribers.push(newHandler);
01487 }
01488
01489
01490
01491 Desktop.handleBodyMouseMove = function(mouseEvent) {
01492
01493
01494 for(var i=0; i<Desktop._mouseMoveSubscribers.length; ++i)
01495 Desktop._mouseMoveSubscribers[i](mouseEvent);
01496
01497 Desktop.desktop.resetFrameMouse();
01498
01499
01500 if(Desktop.foreWinLastMouse[0] != -1 && Desktop.winManipMode == 100) {
01501
01502 if(mouseEvent.which == 0)
01503 return Desktop.handleWindowMouseUp(mouseEvent);
01504
01505 var delta = mouseEvent.clientX-Desktop.foreWinLastMouse[0];
01506 Desktop.desktop.dashboard.setDashboardWidth(Desktop.desktop.dashboard.getDashboardWidth()+delta);
01507 Desktop.foreWinLastMouse = [mouseEvent.clientX,mouseEvent.clientY];
01508
01509 if(Desktop.stretchAndMoveInterval == 0)
01510 Desktop.stretchAndMoveInterval = setInterval(
01511 function() {
01512 if(Desktop.desktop.getLastFrameMouseX() == -1) return;
01513
01514 var delta = Desktop.desktop.getLastFrameMouseX()-Desktop.foreWinLastMouse[0];
01515 Desktop.desktop.dashboard.setDashboardWidth(Desktop.desktop.dashboard.getDashboardWidth()+delta);
01516 Desktop.foreWinLastMouse = [Desktop.desktop.getLastFrameMouseX(),Desktop.desktop.getLastFrameMouseY()];
01517 }
01518 ,10);
01519
01520 return false;
01521 }
01522
01523 if(!Desktop.desktop.getForeWindow()) return false;
01524
01525 if(Desktop.foreWinLastMouse[0] != -1)
01526 {
01527 if(mouseEvent.which == 0)
01528 return Desktop.handleWindowMouseUp(mouseEvent);
01529
01530 var delta = [mouseEvent.clientX-Desktop.foreWinLastMouse[0], mouseEvent.clientY-Desktop.foreWinLastMouse[1]];
01531
01532 Desktop.handleWindowManipulation(delta);
01533
01534 Desktop.foreWinLastMouse = [mouseEvent.clientX,mouseEvent.clientY];
01535
01536 if(Desktop.stretchAndMoveInterval == 0)
01537 Desktop.stretchAndMoveInterval = setInterval(
01538 function() {
01539 if(Desktop.desktop.getLastFrameMouseX() == -1) return;
01540
01541 var delta = [Desktop.desktop.getLastFrameMouseX()-Desktop.foreWinLastMouse[0],
01542 Desktop.desktop.getLastFrameMouseY()-Desktop.foreWinLastMouse[1]];
01543 Desktop.handleWindowManipulation(delta);
01544 Desktop.foreWinLastMouse = [Desktop.desktop.getLastFrameMouseX(),Desktop.desktop.getLastFrameMouseY()];
01545 }
01546 ,10);
01547 }
01548
01549 return false;
01550 }
01551
01552
01553
01554 Desktop.handleWindowManipulation = function(delta) {
01555 if(!Desktop.desktop.getForeWindow()) return false;
01556
01557 var win = Desktop.desktop.getForeWindow();
01558
01559 switch(Desktop.winManipMode) {
01560 case 0:
01561 win.moveWindowByOffset(delta[0],delta[1]);
01562 break;
01563 case 1:
01564 win.resizeAndPositionWindow(
01565 win.getWindowX() + delta[0],
01566 win.getWindowY() + delta[1],
01567 win.getWindowWidth() - delta[0],
01568 win.getWindowHeight() - delta[1]);
01569 break;
01570 case 2:
01571 win.resizeAndPositionWindow(
01572 win.getWindowX(),
01573 win.getWindowY(),
01574 win.getWindowWidth() + delta[0],
01575 win.getWindowHeight() + delta[1]);
01576 break;
01577 case 3:
01578 win.resizeAndPositionWindow(
01579 win.getWindowX(),
01580 win.getWindowY() + delta[1],
01581 win.getWindowWidth() + delta[0],
01582 win.getWindowHeight() - delta[1]);
01583 break;
01584 case 4:
01585 win.resizeAndPositionWindow(
01586 win.getWindowX() + delta[0],
01587 win.getWindowY(),
01588 win.getWindowWidth() - delta[0],
01589 win.getWindowHeight() + delta[1]);
01590 break;
01591 case 5:
01592 win.resizeAndPositionWindow(
01593 win.getWindowX() + delta[0],
01594 win.getWindowY(),
01595 win.getWindowWidth() - delta[0],
01596 win.getWindowHeight());
01597 break;
01598 case 6:
01599 win.resizeAndPositionWindow(
01600 win.getWindowX(),
01601 win.getWindowY(),
01602 win.getWindowWidth() + delta[0],
01603 win.getWindowHeight());
01604 break;
01605 case 7:
01606 win.resizeAndPositionWindow(
01607 win.getWindowX(),
01608 win.getWindowY() + delta[1],
01609 win.getWindowWidth(),
01610 win.getWindowHeight() - delta[1]);
01611 break;
01612 case 8:
01613 win.resizeAndPositionWindow(
01614 win.getWindowX(),
01615 win.getWindowY(),
01616 win.getWindowWidth(),
01617 win.getWindowHeight() + delta[1]);
01618 break;
01619 default:
01620 }
01621 }
01622
01623 Desktop.handleWindowButtonDown = function(mouseEvent) {
01624 mouseEvent.cancelBubble=true;
01625 return false;
01626 }
01627
01628 Desktop.handleWindowRefresh = function(mouseEvent){
01629 Debug.log("Refresh " + this.id.split('-')[1]);
01630 Desktop.desktop.refreshWindowById(this.id.split('-')[1]);
01631 return false;
01632
01633 }
01634
01635 Desktop.handleFullScreenWindowRefresh = function(mouseEvent){
01636 Debug.log("Refresh Full Screen Window");
01637 Desktop.desktop.resetDesktop();
01638 Desktop.desktop.refreshDesktop();
01639
01640
01641
01642 for(var i = 0; i < Desktop.desktop.getNumberOfWindows(); i++)
01643 {
01644 var zIndex = Desktop.desktop.getWindowByIndex(i).getWindowZ();
01645 Debug.log(zIndex);
01646 Debug.log("I: " + i + " " + Desktop.desktop.getWindowByIndex(0).getWindowName());
01647 Debug.log(Desktop.desktop.getWindowByIndex(0).getWindowId());
01648 Desktop.desktop.setForeWindow(Desktop.desktop.getWindowByIndex(0));
01649 Desktop.desktop.refreshWindow();
01650
01651
01652 }
01653
01654 return false;
01655
01656 }
01657
01658 Desktop.handleWindowMinimize = function(mouseEvent) {
01659 Debug.log("minimize " + this.id.split('-')[1]);
01660 Desktop.desktop.minimizeWindowById(this.id.split('-')[1]);
01661 return false;
01662 }
01663
01664 Desktop.handleWindowMaximize = function(mouseEvent) {
01665 Debug.log("maximize " + this.id.split('-')[1]);
01666 Desktop.desktop.maximizeWindowById(this.id.split('-')[1]);
01667 return false;
01668 }
01669
01670 Desktop.handleWindowClose = function(mouseEvent) {
01671
01672 Desktop.desktop.closeWindowById(this.id.split('-')[1]);
01673 return false;
01674 }
01675
01676
01677
01678
01679
01680
01681
01682
01683 Desktop.XMLHttpRequest = function(requestURL, data, returnHandler, reqIndex) {
01684
01685 var errStr = "";
01686 var req = new XMLHttpRequest();
01687
01688 req.onreadystatechange = function() {
01689 if (req.readyState==4) {
01690 if(req.status==200)
01691 {
01692
01693
01694 if(!Desktop.desktop.serverConnected)
01695 {
01696 Desktop.desktop.serverConnected = true;
01697 Desktop.desktop.dashboard.displayConnectionStatus(true);
01698
01699 Desktop.desktop.resetDesktop();
01700
01701 }
01702
01703
01704 if(req.responseText == Globals.REQ_NO_PERMISSION_RESPONSE)
01705 {
01706 errStr = "Request failed do to insufficient account permissions.";
01707
01708 }
01709 else if(req.responseText == Globals.REQ_NO_LOGIN_RESPONSE)
01710 {
01711 errStr = "Login has expired.";
01712
01713 window.clearInterval(Desktop.desktop.checkMailboxTimer);
01714 Desktop.logout();
01715
01716 }
01717
01718
01719 }
01720 else
01721 {
01722
01723
01724 if(Desktop.desktop.serverConnected)
01725 {
01726 Desktop.desktop.serverConnected = false;
01727 Desktop.desktop.dashboard.displayConnectionStatus(false);
01728 }
01729
01730 errStr = "Request Failed - Bad Address:\n" + requestURL;
01731 window.clearInterval(Desktop.desktop.checkMailboxTimer);
01732 Desktop.logout();
01733 }
01734
01735 if(errStr != "")
01736 {
01737 errStr += "\n\n(Try refreshing the page, or alert ots admins if problem persists.)";
01738 Debug.log("Error: " + errStr,Debug.HIGH_PRIORITY);
01739
01740 req = 0;
01741
01742 Debug.log("The user interface is disconnected from the ots Gateway server.", Debug.HIGH_PRIORITY);
01743
01744 document.getElementById("DesktopDashboard-userWithLock").style.display = "none";
01745 }
01746 if(returnHandler) returnHandler(req,reqIndex,errStr);
01747 }
01748 }
01749
01750 if(Desktop.desktop.login)
01751 data = "CookieCode="+Desktop.desktop.login.getCookieCode()+"&"+data;
01752 requestURL = "/urn:xdaq-application:lid="+urnLid+"/"+requestURL;
01753
01754 req.open("POST",requestURL,true);
01755
01756 req.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
01757 req.send(data);
01758 }
01759
01760
01761 Desktop.getXMLAttributeValue = function(req, name, attribute) {
01762 if(req && req.responseXML && req.responseXML.getElementsByTagName(name).length > 0)
01763 return req.responseXML.getElementsByTagName(name)[0].getAttribute(attribute);
01764 else
01765 return undefined;
01766 }
01767
01768
01769
01770 Desktop.getXMLValue = function(req, name) {
01771 return Desktop.getXMLAttributeValue(req,name,"value");
01772 }
01773
01774
01775
01776 Desktop.logout = function () {
01777 if(Desktop.desktop && Desktop.desktop.login &&
01778 !Desktop.desktop.login.isBlackout())
01779 Desktop.desktop.login.logout();
01780 }
01781
01782
01783 Desktop.formatTime = function(t) {
01784 var date = new Date(t * 1000);
01785 var mm = date.getMinutes() < 10?"0"+date.getMinutes():date.getMinutes();
01786 var ss = date.getSeconds() < 10?"0"+date.getSeconds():date.getSeconds();
01787 return date.getHours() + ":" + mm + ":" + ss;
01788 }
01789
01790
01791 Desktop.closeSystemMessage = function(id) {
01792 var el = document.getElementById("Desktop-systemMessageBox-" + id);
01793 el.parentNode.removeChild(el);
01794 }
01795
01796
01797 Desktop.isWizardMode = function() {
01798
01799 Debug.log("Desktop Security: " + Desktop.desktop.security);
01800
01801 return !(!Desktop.desktop.security ||
01802 Desktop.desktop.security == Desktop.SECURITY_TYPE_DIGEST_ACCESS ||
01803 Desktop.desktop.security == Desktop.SECURITY_TYPE_NONE);
01804 }
01805
01806
01807 Desktop.openNewBrowserTab = function(name,subname,windowPath,unique) {
01808
01809
01810
01811
01812 {
01813 var i = windowPath.indexOf("urn:xdaq-application:lid=") + ("urn:xdaq-application:lid=").length;
01814 var isAllNumbers = true;
01815 for(i;i<windowPath.length;++i)
01816 {
01817 Debug.log(windowPath[i]);
01818
01819 if(windowPath[i] < "0" || windowPath[i] > "9")
01820 {
01821 isAllNumbers = false;
01822 break;
01823 }
01824 }
01825 if(isAllNumbers)
01826 windowPath += "/";
01827 }
01828 Debug.log("DesktopWindow= " + windowPath);
01829
01830 Debug.log("name= " + name);
01831 Debug.log("subname= " + subname);
01832 Debug.log("unique= " + unique);
01833 var search = window.parent.window.location.search;
01834 url = window.parent.window.location.pathname;
01835
01836 var str = "requestingWindowId=Desktop";
01837 str += "&windowName=" + name;
01838 str += "&windowSubname=" + subname;
01839 str += "&windowUnique=" + unique;
01840 str += "&windowPath=" + encodeURIComponent(windowPath);
01841
01842
01843
01844
01845 if(!Desktop.isWizardMode())
01846 {
01847 var i = url.indexOf("urn:xdaq-application:lid=") + ("urn:xdaq-application:lid=").length;
01848 var isAllNumbers = true;
01849 for(i;i<url.length;++i)
01850 {
01851 Debug.log(url[i]);
01852
01853 if(url[i] < "0" || url[i] > "9")
01854 {
01855 isAllNumbers = false;
01856 break;
01857 }
01858 }
01859 if(isAllNumbers)
01860 url += "/";
01861 url += "?" + str;
01862 }
01863 else
01864 {
01865 url += search.split('&')[0] + "&" + str;
01866 }
01867
01868 Debug.log("DesktopContent.openNewBrowserTab= " + url);
01869
01870 window.open(url,'_blank');
01871 }
01872
01873
01874
01875 Desktop.desktopTooltip = function() {
01876
01877 DesktopContent.tooltip("Desktop Introduction",
01878 "Welcome to the <i>otsdaq</i> Desktop environment. This is your portal " +
01879 "to all of the possibilities of <i>otsdaq</i>.\n\n" +
01880 "Briefly, here are the features:" +
01881
01882 "\n\t- <b>Desktop Window Icons:</b> " +
01883 "<INDENT>" +
01884 "Click the rounded-square icons on your Desktop to open " +
01885 "a particular window. If you hold down your click (for a second), you " +
01886 "can open the window in fullscreen, or in a new tab, or even open the window " +
01887 "then tile it on the screen with all other open windows!" +
01888 "</INDENT>" +
01889
01890 "\n\t- <b>Desktop Dashboard (top pane):</b> " +
01891 "<INDENT>" +
01892 "Along the top and left margins of the Desktop, you will find the Desktop " +
01893 "Dashboard - this section is an introduction to the top pane of the Dashboard. " +
01894 "The top pane of the Dashboard " +
01895 "is made of buttons and icons going from left to right:" +
01896
01897 "\n\t- <b>Left Pane Toggler:</b> " +
01898 "<INDENT>" +
01899 "The first button you will encounter in the top pane looks like a horizontal double-arrow " +
01900 "icon. This button toggles the display of the left pane of the Dashboard. Note when you " +
01901 "refresh the page, the state of the left pane persists!" +
01902 "</INDENT>" +
01903
01904 "\n\t- <b>Layouts Menu:</b> " +
01905 "<INDENT>" +
01906 "The next button you will encounter in the top pane reads 'Layouts.' " +
01907 "This button gives you access to your Window Layout Presets. You will see 2 'System' presets there " +
01908 "which can be setup by uesrs with admin privileges. There are also 3 'User' presets which you can setup for " +
01909 "yourself in the User Settings window (get there with " +
01910 "the cog wheel icon in the upper-right of the Desktop)." +
01911 "</INDENT>" +
01912
01913 "\n\t- <b>Tile Desktop Windows:</b> " +
01914 "<INDENT>" +
01915 "The next button you will encounter in the top pane reads 'Tile.' " +
01916 "This button will automatically tile all open Desktop Windows to fit in your browser window." +
01917 "</INDENT>" +
01918
01919 "\n\t- <b>Show Desktop:</b> " +
01920 "<INDENT>" +
01921 "The next button you will encounter in the top pane reads 'Show Desktop.' " +
01922 "This button will minimize all open Desktop Windows which is nice " +
01923 "when you want to see all of your Desktop Icons again." +
01924 "</INDENT>" +
01925
01926 "\n\t- <b>Full Screen:</b> " +
01927 "<INDENT>" +
01928 "The next button you will encounter in the top pane reads 'Full Screen.' " +
01929 "This button will maximize to full screen the Desktop Window that was last used (i.e. the window that has the focus)." +
01930 "</INDENT>" +
01931 "</INDENT>" +
01932
01933 "\n\t- <b>Desktop Dashboard (left pane):</b> " +
01934 "<INDENT>" +
01935 "Along the top and left margins of the Desktop, you will find the Desktop " +
01936 "Dashboard - this section is an introduction to the left pane of the Dashboard. " +
01937 "The left pane of the Dashboard " +
01938 "is a listing of all open Desktop Windows. If you click one of the buttons in the list, " +
01939 "the associated window " +
01940 "will be minimized or restored. If you hold down your click (for one second) you can choose " +
01941 "to minimize, maximize, or close the window!" +
01942 "</INDENT>" +
01943
01944
01945
01946 "\n\nRemember, if you would like to take a look at the available online documentation, " +
01947 "click the question mark at the top-right of the Desktop."
01948 );
01949 }
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967