1 | <%-- $Id: view_item.jsp 2978 2006-11-30 07:27:42Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) Authors contributing to this file. |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 2 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page session="false" |
---|
28 | import="net.sf.basedb.core.SessionControl" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.SystemItems" |
---|
31 | import="net.sf.basedb.core.BasicItem" |
---|
32 | import="net.sf.basedb.core.Removable" |
---|
33 | import="net.sf.basedb.core.Shareable" |
---|
34 | import="net.sf.basedb.core.Nameable" |
---|
35 | import="net.sf.basedb.core.File" |
---|
36 | import="net.sf.basedb.core.Directory" |
---|
37 | import="net.sf.basedb.core.Item" |
---|
38 | import="net.sf.basedb.core.ItemProxy" |
---|
39 | import="net.sf.basedb.core.ItemContext" |
---|
40 | import="net.sf.basedb.core.Permission" |
---|
41 | import="net.sf.basedb.core.Session" |
---|
42 | import="net.sf.basedb.core.User" |
---|
43 | import="net.sf.basedb.core.Client" |
---|
44 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
45 | import="net.sf.basedb.core.PluginDefinition" |
---|
46 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
47 | import="net.sf.basedb.core.plugin.Plugin" |
---|
48 | import="net.sf.basedb.clients.web.Base" |
---|
49 | import="net.sf.basedb.clients.web.PermissionUtil" |
---|
50 | import="net.sf.basedb.clients.web.util.HTML" |
---|
51 | import="net.sf.basedb.util.Values" |
---|
52 | import="java.util.Date" |
---|
53 | import="java.util.Map" |
---|
54 | import="java.util.Set" |
---|
55 | import="java.util.List" |
---|
56 | %> |
---|
57 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
58 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
59 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
60 | <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %> |
---|
61 | |
---|
62 | <% |
---|
63 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
64 | final String ID = sc.getId(); |
---|
65 | final int itemId = Values.getInt(request.getParameter("item_id")); |
---|
66 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
67 | final DbControl dc = sc.newDbControl(); |
---|
68 | try |
---|
69 | { |
---|
70 | BasicItem item = itemType.getById(dc, itemId); |
---|
71 | Set<ItemProxy> usingItems = item.getUsingItems(); |
---|
72 | final boolean isUsed = usingItems != null && usingItems.size() > 0; |
---|
73 | final boolean writePermission = item.hasPermission(Permission.WRITE); |
---|
74 | final boolean deletePermission = item.hasPermission(Permission.DELETE); |
---|
75 | final boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION); |
---|
76 | final Shareable shareable = item instanceof Shareable ? (Shareable)item : null; |
---|
77 | final boolean isShared = shareable != null && shareable.isShared(); |
---|
78 | final Removable removable = item instanceof Removable ? (Removable)item : null; |
---|
79 | final boolean isRemoved = removable != null && removable.isRemoved(); |
---|
80 | String name = ""; |
---|
81 | String description = ""; |
---|
82 | if (item instanceof File) |
---|
83 | { |
---|
84 | File file = (File)item; |
---|
85 | name = file.getPath().toString(); |
---|
86 | description = file.getDescription(); |
---|
87 | } |
---|
88 | else if (item instanceof Directory) |
---|
89 | { |
---|
90 | Directory dir = (Directory)item; |
---|
91 | name = dir.getPath().toString(); |
---|
92 | description = dir.getDescription(); |
---|
93 | } |
---|
94 | else if (item instanceof Nameable) |
---|
95 | { |
---|
96 | Nameable nameable = (Nameable)item; |
---|
97 | name = nameable.getName(); |
---|
98 | description = nameable.getDescription(); |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | name = item.toString(); |
---|
103 | } |
---|
104 | String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, writePermission); |
---|
105 | %> |
---|
106 | |
---|
107 | <base:page> |
---|
108 | <base:head scripts="tabcontrol.js,table.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css"> |
---|
109 | <script language="JavaScript"> |
---|
110 | var submitPage = 'index.jsp'; |
---|
111 | var formId = 'usingItems'; |
---|
112 | function editItem() |
---|
113 | { |
---|
114 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true); |
---|
115 | } |
---|
116 | function shareItem() |
---|
117 | { |
---|
118 | var controller = Main.getController('<%=itemType.name()%>'); |
---|
119 | var url = getRoot() + controller.url + '?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>'; |
---|
120 | Main.openPopup(url, 'ShareItem', 500, 400); |
---|
121 | } |
---|
122 | function restoreItem() |
---|
123 | { |
---|
124 | url = 'index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_type=<%=itemType.name()%>&item_id=<%=itemId%>'; |
---|
125 | location.replace(url); |
---|
126 | } |
---|
127 | function deleteItem() |
---|
128 | { |
---|
129 | if (!confirm('You are about to PERMANENTLY DELETE this item.\n This can\'t be undone. Continue?')) |
---|
130 | { |
---|
131 | return; |
---|
132 | } |
---|
133 | var url = 'index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_type=<%=itemType.name()%>&item_id=<%=itemId%>'; |
---|
134 | location.replace(url); |
---|
135 | } |
---|
136 | function deleteItems() |
---|
137 | { |
---|
138 | var frm = document.forms[formId]; |
---|
139 | var numChecked = Forms.numChecked(frm, /item:/); |
---|
140 | if (numChecked == 0) |
---|
141 | { |
---|
142 | alert('Please select at least one item in the list'); |
---|
143 | return; |
---|
144 | } |
---|
145 | frm.action = submitPage; |
---|
146 | frm.cmd.value = 'DeleteItems'; |
---|
147 | frm.submit(); |
---|
148 | } |
---|
149 | function restoreItems() |
---|
150 | { |
---|
151 | var frm = document.forms[formId]; |
---|
152 | var numChecked = Forms.numChecked(frm, /item:/); |
---|
153 | if (numChecked == 0) |
---|
154 | { |
---|
155 | alert('Please select at least one item in the list'); |
---|
156 | return; |
---|
157 | } |
---|
158 | frm.action = submitPage; |
---|
159 | frm.cmd.value = 'RestoreItems'; |
---|
160 | frm.submit(); |
---|
161 | } |
---|
162 | |
---|
163 | </script> |
---|
164 | </base:head> |
---|
165 | <base:body> |
---|
166 | <p> |
---|
167 | <p:path> |
---|
168 | <p:pathelement title="Trashcan" href="<%="index.jsp?ID="+ID%>" /> |
---|
169 | <p:pathelement title="<%=itemType.toString() + ": " + HTML.encodeTags(name)%>" /> |
---|
170 | </p:path> |
---|
171 | |
---|
172 | <t:tabcontrol id="main"> |
---|
173 | <t:tab id="properties" title="Properties"> |
---|
174 | |
---|
175 | <tbl:toolbar |
---|
176 | > |
---|
177 | <tbl:button |
---|
178 | disabled="<%=writePermission ? false : true%>" |
---|
179 | image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" |
---|
180 | onclick="editItem()" |
---|
181 | title="Edit…" |
---|
182 | tooltip="<%=writePermission ? "Edit this item" : "You do not have permission to edit this item"%>" |
---|
183 | /> |
---|
184 | <tbl:button |
---|
185 | disabled="<%=deletePermission ? false : true%>" |
---|
186 | image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" |
---|
187 | onclick="deleteItem()" |
---|
188 | title="Delete" |
---|
189 | visible="<%=!isUsed%>" |
---|
190 | tooltip="<%=deletePermission ? "Permanently delete this item" : "You do not have permission to delete this item"%>" |
---|
191 | /> |
---|
192 | <tbl:button |
---|
193 | disabled="<%=writePermission ? false : true%>" |
---|
194 | image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" |
---|
195 | onclick="restoreItem()" |
---|
196 | title="Restore" |
---|
197 | visible="<%=isRemoved%>" |
---|
198 | tooltip="<%=writePermission ? "Restore this item" : "You do not have permission to restore this item"%>" |
---|
199 | /> |
---|
200 | <tbl:button |
---|
201 | disabled="<%=sharePermission ? false : true%>" |
---|
202 | image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>" |
---|
203 | onclick="shareItem()" |
---|
204 | title="Share…" |
---|
205 | visible="<%=shareable != null%>" |
---|
206 | tooltip="<%=sharePermission ? "Share this item to other user, groups and projects" : "You do not have permission to share this scan"%>" |
---|
207 | /> |
---|
208 | <tbl:button |
---|
209 | image="help.gif" |
---|
210 | onclick="<%="Main.openHelp('" + ID +"', 'trash.view.properties')"%>" |
---|
211 | title="Help…" |
---|
212 | tooltip="Get help about this page" |
---|
213 | /> |
---|
214 | </tbl:toolbar> |
---|
215 | |
---|
216 | <div class="boxedbottom"> |
---|
217 | <div class="itemstatus">Permissions on this item: |
---|
218 | <i><%=PermissionUtil.getFullPermissionNames(item)%></i></div> |
---|
219 | <% |
---|
220 | if (isRemoved || isShared || isUsed) |
---|
221 | { |
---|
222 | %> |
---|
223 | <div class="itemstatus"> |
---|
224 | <base:icon image="deleted.gif" |
---|
225 | visible="<%=isRemoved%>" style="margin-bottom: 2px;"> This item has been flagged for deletion<br></base:icon> |
---|
226 | <base:icon image="shared.gif" |
---|
227 | visible="<%=isShared%>" style="margin-bottom: 2px;"> This item is shared to other user, groups and/or projects<br></base:icon> |
---|
228 | <base:icon image="used.gif" |
---|
229 | visible="<%=isUsed%>" style="margin-bottom: 2px;"> This item is used by other items and can't be permanently deleted</base:icon> |
---|
230 | </div> |
---|
231 | <% |
---|
232 | } |
---|
233 | %> |
---|
234 | <table class="form" cellspacing=0> |
---|
235 | <tr> |
---|
236 | <td class="prompt">Type</td> |
---|
237 | <td><%=itemType.toString()%></td> |
---|
238 | </tr> |
---|
239 | <tr> |
---|
240 | <td class="prompt">Name</td> |
---|
241 | <td><%=link%></td> |
---|
242 | </tr> |
---|
243 | <tr> |
---|
244 | <td class="prompt">Description</td> |
---|
245 | <td><%=HTML.niceFormat(description)%></td> |
---|
246 | </tr> |
---|
247 | </table> |
---|
248 | |
---|
249 | <% |
---|
250 | if (isUsed) |
---|
251 | { |
---|
252 | %> |
---|
253 | <h4 class="docked">Items using <%=itemType.toString()%>: <%=HTML.encodeTags(name)%></h4> |
---|
254 | <tbl:table |
---|
255 | id="usingItems" |
---|
256 | clazz="itemlist" |
---|
257 | columns="all" |
---|
258 | > |
---|
259 | <tbl:hidden |
---|
260 | name="item_type" |
---|
261 | value="<%=itemType.name()%>" |
---|
262 | /> |
---|
263 | <tbl:hidden |
---|
264 | name="item_id" |
---|
265 | value="<%=String.valueOf(itemId)%>" |
---|
266 | /> |
---|
267 | <tbl:columndef |
---|
268 | id="name" |
---|
269 | title="Name/ID" |
---|
270 | /> |
---|
271 | <tbl:columndef |
---|
272 | id="type" |
---|
273 | title="Type" |
---|
274 | /> |
---|
275 | <tbl:columndef |
---|
276 | id="description" |
---|
277 | title="Description" |
---|
278 | /> |
---|
279 | <tbl:toolbar> |
---|
280 | <tbl:button |
---|
281 | image="delete.gif" |
---|
282 | onclick="deleteItems()" |
---|
283 | title="Delete" |
---|
284 | tooltip="Mark the selected items for deletion" |
---|
285 | /> |
---|
286 | <tbl:button |
---|
287 | image="restore.gif" |
---|
288 | onclick="restoreItems()" |
---|
289 | title="Restore" |
---|
290 | tooltip="Restore the selected item" |
---|
291 | /> |
---|
292 | </tbl:toolbar> |
---|
293 | <tbl:data> |
---|
294 | <tbl:columns> |
---|
295 | <tbl:header |
---|
296 | clazz="index" |
---|
297 | > </tbl:header> |
---|
298 | <tbl:header |
---|
299 | clazz="check" |
---|
300 | ><base:icon |
---|
301 | image="check_uncheck.gif" |
---|
302 | tooltip="Check/uncheck all" |
---|
303 | onclick="Forms.checkUncheck(document.forms['usingItems'], /item:/)" style="align: left;" |
---|
304 | /></tbl:header> |
---|
305 | <tbl:header |
---|
306 | clazz="icons" |
---|
307 | > </tbl:header> |
---|
308 | </tbl:columns> |
---|
309 | <tbl:rows> |
---|
310 | <% |
---|
311 | int index = 0; |
---|
312 | for (ItemProxy proxy : usingItems) |
---|
313 | { |
---|
314 | index++; |
---|
315 | boolean denied = false; |
---|
316 | boolean writePermissionOnUsedBy = false; |
---|
317 | boolean usedByIsRemoved = false; |
---|
318 | boolean usedByRemovable = false; |
---|
319 | BasicItem usedBy = null; |
---|
320 | String usedByName = String.valueOf(proxy.getId()); |
---|
321 | String usedByDescription = ""; |
---|
322 | try |
---|
323 | { |
---|
324 | usedBy = proxy.getItem(dc); |
---|
325 | writePermissionOnUsedBy = usedBy.hasPermission(Permission.WRITE); |
---|
326 | if (usedBy instanceof Removable) |
---|
327 | { |
---|
328 | usedByRemovable = true; |
---|
329 | usedByIsRemoved = ((Removable)usedBy).isRemoved(); |
---|
330 | } |
---|
331 | if (usedBy instanceof File) |
---|
332 | { |
---|
333 | File file = (File)usedBy; |
---|
334 | usedByName = file.getPath().toString(); |
---|
335 | usedByDescription = file.getDescription(); |
---|
336 | } |
---|
337 | else if (usedBy instanceof Directory) |
---|
338 | { |
---|
339 | Directory dir = (Directory)usedBy; |
---|
340 | usedByName = dir.getPath().toString(); |
---|
341 | usedByDescription = dir.getDescription(); |
---|
342 | } |
---|
343 | else if (usedBy instanceof Nameable) |
---|
344 | { |
---|
345 | Nameable nameable = (Nameable)usedBy; |
---|
346 | usedByName = nameable.getName(); |
---|
347 | usedByDescription = nameable.getDescription(); |
---|
348 | } |
---|
349 | else |
---|
350 | { |
---|
351 | usedByName = usedBy.toString(); |
---|
352 | } |
---|
353 | } |
---|
354 | catch (PermissionDeniedException ex) |
---|
355 | { |
---|
356 | denied = true; |
---|
357 | } |
---|
358 | %> |
---|
359 | <tbl:row> |
---|
360 | <tbl:header |
---|
361 | clazz="index" |
---|
362 | ><%=index%></tbl:header> |
---|
363 | <tbl:header |
---|
364 | clazz="check" |
---|
365 | ><% |
---|
366 | if (usedByRemovable) |
---|
367 | { |
---|
368 | %><input |
---|
369 | type="checkbox" |
---|
370 | name="item:<%=proxy.getType().name()%>" |
---|
371 | value="<%=proxy.getId()%>" |
---|
372 | ><% |
---|
373 | } |
---|
374 | %></tbl:header> |
---|
375 | <tbl:header |
---|
376 | clazz="icons" |
---|
377 | ><base:icon |
---|
378 | image="deleted.gif" |
---|
379 | tooltip="This item has been scheduled for deletion" |
---|
380 | visible="<%=usedByIsRemoved%>" |
---|
381 | /> </tbl:header> |
---|
382 | <tbl:cell column="name"><%=Base.getLink(ID, HTML.encodeTags(usedByName), proxy.getType(), proxy.getId(), writePermissionOnUsedBy)%></tbl:cell> |
---|
383 | <tbl:cell column="type"><%=proxy.getType().toString()%></tbl:cell> |
---|
384 | <tbl:cell column="description"><%=HTML.niceFormat(usedByDescription)%></tbl:cell> |
---|
385 | </tbl:row> |
---|
386 | <% |
---|
387 | } |
---|
388 | %> |
---|
389 | </tbl:rows> |
---|
390 | </tbl:data> |
---|
391 | </tbl:table> |
---|
392 | <% |
---|
393 | } |
---|
394 | %> |
---|
395 | |
---|
396 | </t:tab> |
---|
397 | </t:tabcontrol> |
---|
398 | |
---|
399 | </base:body> |
---|
400 | </base:page> |
---|
401 | <% |
---|
402 | } |
---|
403 | finally |
---|
404 | { |
---|
405 | if (dc != null) dc.commit(); |
---|
406 | } |
---|
407 | |
---|
408 | %> |
---|