16 if (typeof Debug ==
'undefined')
17 alert(
'ERROR: Debug is undefined! Must include Debug.js before DesktopIcons.js');
19 if (typeof SimpleContextMenu ==
'undefined')
20 Debug.log(
'ERROR: SimpleContextMenu is undefined! Must include SimpleContextMenu.js before DesktopIcons.js',Debug.HIGH_PRIORITY);
21 if (typeof MultiSelectBox ==
'undefined')
22 Debug.log(
'ERROR: MultiSelectBox is undefined! Must include MultiSelectBox.js before DesktopIcons.js',Debug.HIGH_PRIORITY);
23 if (typeof DesktopContent ==
'undefined')
24 Debug.log(
'ERROR: DesktopContent is undefined! Must include DesktopContent.js before DesktopIcons.js',Debug.HIGH_PRIORITY);
27 if (typeof Desktop ==
'undefined')
28 Debug.log(
'ERROR: Desktop is undefined! Must include Desktop.js before DesktopIcons.js',Debug.HIGH_PRIORITY);
37 Desktop.createIcons =
function(userPermissions, z) {
38 if(
false === (
this instanceof Desktop.createIcons)) {
41 return new Desktop.createIcons(userPermissions, z);
51 var _defaultIconsMargin = 50;
52 var _defaultIconWidth = 64;
53 var _defaultIconHeight = 64;
54 var _defaultIconTextWidth = 90;
55 var _defaultIconTextHeight = 24;
62 var _deepClickTimer = 0;
64 var _folders = [{},[]];
70 var _openFolderPath =
"";
71 var _openFolderElement;
73 var _iconNameToPathMap = {};
80 this.folders = _folders;
81 this.deepClickTimer = _deepClickTimer;
82 this.iconNameToPathMap = _iconNameToPathMap;
89 var _redrawIcons =
function() {
91 _iconsElement.style.left = Desktop.desktop.getDesktopContentX()+_defaultIconsMargin+
"px";
92 _iconsElement.style.top = Desktop.desktop.getDesktopContentY()+_defaultIconsMargin+
"px";
93 _iconsElement.style.width = Desktop.desktop.getDesktopContentWidth()-_defaultIconsMargin-_defaultIconsMargin+
"px";
94 _iconsElement.style.height = Desktop.desktop.getDesktopContentHeight()-_defaultIconsMargin-_defaultIconsMargin+
"px";
102 this.redrawIcons = _redrawIcons;
106 this.resetWithPermissions =
function(permissions, keepSamePermissions)
108 Debug.log(
"Desktop resetWithPermissions " + permissions +
109 ", " + keepSamePermissions,Debug.LOW_PRIORITY);
111 if(permissions === undefined && !keepSamePermissions)
113 else if(!keepSamePermissions)
114 _permissions = permissions;
118 if(!Desktop.isWizardMode())
120 Desktop.XMLHttpRequest(
"Request?RequestType=getDesktopIcons",
"",
126 Debug.log(
"OtsWizardConfiguration");
127 Desktop.XMLHttpRequest(
"requestIcons",
"sequence=" +
128 Desktop.desktop.security, iconRequestHandler);
129 if(!_permissions) _permissions = 1;
138 var iconRequestHandler =
function(req)
142 Desktop.desktop.icons.folders = [{},[]];
143 Desktop.desktop.icons.iconNameToPathMap = {} ;
145 _iconsElement.innerHTML =
"";
150 if(!Desktop.isWizardMode())
154 if((err = Desktop.getXMLValue(req,
"Error")) && err !=
"")
156 Debug.log(
"Error: " + err, Debug.HIGH_PRIORITY);
160 iconArray = Desktop.getXMLValue(req,
"iconList");
164 iconArray = iconArray.split(
",");
170 iconArray = req.responseText.split(
",");
173 Debug.log(
"icon Array split: " + iconArray);
205 var numberOfIconFields = 7;
206 for(var i=0;i<(iconArray.length);i+=numberOfIconFields)
208 if(_permissions >= iconArray[i+3])
209 Desktop.desktop.icons.addIcon(iconArray[i],iconArray[i+1],iconArray[i+5],iconArray[i+2]|0,iconArray[i+4],iconArray[i+6]);
218 this.addIcon =
function(subtext, altText, linkurl, uniqueWin, picfn, folderPath)
228 var i = linkurl.indexOf(
"urn:xdaq-application:lid=") + (
"urn:xdaq-application:lid=").length;
229 var isAllNumbers =
true;
230 for(i;i<linkurl.length;++i)
234 if(linkurl[i] <
"0" || linkurl[i] >
"9")
236 isAllNumbers =
false;
245 Debug.log(
"An error occurred while trying to parse the window url. " +
246 "The window path seems to be invalid: " + e, Debug.HIGH_PRIORITY);
250 this.iconNameToPathMap[subtext] = [linkurl,uniqueWin];
252 var iconContainer = document.createElement(
"div");
253 iconContainer.setAttribute(
"class",
"DesktopIcons-iconContainer");
265 var folderSplit = folderPath.split(
'/');
268 var folders = this.folders;
269 for(var i=0;i<folderSplit.length;++i)
271 if(folderSplit[i] ==
"")
continue;
273 if(folderPtr === undefined)
277 if(folderPtr[0][folderSplit[i]] === undefined)
280 folderPtr[0][folderSplit[i]] = [{},[]];
282 if(folderPtr == folders &&
283 rootFolderIndex === undefined)
284 rootFolderIndex = folderSplit[i];
287 folderPtr = folderPtr[0][folderSplit[i]];
291 if(folderPtr !== undefined)
293 Debug.log(
"folderPtr.length = " + folderPtr.length);
296 folderPtr[1].push([subtext, altText, linkurl, uniqueWin, picfn]);
297 console.log(folders);
301 if(rootFolderIndex !== undefined)
304 Debug.log(
"folderPath = " + folderPath);
305 Debug.log(
"rootFolderIndex = " + rootFolderIndex);
308 subtext = rootFolderIndex;
312 picfn =
"icon-Folder.png";
324 link = document.createElement(
"a");
325 link.setAttribute(
"class",
"DesktopIcons-iconLink");
326 link.title = subtext;
329 if(linkurl ==
"folder")
332 link.addEventListener(
"click",
function(e) {
334 e.clientX-
this.parentNode.parentNode.offsetLeft,
335 e.clientY-
this.parentNode.parentNode.offsetTop,
341 link.addEventListener(
"click",
function(e) {
342 Desktop.desktop.addWindow(subtext,
"",linkurl,uniqueWin);
346 div = document.createElement(
"div");
347 div.setAttribute(
"class",
"DesktopIcons-iconDiv");
348 div.style.width = _defaultIconWidth +
"px";
349 div.style.height = _defaultIconHeight +
"px";
350 div.style.marginLeft = (_defaultIconTextWidth-_defaultIconWidth-2)/2 +
"px";
353 if(picfn !=
"0" && picfn !=
"DEFAULT" && picfn !=
"")
356 div.style.backgroundImage =
"url(/WebPath/images/iconImages/" + picfn+
")";
358 div.style.backgroundImage =
"url(" + picfn+
")";
360 var div2 = document.createElement(
"div");
361 div2.setAttribute(
"class",
"DesktopIcons-iconDiv");
362 div2.style.width = _defaultIconWidth +
"px";
363 div2.style.height = _defaultIconHeight +
"px";
364 div2.style.marginLeft = (-1) +
"px";
365 div2.style.marginTop = (-1) +
"px";
366 div.appendChild(div2);
369 div.innerHTML =
"<table width='100%' height='100%'><td width='100%' height='100%' valign='middle' align='center'>"+
370 altText+
"</td></table>";
373 link.appendChild(div);
374 iconContainer.appendChild(link);
377 link = document.createElement(
"a");
378 link.setAttribute(
"class",
"DesktopIcons-iconLink");
379 link.title = subtext;
381 if(linkurl ==
"folder")
384 link.addEventListener(
"click",
function(e) {
386 e.clientX-
this.parentNode.parentNode.offsetLeft,
387 e.clientY-
this.parentNode.parentNode.offsetTop,
393 link.addEventListener(
"click",
function(e) {
394 Desktop.desktop.addWindow(subtext,
"",linkurl,uniqueWin);
399 div = document.createElement(
"div");
400 div.setAttribute(
"class",
"DesktopIcons-iconSubText");
401 div.style.width = _defaultIconTextWidth +
"px";
402 div.style.height = _defaultIconTextHeight +
"px";
403 div.innerHTML = subtext;
405 link.appendChild(div);
406 iconContainer.appendChild(link);
408 if(linkurl !=
"folder")
413 iconContainer.addEventListener(
"mouseup",
function(event) {
416 window.clearTimeout(_deepClickTimer);
421 var deepClickHandler =
function(event) {
422 event.cancelBubble =
true;
423 event.preventDefault();
424 _deepClickTimer = window.setTimeout(
function() {
426 Debug.log(
"Create Icon Menu");
428 "Open and Maximize Window",
429 "Open in New Browser Tab",
430 "Open and Tile All Windows"
432 var menuItemHandlers = [
433 "Desktop.desktop.addWindow(\""+ subtext +
"\",\"" +
""
434 +
"\",\"" + linkurl +
"\","+uniqueWin+
",2);",
435 "Desktop.openNewBrowserTab(\""+ subtext +
"\",\"" +
""
436 +
"\",\"" + linkurl +
"\","+uniqueWin+
");",
437 "Desktop.desktop.addWindow(\""+ subtext +
"\",\"" +
""
438 +
"\",\"" + linkurl +
"\","+uniqueWin+
",1);",
440 Debug.log(
"createEditTableMenu()");
441 SimpleContextMenu.createMenu(
444 "DesktopIconContextMenu",
445 event.pageX-1,event.pageY-1,
446 Desktop.desktop.dashboard.getDefaultDashboardColor(),
461 iconContainer.addEventListener(
"mousedown", deepClickHandler);
464 _iconsElement.appendChild(iconContainer);
473 while((cdArr = _iconsElement.getElementsByClassName(
"iconsClearDiv")) &&
475 cdArr[0].parentNode.removeChild(cdArr[0]);
478 var newLine = Math.ceil((-1 + Math.sqrt(_numOfIcons*8+1))/2);
479 var newLineOff = newLine;
481 var currChild = _iconsElement.childNodes[0];
482 for(var i=0;i<_numOfIcons;++i) {
484 div = document.createElement(
"div");
485 div.setAttribute(
"id",
"clearDiv");
486 div.setAttribute(
"class",
"iconsClearDiv");
487 _iconsElement.insertBefore(div,currChild);
488 newLine += --newLineOff;
490 currChild = currChild.nextSibling;
502 this.openFolder =
function(x,y,folderName) {
506 var div = document.createElement(
"div");
507 div.setAttribute(
"class",
"DesktopIcons-folderDiv");
508 div.style.padding =
"0 5px 5px 12px";
509 div.style.backgroundColor = DesktopContent.getDefaultWindowColor();
510 div.style.position =
"absolute";
511 div.style.width = (300) +
"px";
512 div.style.left = (x) +
"px";
513 div.style.top = (y) +
"px";
515 div.onmouseup =
function(event) {
event.stopPropagation();};
516 this.iconsElement.appendChild(div);
517 _openFolderElement = div;
519 div = document.createElement(
"div");
521 div.style.height = 250 +
"px";
522 div.style.position =
"relative";
523 _openFolderElement.appendChild(div);
524 _openFolderElement = div;
526 this.openSubFolder(folderName);
532 this.openSubFolder =
function(folderName) {
537 if(folderName.indexOf(
"../") >= 0)
539 var folderSplit = _openFolderPath.split(
'/');
542 for(var i=0;i<folderSplit.length;++i)
543 if(folderSplit[i] !=
"") ++fullDepth;
544 var backPathCount = 1;
545 while(folderName.indexOf(
"../",backPathCount*3) >= 0) ++backPathCount;
547 Debug.log(
"fullDepth " + fullDepth);
548 Debug.log(
"backPathCount " + backPathCount);
550 fullDepth -= backPathCount;
551 _openFolderPtr = this.folders;
552 _openFolderPath =
"/";
554 for(var i=0,backPathCount=0;backPathCount<fullDepth && i<folderSplit.length;++i)
555 if(folderSplit[i] !=
"")
557 _openFolderPtr = _openFolderPtr[0][folderSplit[i]];
558 _openFolderPath += folderSplit[i] +
"/";
562 Debug.log(
"_openFolderPath " + _openFolderPath);
563 Debug.log(
"folderName " + folderName);
565 else if(folderName !=
".")
567 _openFolderPath +=
"/" + folderName;
569 _openFolderPtr = _openFolderPtr[0][folderName];
571 _openFolderPtr = this.folders[0][folderName];
574 Debug.log(
"_openFolderPath = " + _openFolderPath);
575 console.log(_openFolderPtr);
577 if(!_openFolderPtr) {Debug.log(
"Should never happen??!");
return;}
580 var noMultiSelect =
true;
581 var maintainPreviousSelections =
false;
593 var subfolders = Object.keys(_openFolderPtr[0]);
594 for(var i=0;i<subfolders.length;++i)
596 vals.push(subfolders[i]);
597 types.push(
"folder");
600 imgURLs.push(
"/WebPath/images/iconImages/" +
605 for(var i=0;i<_openFolderPtr[1].length;++i)
607 vals.push(_openFolderPtr[1][i][0]);
611 if(_openFolderPtr[1][i][4] !=
"0" &&
612 _openFolderPtr[1][i][4] !=
"DEFAULT" &&
613 _openFolderPtr[1][i][4] !=
"")
616 if(_openFolderPtr[1][i][4][0] !=
'/')
617 imgURLs.push(
"/WebPath/images/iconImages/" +
618 _openFolderPtr[1][i][4]);
620 imgURLs.push(_openFolderPtr[1][i][4]);
623 imgURLs.push(
"=" + _openFolderPtr[1][i][1]);
628 var pathSplit = _openFolderPath.split(
"/");
635 for(var i=0;i<pathSplit.length;++i)
636 if(pathSplit[i] !=
"") ++folderDepth;
637 Debug.log(
"folderDepth " + folderDepth);
639 var subfolderCount = 0;
640 for(var i=0;i<pathSplit.length;++i)
642 if(pathSplit[i] ==
"")
continue;
645 for(var j=0;j<folderDepth-i;++j)
647 if(navPath ==
"") navPath =
".";
650 Debug.log(
"navPath " + navPath);
654 str +=
"<a href='#' onclick='Desktop.desktop.icons.openSubFolder(\"" +
656 pathSplit[i] +
"</a>/";
663 MultiSelectBox.createSelectBox(_openFolderElement,
664 "DesktopFolderMultiSelectBox",
667 "Desktop.desktop.icons.clickFolderContents",
668 noMultiSelect,0,imgURLs,
669 "Desktop.desktop.icons.mouseDownFolderContents",
670 "Desktop.desktop.icons.mouseUpFolderContents");
671 MultiSelectBox.initMySelectBoxes(!maintainPreviousSelections);
676 this.closeFolder =
function() {
680 if(_openFolderElement)
681 _openFolderElement.parentNode.parentNode.removeChild(_openFolderElement.parentNode);
685 Debug.log(
"Ignoring close folder error: " + e);
687 _openFolderElement = 0;
688 _openFolderPath =
"";
689 _openFolderPtr = undefined;
694 this.clickFolderContents =
function(el) {
696 var i = MultiSelectBox.getSelectedIndex(el);
697 var selArr = MultiSelectBox.getSelectionArray(el);
698 var val = el.textContent;
699 var type = el.getAttribute(
"type-value");
700 var key = el.getAttribute(
"key-value")|0;
703 MultiSelectBox.dbg(
"Chosen element index:",i,
712 var target = _openFolderPtr[1][key];
714 Desktop.desktop.addWindow(target[0],
"",target[2],target[3]);
718 this.openSubFolder(val);
724 this.mouseUpFolderContents =
function(el,event) {
725 if(this.deepClickTimer)
727 window.clearTimeout(this.deepClickTimer);
728 this.deepClickTimer = 0;
736 this.mouseDownFolderContents =
function(el,event) {
737 var i = MultiSelectBox.getSelectedIndex(el);
738 var selArr = MultiSelectBox.getSelectionArray(el);
739 var val = el.textContent;
740 var type = el.getAttribute(
"type-value");
741 var key = el.getAttribute(
"key-value")|0;
743 MultiSelectBox.dbg(
"mouseDownFolderContents Chosen element index:",i,
748 if(type !=
"icon")
return;
752 var target = _openFolderPtr[1][key];
760 event.cancelBubble =
true;
761 event.preventDefault();
762 this.deepClickTimer = window.setTimeout(
function() {
764 Debug.log(
"Create Icon Menu");
766 "Open and Maximize Window",
767 "Open in New Browser Tab",
768 "Open and Tile All Windows"
770 var menuItemHandlers = [
771 "Desktop.desktop.addWindow(\""+ target[0] +
"\",\"" +
""
772 +
"\",\"" + target[2] +
"\","+target[3]+
",2);",
773 "Desktop.openNewBrowserTab(\""+ target[0] +
"\",\"" +
""
774 +
"\",\"" + target[2] +
"\","+target[3]+
");",
775 "Desktop.desktop.addWindow(\""+ target[0] +
"\",\"" +
""
776 +
"\",\"" + target[2] +
"\","+target[3]+
",1);",
778 Debug.log(
"createEditTableMenu()");
779 SimpleContextMenu.createMenu(
782 "DesktopIconContextMenu",
783 event.pageX-1,event.pageY-1,
784 Desktop.desktop.dashboard.getDefaultDashboardColor(),
796 this.iconsElement = _iconsElement = document.createElement(
"div");
797 this.iconsElement.setAttribute(
"class",
"DesktopIcons");
798 this.iconsElement.setAttribute(
"id",
"DesktopIcons");
799 this.iconsElement.style.position =
"absolute";
800 this.iconsElement.style.zIndex = z;
804 Debug.log(
"Desktop Icons created",Debug.LOW_PRIORITY);