7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2013 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Tree = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var tree = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
tree.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
31 |
{ |
7604 |
25 Feb 19 |
nicklas |
IconStore.addDefaultIcons(); |
7604 |
25 Feb 19 |
nicklas |
33 |
|
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('ExtensionPoint', 'extensionpoint.png', 'extensionpoint-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('ExtensionPointDisabled', 'extensionpoint-disabled.png', 'extensionpoint-disabled-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('ExtensionPointError', 'extensionpoint-error.png', 'extensionpoint-error-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
37 |
|
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('Extension', 'extension.png', 'extension-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('ExtensionDisabled', 'extension-disabled.png', 'extension-disabled-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('ExtensionError', 'extension-error.png', 'extension-error-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('ExtensionWarning', 'extension-warning.png', 'extension-warning-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
42 |
|
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('Plugin', 'plugin.png', 'plugin-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('PluginDisabled', 'plugin-disabled.png', 'plugin-disabled-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('PluginError', 'plugin-error.png', 'plugin-error-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
46 |
|
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('JarFile', 'jarfile.png', 'jarfile-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('JarFileError', 'jarfile-error.png', 'jarfile-error-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('JarFileWarning', 'jarfile-warning.png', 'jarfile-warning-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('JarFileModified', 'jarfile-modified.png', 'jarfile-modified-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('JarFileModifiedError', 'jarfile-modified-error.png', 'jarfile-modified-error-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('JarFileModifiedWarning', 'jarfile-modified-warning.png', 'jarfile-modified-warning-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
53 |
|
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('XmlFile', 'item.png', 'item-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('XmlFileError', 'item-error.png', 'item-error-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('XmlFileWarning', 'item-warning.png', 'item-warning-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('XmlFileModified', 'item-modified.png', 'item-modified-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('XmlFileModifiedError', 'item-modified-error.png', 'item-modified-error-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
IconStore.addIconSet('XmlFileModifiedWarning', 'item-modified-warning.png', 'item-modified-warning-selected.png'); |
7604 |
25 Feb 19 |
nicklas |
60 |
|
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('joust', 'joust-select', tree.onSelect); |
7604 |
25 Feb 19 |
nicklas |
62 |
|
7604 |
25 Feb 19 |
nicklas |
Joust2.draw('joust'); |
7604 |
25 Feb 19 |
nicklas |
64 |
} |
7604 |
25 Feb 19 |
nicklas |
65 |
|
7604 |
25 Feb 19 |
nicklas |
66 |
|
7604 |
25 Feb 19 |
nicklas |
tree.onSelect = function(event) |
7604 |
25 Feb 19 |
nicklas |
68 |
{ |
7604 |
25 Feb 19 |
nicklas |
var menuItem = event.target.item; |
7604 |
25 Feb 19 |
nicklas |
70 |
|
7604 |
25 Feb 19 |
nicklas |
if (menuItem.type == 'extension-point') |
7604 |
25 Feb 19 |
nicklas |
72 |
{ |
7604 |
25 Feb 19 |
nicklas |
tree.extensionPointOnClick(menuItem.externalId); |
7604 |
25 Feb 19 |
nicklas |
74 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (menuItem.type == 'extension') |
7604 |
25 Feb 19 |
nicklas |
76 |
{ |
7604 |
25 Feb 19 |
nicklas |
tree.extensionOnClick(menuItem.externalId); |
7604 |
25 Feb 19 |
nicklas |
78 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (menuItem.type == 'file') |
7604 |
25 Feb 19 |
nicklas |
80 |
{ |
7604 |
25 Feb 19 |
nicklas |
tree.fileOnClick(menuItem.fileUri); |
7604 |
25 Feb 19 |
nicklas |
82 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (menuItem.type == 'plugin') |
7604 |
25 Feb 19 |
nicklas |
84 |
{ |
7604 |
25 Feb 19 |
nicklas |
tree.pluginOnClick(menuItem.className); |
7604 |
25 Feb 19 |
nicklas |
86 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (menuItem.externalId.indexOf('root.') == 0) |
7604 |
25 Feb 19 |
nicklas |
88 |
{ |
7604 |
25 Feb 19 |
nicklas |
tree.rootOnClick(); |
7604 |
25 Feb 19 |
nicklas |
90 |
} |
7604 |
25 Feb 19 |
nicklas |
91 |
} |
7604 |
25 Feb 19 |
nicklas |
92 |
|
7604 |
25 Feb 19 |
nicklas |
tree.extensionPointOnClick = function(extensionPointId) |
7604 |
25 Feb 19 |
nicklas |
94 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = 'details.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&extensionPointId='+encodeURIComponent(extensionPointId); |
7604 |
25 Feb 19 |
nicklas |
parent.frames['details'].location.href = url; |
7604 |
25 Feb 19 |
nicklas |
98 |
} |
7604 |
25 Feb 19 |
nicklas |
99 |
|
7604 |
25 Feb 19 |
nicklas |
tree.extensionOnClick = function(extensionId) |
7604 |
25 Feb 19 |
nicklas |
101 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = 'details.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&extensionId='+encodeURIComponent(extensionId); |
7604 |
25 Feb 19 |
nicklas |
parent.frames['details'].location.href = url; |
7604 |
25 Feb 19 |
nicklas |
105 |
} |
7604 |
25 Feb 19 |
nicklas |
106 |
|
7604 |
25 Feb 19 |
nicklas |
tree.fileOnClick = function(fileUri) |
7604 |
25 Feb 19 |
nicklas |
108 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = 'details.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&fileuri='+encodeURIComponent(fileUri); |
7604 |
25 Feb 19 |
nicklas |
parent.frames['details'].location.href = url; |
7604 |
25 Feb 19 |
nicklas |
112 |
} |
7604 |
25 Feb 19 |
nicklas |
113 |
|
7604 |
25 Feb 19 |
nicklas |
tree.pluginOnClick = function(className) |
7604 |
25 Feb 19 |
nicklas |
115 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = '../plugindefinitions/index.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=ViewItemByClass&iframe=1'; |
7604 |
25 Feb 19 |
nicklas |
url += '&className='+encodeURIComponent(className); |
7604 |
25 Feb 19 |
nicklas |
parent.frames['details'].location.href = url; |
7604 |
25 Feb 19 |
nicklas |
120 |
} |
7604 |
25 Feb 19 |
nicklas |
121 |
|
7604 |
25 Feb 19 |
nicklas |
tree.rootOnClick = function() |
7604 |
25 Feb 19 |
nicklas |
123 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = 'details.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
parent.frames['details'].location.href = url; |
7604 |
25 Feb 19 |
nicklas |
126 |
} |
7604 |
25 Feb 19 |
nicklas |
127 |
|
7604 |
25 Feb 19 |
nicklas |
128 |
/** |
7604 |
25 Feb 19 |
nicklas |
Select the node representing the extension with |
7604 |
25 Feb 19 |
nicklas |
the given file name. |
7604 |
25 Feb 19 |
nicklas |
131 |
*/ |
7604 |
25 Feb 19 |
nicklas |
tree.selectFile = function(filename) |
7604 |
25 Feb 19 |
nicklas |
133 |
{ |
7604 |
25 Feb 19 |
nicklas |
var menuElement = Doc.element(filename); |
7604 |
25 Feb 19 |
nicklas |
if (menuElement) |
7604 |
25 Feb 19 |
nicklas |
136 |
{ |
7604 |
25 Feb 19 |
nicklas |
//Joust2.open(menuElement); |
7604 |
25 Feb 19 |
nicklas |
Joust2.select(menuElement); |
7604 |
25 Feb 19 |
nicklas |
139 |
} |
7604 |
25 Feb 19 |
nicklas |
140 |
} |
7604 |
25 Feb 19 |
nicklas |
141 |
|
7604 |
25 Feb 19 |
nicklas |
142 |
/** |
7604 |
25 Feb 19 |
nicklas |
Set the icon for all menu items with the given external id. |
7604 |
25 Feb 19 |
nicklas |
NOTE! A single extension may appear in multiple places in the tree! |
7604 |
25 Feb 19 |
nicklas |
145 |
*/ |
7604 |
25 Feb 19 |
nicklas |
tree.setIcon = function(externalId, icon) |
7604 |
25 Feb 19 |
nicklas |
147 |
{ |
7604 |
25 Feb 19 |
nicklas |
var icons = []; |
7604 |
25 Feb 19 |
nicklas |
icons[externalId] = icon; |
7604 |
25 Feb 19 |
nicklas |
tree.setIconsByExternalId(icons); |
7604 |
25 Feb 19 |
nicklas |
151 |
} |
7604 |
25 Feb 19 |
nicklas |
152 |
|
7604 |
25 Feb 19 |
nicklas |
153 |
/** |
7604 |
25 Feb 19 |
nicklas |
Enabled/disable all child icons for the selected |
7604 |
25 Feb 19 |
nicklas |
menu item. |
7604 |
25 Feb 19 |
nicklas |
156 |
*/ |
7604 |
25 Feb 19 |
nicklas |
tree.setChildIcons = function(menuElement, enable) |
7604 |
25 Feb 19 |
nicklas |
158 |
{ |
7604 |
25 Feb 19 |
nicklas |
var menuElement = Doc.element(menuElement); |
7604 |
25 Feb 19 |
nicklas |
if (!menuElement) return; |
7604 |
25 Feb 19 |
nicklas |
161 |
|
7604 |
25 Feb 19 |
nicklas |
var menuItem = menuElement.item; |
7604 |
25 Feb 19 |
nicklas |
if (!menuItem.children) return; |
7604 |
25 Feb 19 |
nicklas |
164 |
|
7604 |
25 Feb 19 |
nicklas |
var icons = []; |
7604 |
25 Feb 19 |
nicklas |
for (var childNo = 0; childNo < menuItem.children.length; childNo++) |
7604 |
25 Feb 19 |
nicklas |
167 |
{ |
7604 |
25 Feb 19 |
nicklas |
var child = menuItem.children[childNo]; |
7604 |
25 Feb 19 |
nicklas |
169 |
|
7604 |
25 Feb 19 |
nicklas |
if (child.type == 'group') |
7604 |
25 Feb 19 |
nicklas |
171 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Receusive call into grouped extensions |
7604 |
25 Feb 19 |
nicklas |
tree.setChildIcons(child.id, enable); |
7604 |
25 Feb 19 |
nicklas |
174 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
176 |
{ |
7604 |
25 Feb 19 |
nicklas |
var iconName = child.icon; |
7604 |
25 Feb 19 |
nicklas |
if (iconName.indexOf('Error') == -1) |
7604 |
25 Feb 19 |
nicklas |
179 |
{ |
7604 |
25 Feb 19 |
nicklas |
var isDisabled = iconName.indexOf('Disabled') > 0; |
7604 |
25 Feb 19 |
nicklas |
if (enable && isDisabled) |
7604 |
25 Feb 19 |
nicklas |
182 |
{ |
7604 |
25 Feb 19 |
nicklas |
iconName = iconName.replace('Disabled', ''); |
7604 |
25 Feb 19 |
nicklas |
184 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (!enable && !isDisabled) |
7604 |
25 Feb 19 |
nicklas |
186 |
{ |
7604 |
25 Feb 19 |
nicklas |
iconName += 'Disabled'; |
7604 |
25 Feb 19 |
nicklas |
188 |
} |
7604 |
25 Feb 19 |
nicklas |
icons[child.externalId] = iconName; |
7604 |
25 Feb 19 |
nicklas |
190 |
} |
7604 |
25 Feb 19 |
nicklas |
191 |
} |
7604 |
25 Feb 19 |
nicklas |
192 |
} |
7604 |
25 Feb 19 |
nicklas |
tree.setIconsByExternalId(icons); |
7604 |
25 Feb 19 |
nicklas |
194 |
} |
7604 |
25 Feb 19 |
nicklas |
195 |
|
7604 |
25 Feb 19 |
nicklas |
196 |
|
7604 |
25 Feb 19 |
nicklas |
197 |
/** |
7604 |
25 Feb 19 |
nicklas |
'icons' is an array with <key>=<externalId> and <value>=<new icon name> |
7604 |
25 Feb 19 |
nicklas |
Loop through all menu items and change the icon if the external id |
7604 |
25 Feb 19 |
nicklas |
matches. |
7604 |
25 Feb 19 |
nicklas |
201 |
*/ |
7604 |
25 Feb 19 |
nicklas |
tree.setIconsByExternalId = function(icons) |
7604 |
25 Feb 19 |
nicklas |
203 |
{ |
7604 |
25 Feb 19 |
nicklas |
var tree = Doc.element('joust'); |
7604 |
25 Feb 19 |
nicklas |
205 |
|
7604 |
25 Feb 19 |
nicklas |
var menuElements = tree.getElementsByClassName('joustitem'); |
7604 |
25 Feb 19 |
nicklas |
for (var menuNo = 0; menuNo < menuElements.length; menuNo++) |
7604 |
25 Feb 19 |
nicklas |
208 |
{ |
7604 |
25 Feb 19 |
nicklas |
var menuElement = menuElements[menuNo]; |
7604 |
25 Feb 19 |
nicklas |
var menuItem = menuElement.item; |
7604 |
25 Feb 19 |
nicklas |
211 |
|
7604 |
25 Feb 19 |
nicklas |
var iconName = icons[menuItem.externalId]; |
7604 |
25 Feb 19 |
nicklas |
if (iconName) |
7604 |
25 Feb 19 |
nicklas |
214 |
{ |
7604 |
25 Feb 19 |
nicklas |
menuItem.icon = iconName; |
7604 |
25 Feb 19 |
nicklas |
Joust2.updateIconsAndText(menuElement); |
7604 |
25 Feb 19 |
nicklas |
217 |
} |
7604 |
25 Feb 19 |
nicklas |
218 |
} |
7604 |
25 Feb 19 |
nicklas |
219 |
} |
7604 |
25 Feb 19 |
nicklas |
220 |
|
7604 |
25 Feb 19 |
nicklas |
221 |
|
7604 |
25 Feb 19 |
nicklas |
return tree; |
7604 |
25 Feb 19 |
nicklas |
223 |
}(); |
7604 |
25 Feb 19 |
nicklas |
224 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Tree.initPage); |