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