otsdaq_utilities  v2_04_01
DesktopIcons.js
1 //=====================================================================================
2 //
3 // Created Mar, 2013
4 // by Ryan Rivera ((rrivera at fnal.gov))
5 //
6 // DesktopIcons.js
7 //
8 // This is the desktop code for the user interface for ots. ots is the DAQ
9 // and control software for the Fermi Strips Telescope.
10 //
11 // The desktop consists of icons to launch windows
12 //
13 //=====================================================================================
14 
15 
16 if (typeof Debug == 'undefined')
17  alert('ERROR: Debug is undefined! Must include Debug.js before DesktopIcons.js');
18 
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') //used for folders
22  Debug.log('ERROR: MultiSelectBox is undefined! Must include MultiSelectBox.js before DesktopIcons.js',Debug.HIGH_PRIORITY);
23 if (typeof DesktopContent == 'undefined') //used for getting solid window color for folders
24  Debug.log('ERROR: DesktopContent is undefined! Must include DesktopContent.js before DesktopIcons.js',Debug.HIGH_PRIORITY);
25 
26 
27 if (typeof Desktop == 'undefined')
28  Debug.log('ERROR: Desktop is undefined! Must include Desktop.js before DesktopIcons.js',Debug.HIGH_PRIORITY);
29 else {
30 
31 
34  //define Desktop.createIcons to return dashboard class
37  Desktop.createIcons = function(userPermissions, z) {
38  if(false === (this instanceof Desktop.createIcons)) {
39  //here to correct if called as "var v = Desktop.createIcons();"
40  // instead of "var v = new Desktop.createIcons();"
41  return new Desktop.createIcons(userPermissions, z);
42  }
43 
44 
45  //------------------------------------------------------------------
46  //create private members variables ----------------------
47  //------------------------------------------------------------------
48 
49  //all units in pixels unless otherwise specified
50 
51  var _defaultIconsMargin = 50; //margin to desktop border for all icons
52  var _defaultIconWidth = 64;
53  var _defaultIconHeight = 64;
54  var _defaultIconTextWidth = 90;
55  var _defaultIconTextHeight = 32;
56  var _permissions = 0;
57 
58  var _iconsElement;
59 
60  var _numOfIcons = 0;
61 
62  var _deepClickTimer = 0;
63 
64  var _folders = [{},[]]; // a folder is a an Object of subfolders and an array of icons
65  // It has an array of icon objects (in case icon names are not unique,
66  // the array index makes them unique).
67  // Subfolder names must be unique.
68  var _openFolderPtr; // always points to the currently open folder within the _folders object
69  // so that subfolders can easily navigate
70  var _openFolderPath = "";
71  var _openFolderElement;
72 
73  var _iconNameToPathMap = {/* "name": [path,unique] */}; //used to open icons programatically
74 
75 
76  //------------------------------------------------------------------
77  //create public members variables ----------------------
78  //------------------------------------------------------------------
79  this.iconsElement;
80  this.folders = _folders;
81  this.deepClickTimer = _deepClickTimer;
82  this.iconNameToPathMap = _iconNameToPathMap;
83 
84 
85  //------------------------------------------------------------------
86  //create PRIVATE members functions ----------------------
87  //------------------------------------------------------------------
88 
89  var _redrawIcons = function() {
90 
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";
95 
96  }
97 
98  //------------------------------------------------------------------
99  //create PUBLIC members functions ----------------------
100  //------------------------------------------------------------------
101 
102  this.redrawIcons = _redrawIcons;
103 
104  // this.resetWithPermissions ~~
105  this.resetWithPermissions = function(permissions) {
106  Debug.log("Desktop resetWithPermissions " + permissions,Debug.LOW_PRIORITY);
107 
108  _permissions = permissions;
110 
111 
112  if(!Desktop.isWizardMode())
113  { //This is satisfied for Digest Access Authorization and No Security on OTS
114  Desktop.XMLHttpRequest("Request?RequestType=getDesktopIcons", "",
115  iconRequestHandler);
116  return;
117  }
118  else //it is the sequence for OtsWizardConfiguration
119  {
120  Debug.log("OtsWizardConfiguration");
121  Desktop.XMLHttpRequest("requestIcons", "sequence=" +
122  Desktop.desktop.security, iconRequestHandler);
123  if(!_permissions) _permissions = 1;
124  return;
125  }
126 
127  }
128 
129  //_iconRequestHandler
130  //adds the icons from the hardcoded, C++ in OtsConfigurationWizard
131  var iconRequestHandler = function(req) {
132 
133  //clear folder object
134  Desktop.desktop.icons.folders = [{},[]];
135  Desktop.desktop.icons.iconNameToPathMap = {} ; //clear map
136 
137  _iconsElement.innerHTML = ""; //clear existing icons
138  _numOfIcons = 0;
139 
140  var iconArray;
141 
142  if(!Desktop.isWizardMode())
143  { //This is satisfied for Digest Access Authorization and No Security on OTS
144 
145  var err;
146  if((err = Desktop.getXMLValue(req,"Error")) && err != "")
147  {
148  Debug.log("Error: " + err, Debug.HIGH_PRIORITY);
149  return;
150  }
151 
152  iconArray = Desktop.getXMLValue(req,"iconList");
153  //Debug.log("icon Array unsplit: " + iconArray);
154  iconArray = iconArray.split(",");
155  }
156  else //it is the wizard
157  {
158  iconArray = req.responseText.split(",");
159  }
160 
161  Debug.log("icon Array split: " + iconArray);
162  //Debug.log(_permissions);
163 
164  //an icon is 7 fields.. give comma-separated
165  //0 - subtext = text below icon
166  //1 - altText = text icon if no image given
167  //2 - uniqueWin = if true, only one window is allowed, else multiple instances of window
168  //3 - permissions = security level needed to see icon
169  //4 - picfn = icon image filename
170  //5 - linkurl = url of the window to open
171  //6 - folderPath = folder and subfolder location '/' separated
172 
173  // //debugging
174  // var depth = 10;
175  // var breadth = 20;
176  // var folder = "";
177  // for(var i=0;i<depth;++i)
178  // {
179  // folder += "/folder-" +i;
180  // for(var j=0;j<breadth;++j)
181  // Desktop.desktop.icons.addIcon("title-"+i + "-"+j,
182  // "alt",
183  // iconArray[j%4*7+5],
184  // 1,
185  // "0",//iconArray[j%4*7+4],
186  // folder);
187  // }
188  // Desktop.desktop.icons.openFolder(100,100,"folder-0");
189  // return;
190 
191 
192 
193  var numberOfIconFields = 7;
194  for(var i=0;i<(iconArray.length);i+=numberOfIconFields) //add icons
195  {
196  if(_permissions >= iconArray[i+3])
197  Desktop.desktop.icons.addIcon(iconArray[i],iconArray[i+1],iconArray[i+5],iconArray[i+2]|0,iconArray[i+4],iconArray[i+6]);
198  }
199 
200 
201  }
202 
203  // this.addIcon ~~
204  // adds an icon subtext wording underneath and image icon (if picfn defined, else alt text icon)
205  this.addIcon = function(subtext, altText, linkurl, uniqueWin, picfn, folderPath) {
206 
207  //Debug.log("this.addIcon");
208 
209  //same as in DesktopContent.openNewBrowserTab
210  //for linkurl, need to check lid=## is terminated with /
211  // check from = that there is nothing but numbers
212  try
213  {
214  var i = linkurl.indexOf("urn:xdaq-application:lid=") + ("urn:xdaq-application:lid=").length;
215  var isAllNumbers = true;
216  for(i;i<linkurl.length;++i)
217  {
218  //Debug.log(linkurl[i]);
219 
220  if(linkurl[i] < "0" || linkurl[i] > "9")
221  {
222  isAllNumbers = false;
223  break;
224  }
225  }
226  if(isAllNumbers)
227  linkurl += "/";
228  }
229  catch(e)
230  {
231  Debug.log("An error occurred while trying to parse the window url. " +
232  "The window path seems to be invalid: " + e, Debug.HIGH_PRIORITY);
233  return;
234  }
235 
236  this.iconNameToPathMap[subtext] = [linkurl,uniqueWin];
237 
238  var iconContainer = document.createElement("div");
239  iconContainer.setAttribute("class", "DesktopIcons-iconContainer");
240 
241  var link;
242  var div;
243 
244 
245  //if folder path is non-empty,
246  // create the full folder structure in the _folders object
247  // and show the top level folder icon (if new to _folders object)
248  //else
249  // just show icon
250 
251  var folderSplit = folderPath.split('/'); //root folder is first non empty index
252  var rootFolderIndex;
253  var folderPtr;
254  var folders = this.folders;
255  for(var i=0;i<folderSplit.length;++i)
256  {
257  if(folderSplit[i] == "") continue;
258 
259  if(folderPtr === undefined)
260  folderPtr = folders; //init to root folder first time
261 
262  //check if folder exists (this is root or subfolder level)
263  if(folderPtr[0][folderSplit[i]] === undefined)
264  {
265  //need to create folder object
266  folderPtr[0][folderSplit[i]] = [{},[]]; // a folder is a an Object of subfolders and an array of icons
267 
268  if(folderPtr == folders &&
269  rootFolderIndex === undefined) //found new root icon
270  rootFolderIndex = folderSplit[i]; //need to display icon on desktop
271  }
272 
273  folderPtr = folderPtr[0][folderSplit[i]];
274  }
275 
276  //if folderPath, add icon to structure at folderPtr
277  if(folderPtr !== undefined)
278  {
279  Debug.log("folderPtr.length = " + folderPtr.length);
280 
281  //push new icon object
282  folderPtr[1].push([subtext, altText, linkurl, uniqueWin, picfn]);
283  console.log(folders);
284 
285  //check if this is first icon encountered in this root folder
286  // if so, need to display on desktop
287  if(rootFolderIndex !== undefined)
288  {
289  //there is a new folder to be displayed on desktop
290  Debug.log("folderPath = " + folderPath);
291  Debug.log("rootFolderIndex = " + rootFolderIndex);
292 
293  //add the folder icon to desktop
294  subtext = rootFolderIndex;
295  altText = "F";
296  linkurl = "folder";
297  uniqueWin = 1;
298  picfn = "icon-Folder.png";
299  }
300  else //this icon is in a folder, and the root folder is already displayed
301  return;
302  }
303 
304 
305 
306  //var jsCmd = "Javascript:var newWin = Desktop.desktop.addWindow(\""+ subtext + "\",\"" + ""
307  // + "\",\"" + linkurl + "\","+uniqueWin+");";
308 
309  //create icon square
310  link = document.createElement("a");
311  link.setAttribute("class", "DesktopIcons-iconLink");
312  link.title = subtext;
313  //link.href = "#";//jsCmd;
314 
315  if(linkurl == "folder")
316  {
317  var iconsObj = this;
318  link.addEventListener("click", function(e) {
319  iconsObj.openFolder(
320  e.clientX-this.parentNode.parentNode.offsetLeft,
321  e.clientY-this.parentNode.parentNode.offsetTop,
322  subtext);
323  }, false);
324  }
325  else
326  {
327  link.addEventListener("click", function(e) {
328  Desktop.desktop.addWindow(subtext,"",linkurl,uniqueWin);
329  }, false);
330  }
331 
332  div = document.createElement("div");
333  div.setAttribute("class", "DesktopIcons-iconDiv");
334  div.style.width = _defaultIconWidth + "px";
335  div.style.height = _defaultIconHeight + "px";
336  div.style.marginLeft = (_defaultIconTextWidth-_defaultIconWidth-2)/2 + "px"; //extra 2 for border
337 
338  //define icon content
339  if(picfn != "0" && picfn != "DEFAULT" && picfn != "")
340  { //if icon image
341  if(picfn[0] != '/')
342  div.style.backgroundImage = "url(/WebPath/images/iconImages/" + picfn+")";
343  else
344  div.style.backgroundImage = "url(" + picfn+")";
345 
346  var div2 = document.createElement("div");
347  div2.setAttribute("class", "DesktopIcons-iconDiv");
348  div2.style.width = _defaultIconWidth + "px";
349  div2.style.height = _defaultIconHeight + "px";
350  div2.style.marginLeft = (-1) + "px"; //put effect over top of background image and line up with border
351  div2.style.marginTop = (-1) + "px";
352  div.appendChild(div2);
353  }
354  else { //if text only icon, gets effect from .css
355  div.innerHTML = "<table width='100%' height='100%'><td width='100%' height='100%' valign='middle' align='center'>"+
356  altText+"</td></table>";
357  }
358 
359  link.appendChild(div);
360  iconContainer.appendChild(link); //add square to icon container
361 
362  //create icon sub text
363  link = document.createElement("a");
364  link.setAttribute("class", "DesktopIcons-iconLink");
365  link.title = subtext;
366  //link.href = "#";////link.href = jsCmd;
367  if(linkurl == "folder")
368  {
369  var iconsObj = this;
370  link.addEventListener("click", function(e) {
371  iconsObj.openFolder(
372  e.clientX-this.parentNode.parentNode.offsetLeft,
373  e.clientY-this.parentNode.parentNode.offsetTop,
374  subtext);
375  }, false);
376  }
377  else
378  {
379  link.addEventListener("click", function(e) {
380  Desktop.desktop.addWindow(subtext,"",linkurl,uniqueWin);
381  }, false);
382  }
383 
384 
385  div = document.createElement("div");
386  div.setAttribute("class", "DesktopIcons-iconSubText");
387  div.style.width = _defaultIconTextWidth + "px";
388  div.style.height = _defaultIconTextHeight + "px";
389  div.innerHTML = subtext;
390 
391  link.appendChild(div);
392  iconContainer.appendChild(link); //add subtext to icon container
393 
394  if(linkurl != "folder") //if not folder, add context click menu handlers
395  {
396  //add context click menu handlers
397  // mouseup and contextMenu to stop default right-click behavior
398  // and mousedown to start the menu (so "deep clicks" work)
399  iconContainer.addEventListener("mouseup", function(event) {
400  if(_deepClickTimer)
401  {
402  window.clearTimeout(_deepClickTimer);
403  _deepClickTimer = 0;
404  }
405  }); //end onmouseup event
406 
407  var deepClickHandler = function(event) {
408  event.cancelBubble = true; //prevent default behavior
409  event.preventDefault();
410  _deepClickTimer = window.setTimeout(function() {
411 
412  Debug.log("Create Icon Menu");
413  var menuItems = [
414  "Open and Maximize Window",
415  "Open in New Browser Tab",
416  "Open and Tile All Windows"
417  ];
418  var menuItemHandlers = [
419  "Desktop.desktop.addWindow(\""+ subtext + "\",\"" + ""
420  + "\",\"" + linkurl + "\","+uniqueWin+",2);", // 2 for maximize
421  "Desktop.openNewBrowserTab(\""+ subtext + "\",\"" + ""
422  + "\",\"" + linkurl + "\","+uniqueWin+");", // 2 for maximize
423  "Desktop.desktop.addWindow(\""+ subtext + "\",\"" + ""
424  + "\",\"" + linkurl + "\","+uniqueWin+",1);", // 1 for tile
425  ];
426  Debug.log("createEditTableMenu()");
427  SimpleContextMenu.createMenu(
428  menuItems,
429  menuItemHandlers,
430  "DesktopIconContextMenu", //element ID
431  event.pageX-1,event.pageY-1, //top left position
432  Desktop.desktop.dashboard.getDefaultDashboardColor(), //primary color
433  "white" //secondary color
434  );
435 
436  },500); //end timeout handler
437 
438  }; //end deepClickHandler event
439 
440  //FIXME ... debug touchstart on android to block browser context
441  // iconContainer.addEventListener("touchstart", function(event) {
442  // event.preventDefault();
443  //
444  // deepClickHandler(event);
445  // return false;
446  // });
447  iconContainer.addEventListener("mousedown", deepClickHandler);
448  }
449 
450  _iconsElement.appendChild(iconContainer); //add to desktop icon element
451 
452  ++_numOfIcons; //maintain icon count
453 
454  //reset icon arrangement based on _numOfIcons
455  if(_numOfIcons > 1) {
456  var cdArr = _iconsElement.getElementsByClassName("iconsClearDiv");
457 
458  while(cdArr.length) cdArr[0].parentNode.removeChild(cdArr[0]); //get rid of all clearDivs
459 
460  var newLine = Math.ceil((-1 + Math.sqrt(_numOfIcons*8+1))/2);
461  var newLineOff = newLine;
462 
463  var currChild = _iconsElement.childNodes[0];
464  for(var i=0;i<_numOfIcons;++i) {
465  if(i == newLine) { //add new line before currChild
466  div = document.createElement("div");
467  div.setAttribute("id", "clearDiv");
468  div.setAttribute("class", "iconsClearDiv");
469  _iconsElement.insertBefore(div,currChild);
470  newLine += --newLineOff; //update new line index
471  }
472  currChild = currChild.nextSibling; //get next child
473  }
474  }
475  }
476 
477  //this.openFolder ~~
478  // this version is called from desktop icons
479  // it opens up the div content at a position
480  // while openSubFolder is called by subfolder icons
481  // it navigates to the next level folder
482  // after the div is displayed openFolder makes use of openSubFolder.
483  this.openFolder = function(x,y,folderName) {
484 
485  this.closeFolder(); //close any open folders
486 
487  var div = document.createElement("div");
488  div.setAttribute("class", "DesktopIcons-folderDiv");
489  div.style.padding = "0 5px 5px 12px";
490  div.style.backgroundColor = DesktopContent.getDefaultWindowColor();//Desktop.desktop.defaultWindowFrameColor;
491  div.style.position = "absolute";
492  div.style.width = (300) + "px";
493  div.style.left = (x) + "px";
494  div.style.top = (y) + "px";
495  //each mouse up events.. because mouseup on desktop closes folder
496  div.onmouseup = function(event) {event.stopPropagation();};
497  this.iconsElement.appendChild(div);
498  _openFolderElement = div;
499 
500  div = document.createElement("div");
501  //div.style.width = 300 + "px";
502  div.style.height = 250 + "px";
503  div.style.position = "relative";
504  _openFolderElement.appendChild(div);
505  _openFolderElement = div;
506 
507  this.openSubFolder(folderName);
508  }
509 
510  //this.openSubFolder ~~
511  // folderArray is a list of folder and icon objects
512  this.openSubFolder = function(folderName) {
513 
514  //handle dot dots "../" to go back in path
515  // manipulate _openFolderPath, _openFolderPtr, and folderName
516 
517  if(folderName.indexOf("../") >= 0)
518  {
519  var folderSplit = _openFolderPath.split('/');
520  var fullDepth = 0;
521  //get depth
522  for(var i=0;i<folderSplit.length;++i)
523  if(folderSplit[i] != "") ++fullDepth;
524  var backPathCount = 1;
525  while(folderName.indexOf("../",backPathCount*3) >= 0) ++backPathCount;
526 
527  Debug.log("fullDepth " + fullDepth);
528  Debug.log("backPathCount " + backPathCount);
529 
530  fullDepth -= backPathCount; //new depth
531  _openFolderPtr = this.folders; //reset folder Ptr
532  _openFolderPath = "/"; //reset folder path
533  //repurpose backPathCount to count aggregate depth
534  for(var i=0,backPathCount=0;backPathCount<fullDepth && i<folderSplit.length;++i)
535  if(folderSplit[i] != "")
536  {
537  _openFolderPtr = _openFolderPtr[0][folderSplit[i]];
538  _openFolderPath += folderSplit[i] + "/";
539  ++backPathCount;
540  }
541 
542  Debug.log("_openFolderPath " + _openFolderPath);
543  Debug.log("folderName " + folderName);
544  }
545  else if(folderName != ".") //normal subfolder handling (if not "stay here")
546  {
547  _openFolderPath += "/" + folderName;
548  if(_openFolderPtr)
549  _openFolderPtr = _openFolderPtr[0][folderName];
550  else
551  _openFolderPtr = this.folders[0][folderName];
552  }
553 
554  Debug.log("_openFolderPath = " + _openFolderPath);
555  console.log(_openFolderPtr);
556 
557  if(!_openFolderPtr) {Debug.log("Should never happen??!"); return;}//throw("What");
558  //if(!_openFolderPtr) this.resetWithPermissions = function(_permissions);
559 
560  var noMultiSelect = true; // true or false (false for multiselect functionality)
561  var maintainPreviousSelections = false; //true or false (true means redraw select box using the js array selects left over from the last time this box was drawn using the same element id)
562 
563 
564  var vals = [];//["One little piggy","two little piggies","three little piggies","one","two","three"];
565  var keys = [];//["one","two","three","one","two","three"];
566  var types = [];//["number","numbers","numbers","one","two","three"];
567  var imgURLs = [];
568 
569 
570  //show folders first, then icons
571 
572  //subfolders
573  var subfolders = Object.keys(_openFolderPtr[0]);
574  for(var i=0;i<subfolders.length;++i)
575  {
576  vals.push(subfolders[i]);
577  types.push("folder");
578  keys.push(i);
579  imgURLs.push("/WebPath/images/iconImages/" +
580  "icon-Folder.png");
581  }
582  //then icons
583  //Icon object array (0-subtext, 1-altText, 2-linkurl, 3-uniqueWin, 4-picfn)
584  for(var i=0;i<_openFolderPtr[1].length;++i)
585  {
586  vals.push(_openFolderPtr[1][i][0]);
587  types.push("icon");
588  keys.push(i);
589 
590  if(_openFolderPtr[1][i][4] != "0" &&
591  _openFolderPtr[1][i][4] != "DEFAULT" &&
592  _openFolderPtr[1][i][4] != "") //if icon image
593  {
594  imgURLs.push("/WebPath/images/iconImages/" +
595  _openFolderPtr[1][i][4]);
596  }
597  else
598  imgURLs.push("=" + _openFolderPtr[1][i][1]);
599  }
600 
601  //make link title
602  var str = "";
603  var pathSplit = _openFolderPath.split("/");
604 
605  str += "/";
606  var navPath;
607 
608  //count depth first
609  var folderDepth = 0;
610  for(var i=0;i<pathSplit.length;++i)
611  if(pathSplit[i] != "") ++folderDepth;
612  Debug.log("folderDepth " + folderDepth);
613 
614  var subfolderCount = 0;
615  for(var i=0;i<pathSplit.length;++i)
616  {
617  if(pathSplit[i] == "") continue; //skip empty
618 
619  navPath = "";
620  for(var j=0;j<folderDepth-i;++j)
621  navPath += "../";
622  if(navPath == "") navPath = "."; //already here
623 
624 
625  Debug.log("navPath " + navPath);
626  ++subfolderCount;
627 
628  //need to do .. .. depending on depth
629  str += "<a href='#' onclick='Desktop.desktop.icons.openSubFolder(\"" +
630  navPath + "\");'>" +
631  pathSplit[i] + "</a>/";
632  Debug.log(str);
633 
634  }
635 
636  //write to a particular div
637  //var el1 = document.getElementById('box1Div');
638  MultiSelectBox.createSelectBox(_openFolderElement,
639  "DesktopFolderMultiSelectBox",
640  str,
641  vals,keys,types,
642  "Desktop.desktop.icons.clickFolderContents",
643  noMultiSelect,0,imgURLs,
644  "Desktop.desktop.icons.mouseDownFolderContents",
645  "Desktop.desktop.icons.mouseUpFolderContents");
646  MultiSelectBox.initMySelectBoxes(!maintainPreviousSelections);
647  }
648 
649  //this.closeFolder ~~
650  this.closeFolder = function() {
651  //Debug.log("Close folder");
652  try
653  {
654  if(_openFolderElement)
655  _openFolderElement.parentNode.parentNode.removeChild(_openFolderElement.parentNode);
656  }
657  catch(e)
658  {
659  Debug.log("Ignoring close folder error: " + e);
660  }
661  _openFolderElement = 0;
662  _openFolderPath = ""; //clear
663  _openFolderPtr = undefined; //clear
664  }
665 
666  //this.clickFolderContents ~~
667  this.clickFolderContents = function(el) {
668 
669  var i = MultiSelectBox.getSelectedIndex(el);
670  var selArr = MultiSelectBox.getSelectionArray(el);
671  var val = el.textContent;
672  var type = el.getAttribute("type-value");
673  var key = el.getAttribute("key-value")|0;
674 
675 
676  MultiSelectBox.dbg("Chosen element index:",i,
677  " value:",val,
678  " key:",key,
679  " type:",type);
680 
681 
682 
683  if(type == "icon")
684  {
685  var target = _openFolderPtr[1][key];
686  //Icon object array (0-subtext, 1-altText, 2-linkurl, 3-uniqueWin, 4-picfn)
687  Desktop.desktop.addWindow(target[0],"",target[2],target[3]);
688  //this.closeFolder();
689  }
690  else
691  this.openSubFolder(val);
692  }
693 
694  //this.mouseUpFolderContents ~~
695  // this functionality should mirror addIcon()
696  this.mouseUpFolderContents = function(el,event) {
697  if(this.deepClickTimer)
698  {
699  window.clearTimeout(this.deepClickTimer);
700  this.deepClickTimer = 0;
701  }
702  }
703 
704  //this.mouseDownFolderContents ~~
705  // this functionality should mirror local function
706  // deepClickHandler() in addIcon()
707  this.mouseDownFolderContents = function(el,event) {
708  var i = MultiSelectBox.getSelectedIndex(el);
709  var selArr = MultiSelectBox.getSelectionArray(el);
710  var val = el.textContent;
711  var type = el.getAttribute("type-value");
712  var key = el.getAttribute("key-value")|0;
713 
714  MultiSelectBox.dbg("mouseDownFolderContents Chosen element index:",i,
715  " value:",val,
716  " key:",key,
717  " type:",type);
718 
719  if(type != "icon") return;
720 
721  //only deep click functionality for icons
722 
723  var target = _openFolderPtr[1][key];
724  //Icon object array (0-subtext, 1-altText, 2-linkurl, 3-uniqueWin, 4-picfn)
725 
726 
727  //========================
728  // this functionality should mirror local function
729  // deepClickHandler() in addIcon()
730 
731  event.cancelBubble = true; //prevent default behavior
732  event.preventDefault();
733  this.deepClickTimer = window.setTimeout(function() {
734 
735  Debug.log("Create Icon Menu");
736  var menuItems = [
737  "Open and Maximize Window",
738  "Open in New Browser Tab",
739  "Open and Tile All Windows"
740  ];
741  var menuItemHandlers = [
742  "Desktop.desktop.addWindow(\""+ target[0] + "\",\"" + ""
743  + "\",\"" + target[2] + "\","+target[3]+",2);", // 2 for maximize
744  "Desktop.openNewBrowserTab(\""+ target[0] + "\",\"" + ""
745  + "\",\"" + target[2] + "\","+target[3]+");", // 2 for maximize
746  "Desktop.desktop.addWindow(\""+ target[0] + "\",\"" + ""
747  + "\",\"" + target[2] + "\","+target[3]+",1);", // 1 for tile
748  ];
749  Debug.log("createEditTableMenu()");
750  SimpleContextMenu.createMenu(
751  menuItems,
752  menuItemHandlers,
753  "DesktopIconContextMenu", //element ID
754  event.pageX-1,event.pageY-1, //top left position
755  Desktop.desktop.dashboard.getDefaultDashboardColor(), //primary color
756  "white" //secondary color
757  );
758 
759  },500); //end timeout handler
760 
761  }
762 
763  //------------------------------------------------------------------
764  //handle class construction ----------------------
765  //------------------------------------------------------------------
766 
767  this.iconsElement = _iconsElement = document.createElement("div");
768  this.iconsElement.setAttribute("class", "DesktopIcons");
769  this.iconsElement.setAttribute("id", "DesktopIcons");
770  this.iconsElement.style.position = "absolute";
771  this.iconsElement.style.zIndex = z;
772 
773 
774 
775  Debug.log("Desktop Icons created",Debug.LOW_PRIORITY);
776  }
777 
778 }
779 
780 
781 
782 
783 
784 
785 
786 
787 
788