1 | <%-- $Id: view_hardware.jsp 5042 2009-08-11 10:48:42Z martin $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
---|
4 | Copyright (C) 2007 Martin Svensson |
---|
5 | |
---|
6 | This file is part of BASE - BioArray Software Environment. |
---|
7 | Available at http://base.thep.lu.se/ |
---|
8 | |
---|
9 | BASE is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 3 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | BASE is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | ------------------------------------------------------------------ |
---|
22 | |
---|
23 | @author Nicklas |
---|
24 | @version 2.0 |
---|
25 | --%> |
---|
26 | <%@ page session="false" |
---|
27 | import="net.sf.basedb.core.SessionControl" |
---|
28 | import="net.sf.basedb.core.DbControl" |
---|
29 | import="net.sf.basedb.core.SystemItems" |
---|
30 | import="net.sf.basedb.core.Group" |
---|
31 | import="net.sf.basedb.core.Item" |
---|
32 | import="net.sf.basedb.core.ItemContext" |
---|
33 | import="net.sf.basedb.core.ItemResultList" |
---|
34 | import="net.sf.basedb.core.Permission" |
---|
35 | import="net.sf.basedb.core.Hardware" |
---|
36 | import="net.sf.basedb.core.HardwareType" |
---|
37 | import="net.sf.basedb.core.User" |
---|
38 | import="net.sf.basedb.core.MultiPermissions" |
---|
39 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
40 | import="net.sf.basedb.core.PluginDefinition" |
---|
41 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
42 | import="net.sf.basedb.core.plugin.Plugin" |
---|
43 | import="net.sf.basedb.core.Project" |
---|
44 | import="net.sf.basedb.clients.web.Base" |
---|
45 | import="net.sf.basedb.clients.web.PermissionUtil" |
---|
46 | import="net.sf.basedb.clients.web.util.HTML" |
---|
47 | import="net.sf.basedb.util.Values" |
---|
48 | import="net.sf.basedb.util.formatter.Formatter" |
---|
49 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
50 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
51 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
52 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
53 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
54 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
55 | import="java.util.Date" |
---|
56 | import="java.util.Collections" |
---|
57 | import="java.util.Map" |
---|
58 | import="java.util.Set" |
---|
59 | %> |
---|
60 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
61 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
62 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
63 | <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %> |
---|
64 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
65 | <%! |
---|
66 | private static final Item itemType = Item.HARDWARE; |
---|
67 | private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM); |
---|
68 | %> |
---|
69 | <% |
---|
70 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
71 | final String ID = sc.getId(); |
---|
72 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
73 | final int itemId = cc.getId(); |
---|
74 | final float scale = Base.getScale(sc); |
---|
75 | final DbControl dc = sc.newDbControl(); |
---|
76 | try |
---|
77 | { |
---|
78 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
79 | Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); |
---|
80 | |
---|
81 | String title = null; |
---|
82 | Hardware hardware = Hardware.getById(dc, itemId); |
---|
83 | |
---|
84 | final boolean writePermission = hardware.hasPermission(Permission.WRITE); |
---|
85 | final boolean deletePermission = hardware.hasPermission(Permission.DELETE); |
---|
86 | final boolean sharePermission = hardware.hasPermission(Permission.SET_PERMISSION); |
---|
87 | final boolean setOwnerPermission = hardware.hasPermission(Permission.SET_OWNER); |
---|
88 | final boolean isOwner = hardware.isOwner(); |
---|
89 | final boolean isRemoved = hardware.isRemoved(); |
---|
90 | final boolean isUsed = isRemoved && hardware.isUsed(); |
---|
91 | final boolean deletePermanentlyPermission = deletePermission && !isUsed; |
---|
92 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, hardware); |
---|
93 | ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext); |
---|
94 | %> |
---|
95 | <base:page title="<%=title%>"> |
---|
96 | <base:head scripts="table,js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css"> |
---|
97 | <ext:scripts context="<%=jspContext%>" /> |
---|
98 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
99 | <script language="JavaScript"> |
---|
100 | function editItem() |
---|
101 | { |
---|
102 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true); |
---|
103 | } |
---|
104 | function shareItem() |
---|
105 | { |
---|
106 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareHardware', 600, 400); |
---|
107 | } |
---|
108 | function deleteItem() |
---|
109 | { |
---|
110 | location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>'); |
---|
111 | } |
---|
112 | function restoreItem() |
---|
113 | { |
---|
114 | location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>'); |
---|
115 | } |
---|
116 | function deleteItemPermanently() |
---|
117 | { |
---|
118 | Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted'); |
---|
119 | } |
---|
120 | function itemDeleted() |
---|
121 | { |
---|
122 | Main.listItems('<%=ID%>', '<%=itemType.name()%>'); |
---|
123 | } |
---|
124 | function showUsingItems() |
---|
125 | { |
---|
126 | Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>); |
---|
127 | } |
---|
128 | function setOwner() |
---|
129 | { |
---|
130 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150); |
---|
131 | } |
---|
132 | function runPlugin(cmd) |
---|
133 | { |
---|
134 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540); |
---|
135 | } |
---|
136 | </script> |
---|
137 | </base:head> |
---|
138 | <base:body> |
---|
139 | <p> |
---|
140 | <p:path> |
---|
141 | <p:pathelement title="Hardware" href="<%="index.jsp?ID="+ID%>" /> |
---|
142 | <p:pathelement title="<%=HTML.encodeTags(hardware.getName())%>" /> |
---|
143 | </p:path> |
---|
144 | |
---|
145 | <t:tabcontrol id="main" active="properties"> |
---|
146 | <t:tab id="properties" title="Properties"> |
---|
147 | |
---|
148 | <tbl:toolbar |
---|
149 | > |
---|
150 | <tbl:button |
---|
151 | disabled="<%=writePermission ? false : true%>" |
---|
152 | image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" |
---|
153 | onclick="editItem()" |
---|
154 | title="Edit…" |
---|
155 | tooltip="<%=writePermission ? "Edit this hardware" : "You do not have permission to edit this hardware"%>" |
---|
156 | /> |
---|
157 | <tbl:button |
---|
158 | disabled="<%=deletePermission ? false : true%>" |
---|
159 | image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" |
---|
160 | onclick="deleteItem()" |
---|
161 | title="Delete" |
---|
162 | visible="<%=!hardware.isRemoved()%>" |
---|
163 | tooltip="<%=deletePermission ? "Delete this hardware" : "You do not have permission to delete this hardware"%>" |
---|
164 | /> |
---|
165 | <tbl:button |
---|
166 | disabled="<%=writePermission ? false : true%>" |
---|
167 | image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" |
---|
168 | onclick="restoreItem()" |
---|
169 | title="Restore" |
---|
170 | visible="<%=hardware.isRemoved()%>" |
---|
171 | tooltip="<%=writePermission ? "Restore this hardware" : "You do not have permission to restore this hardware"%>" |
---|
172 | /> |
---|
173 | <tbl:button |
---|
174 | disabled="<%=sharePermission ? false : true%>" |
---|
175 | image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>" |
---|
176 | onclick="shareItem()" |
---|
177 | title="Share…" |
---|
178 | tooltip="<%=sharePermission ? "Share this hardware to other user, groups and projects" : "You do not have permission to share this hardware"%>" |
---|
179 | /> |
---|
180 | <tbl:button |
---|
181 | disabled="<%=setOwnerPermission ? false : true%>" |
---|
182 | image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>" |
---|
183 | onclick="setOwner()" |
---|
184 | title="Set owner…" |
---|
185 | tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>" |
---|
186 | /> |
---|
187 | <tbl:button |
---|
188 | image="import.gif" |
---|
189 | onclick="runPlugin('ImportItem')" |
---|
190 | title="Import…" |
---|
191 | tooltip="Import data" |
---|
192 | visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>" |
---|
193 | /> |
---|
194 | <tbl:button |
---|
195 | image="export.gif" |
---|
196 | onclick="runPlugin('ExportItem')" |
---|
197 | title="Export…" |
---|
198 | tooltip="Export data" |
---|
199 | visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>" |
---|
200 | /> |
---|
201 | <tbl:button |
---|
202 | image="runplugin.gif" |
---|
203 | onclick="runPlugin('RunPlugin')" |
---|
204 | title="Run plugin…" |
---|
205 | tooltip="Run a plugin" |
---|
206 | visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>" |
---|
207 | /> |
---|
208 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
209 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
210 | <tbl:button |
---|
211 | image="help.gif" |
---|
212 | onclick="<%="Main.openHelp('" + ID +"', 'hardware.view.properties')"%>" |
---|
213 | title="Help…" |
---|
214 | tooltip="Get help about this page" |
---|
215 | /> |
---|
216 | </tbl:toolbar> |
---|
217 | <div class="boxedbottom"> |
---|
218 | <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(hardware)%></i></div> |
---|
219 | <% |
---|
220 | if (hardware.isRemoved() || hardware.isShared()) |
---|
221 | { |
---|
222 | %> |
---|
223 | <div class="itemstatus"> |
---|
224 | <base:icon |
---|
225 | image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>" |
---|
226 | onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>" |
---|
227 | tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>" |
---|
228 | visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon> |
---|
229 | <base:icon image="used.gif" |
---|
230 | onclick="showUsingItems()" |
---|
231 | tooltip="Show the items that are using this one" |
---|
232 | visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon> |
---|
233 | <base:icon image="shared.gif" |
---|
234 | visible="<%=hardware.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon> |
---|
235 | </div> |
---|
236 | <% |
---|
237 | } |
---|
238 | %> |
---|
239 | <table class="form" cellspacing=0> |
---|
240 | <tr> |
---|
241 | <td class="prompt">Name</td> |
---|
242 | <td><%=HTML.encodeTags(hardware.getName())%></td> |
---|
243 | </tr> |
---|
244 | <tr> |
---|
245 | <td class="prompt">Registered</td> |
---|
246 | <td><%=dateFormatter.format(hardware.getEntryDate())%></td> |
---|
247 | </tr> |
---|
248 | <tr> |
---|
249 | <td class="prompt">Type</td> |
---|
250 | <td><base:propertyvalue item="<%=hardware%>" property="hardwareType" /></td> |
---|
251 | </tr> |
---|
252 | <tr> |
---|
253 | <td class="prompt">Version</td> |
---|
254 | <td><%=HTML.encodeTags(hardware.getVersionString())%></td> |
---|
255 | </tr> |
---|
256 | <tr> |
---|
257 | <td class="prompt">Owner</td> |
---|
258 | <td><base:propertyvalue item="<%=hardware%>" property="owner" /></td> |
---|
259 | </tr> |
---|
260 | <tr> |
---|
261 | <td class="prompt">Description</td> |
---|
262 | <td><%=HTML.niceFormat(hardware.getDescription())%></td> |
---|
263 | </tr> |
---|
264 | </table> |
---|
265 | <% |
---|
266 | |
---|
267 | // Tables with users/groups/projects that this item is shared to |
---|
268 | MultiPermissions mp = new MultiPermissions(Collections.singleton(hardware)); |
---|
269 | ItemResultList<User> users = mp.getUsers().list(dc); |
---|
270 | ItemResultList<Group> groups = mp.getGroups().list(dc); |
---|
271 | ItemResultList<Project> projects = mp.getProjects().list(dc); |
---|
272 | int totalShare = (users.size() + groups.size() + projects.size()); |
---|
273 | |
---|
274 | if (totalShare > 0) |
---|
275 | { |
---|
276 | %> |
---|
277 | <base:section |
---|
278 | id="sharedTo" |
---|
279 | title="<%="Shared to (" + totalShare + ")"%>" |
---|
280 | context="<%=cc%>" |
---|
281 | > |
---|
282 | <tbl:table |
---|
283 | id="itemsSharedTo" |
---|
284 | clazz="itemlist" |
---|
285 | columns="all" |
---|
286 | > |
---|
287 | <tbl:columndef |
---|
288 | id="itemType" |
---|
289 | title="Item type" |
---|
290 | /> |
---|
291 | <tbl:columndef |
---|
292 | id="name" |
---|
293 | title="Name" |
---|
294 | /> |
---|
295 | <tbl:columndef |
---|
296 | id="permissions" |
---|
297 | title="Permissions" |
---|
298 | /> |
---|
299 | <tbl:data> |
---|
300 | <tbl:columns> |
---|
301 | </tbl:columns> |
---|
302 | <tbl:rows> |
---|
303 | <% |
---|
304 | for (Project project : projects) |
---|
305 | { |
---|
306 | Set<Permission> permissions = mp.getPermissions(project).values().iterator().next(); |
---|
307 | %> |
---|
308 | <tbl:row> |
---|
309 | <tbl:cell column="itemType"><%=project.getType()%></tbl:cell> |
---|
310 | <tbl:cell column="name"><base:icon |
---|
311 | image="deleted.gif" |
---|
312 | tooltip="This item has been scheduled for deletion" |
---|
313 | visible="<%=project.isRemoved()%>" |
---|
314 | /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell> |
---|
315 | <tbl:cell column="permissions"> |
---|
316 | <%=PermissionUtil.translatePermissionsToString(permissions)%> |
---|
317 | </tbl:cell> |
---|
318 | </tbl:row> |
---|
319 | <% |
---|
320 | } |
---|
321 | for (Group group : groups) |
---|
322 | { |
---|
323 | Set<Permission> permissions = mp.getPermissions(group).values().iterator().next(); |
---|
324 | %> |
---|
325 | <tbl:row> |
---|
326 | <tbl:cell column="itemType"><%=group.getType()%></tbl:cell> |
---|
327 | <tbl:cell column="name"><base:icon |
---|
328 | image="deleted.gif" |
---|
329 | tooltip="This item has been scheduled for deletion" |
---|
330 | visible="<%=group.isRemoved()%>" |
---|
331 | /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell> |
---|
332 | <tbl:cell column="permissions"> |
---|
333 | <%=PermissionUtil.translatePermissionsToString(permissions)%> |
---|
334 | </tbl:cell> |
---|
335 | </tbl:row> |
---|
336 | <% |
---|
337 | } |
---|
338 | for (User user : users) |
---|
339 | { |
---|
340 | Set<Permission> permissions = mp.getPermissions(user).values().iterator().next(); |
---|
341 | %> |
---|
342 | <tbl:row> |
---|
343 | <tbl:cell column="itemType"><%=user.getType()%></tbl:cell> |
---|
344 | <tbl:cell column="name"><base:icon |
---|
345 | image="deleted.gif" |
---|
346 | tooltip="This item has been scheduled for deletion" |
---|
347 | visible="<%=user.isRemoved()%>" |
---|
348 | /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell> |
---|
349 | <tbl:cell column="permissions"> |
---|
350 | <%=PermissionUtil.translatePermissionsToString(permissions)%> |
---|
351 | </tbl:cell> |
---|
352 | </tbl:row> |
---|
353 | <% |
---|
354 | } |
---|
355 | %> |
---|
356 | </tbl:rows> |
---|
357 | </tbl:data> |
---|
358 | </tbl:table> |
---|
359 | </base:section> |
---|
360 | <% |
---|
361 | } |
---|
362 | else |
---|
363 | { |
---|
364 | %> |
---|
365 | <h4>Shared to</h4> |
---|
366 | This hardware is not shared |
---|
367 | (or, you don't have permission to view the ones it is shared to). |
---|
368 | <% |
---|
369 | } |
---|
370 | %> |
---|
371 | </div> |
---|
372 | </t:tab> |
---|
373 | </t:tabcontrol> |
---|
374 | |
---|
375 | |
---|
376 | </base:body> |
---|
377 | </base:page> |
---|
378 | <% |
---|
379 | } |
---|
380 | finally |
---|
381 | { |
---|
382 | if (dc != null) dc.close(); |
---|
383 | } |
---|
384 | |
---|
385 | %> |
---|