1 | <%-- $Id: list_trash.jsp 5952 2012-02-10 12:27:27Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
---|
4 | Copyright (C) 2007 Johan Enell, Nicklas Nordborg, 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 pageEncoding="UTF-8" session="false" |
---|
27 | import="net.sf.basedb.core.SessionControl" |
---|
28 | import="net.sf.basedb.core.DbControl" |
---|
29 | import="net.sf.basedb.core.Trashcan" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.ItemContext" |
---|
32 | import="net.sf.basedb.core.Permission" |
---|
33 | import="net.sf.basedb.core.BasicItem" |
---|
34 | import="net.sf.basedb.core.Removable" |
---|
35 | import="net.sf.basedb.core.Nameable" |
---|
36 | import="net.sf.basedb.core.File" |
---|
37 | import="net.sf.basedb.core.Directory" |
---|
38 | import="net.sf.basedb.core.Metadata" |
---|
39 | import="net.sf.basedb.core.query.ResultList" |
---|
40 | import="net.sf.basedb.util.Enumeration" |
---|
41 | import="net.sf.basedb.clients.web.Base" |
---|
42 | import="net.sf.basedb.clients.web.util.HTML" |
---|
43 | import="net.sf.basedb.util.Values" |
---|
44 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
45 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
46 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
47 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
48 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
49 | import="java.util.Set" |
---|
50 | import="java.util.HashSet" |
---|
51 | %> |
---|
52 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
53 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
54 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
55 | <%! |
---|
56 | private static final Item itemType = Item.SYSTEM; |
---|
57 | private static final String subContext = "trashcan"; |
---|
58 | |
---|
59 | private static final Enumeration<String, String> items = new Enumeration<String, String>(); |
---|
60 | static |
---|
61 | { |
---|
62 | for (Item item : Metadata.getRemovableItems()) |
---|
63 | { |
---|
64 | items.add(item.name(), item.toString()); |
---|
65 | } |
---|
66 | } |
---|
67 | %> |
---|
68 | <% |
---|
69 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
70 | final String ID = sc.getId(); |
---|
71 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null); |
---|
72 | |
---|
73 | final DbControl dc = sc.newDbControl(); |
---|
74 | ResultList<Removable> trash = null; |
---|
75 | try |
---|
76 | { |
---|
77 | long totalCount = 0; |
---|
78 | try |
---|
79 | { |
---|
80 | String filterItem = cc.getPropertyValue("type"); |
---|
81 | Set<Item> itemTypes = null; |
---|
82 | if (filterItem != null) |
---|
83 | { |
---|
84 | itemTypes = new HashSet<Item>(); |
---|
85 | for (String name : filterItem.split("\\|")) |
---|
86 | { |
---|
87 | itemTypes.add(Item.valueOf(name)); |
---|
88 | } |
---|
89 | } |
---|
90 | trash = Trashcan.getItems(dc, itemTypes, cc.getPage() * cc.getRowsPerPage(), cc.getRowsPerPage()); |
---|
91 | totalCount = trash.getTotalCount(); |
---|
92 | } |
---|
93 | catch (Throwable t) |
---|
94 | { |
---|
95 | cc.setMessage(t.getMessage()); |
---|
96 | } |
---|
97 | int numListed = 0; |
---|
98 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext); |
---|
99 | ExtensionsInvoker invoker = ExtensionsControl.useExtensions(jspContext, |
---|
100 | "net.sf.basedb.clients.web.toolbar.list.all", |
---|
101 | "net.sf.basedb.clients.web.toolbar.list.trashcan"); |
---|
102 | %> |
---|
103 | <base:page title="Trashcan"> |
---|
104 | <base:head scripts="menu.js,table.js" styles="menu.css,table.css,toolbar.css"> |
---|
105 | <ext:scripts context="<%=jspContext%>" /> |
---|
106 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
107 | <script language="JavaScript"> |
---|
108 | var submitPage = 'index.jsp'; |
---|
109 | var formId = 'trashcan'; |
---|
110 | function viewItem(itemId) |
---|
111 | { |
---|
112 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id='+itemId, 'ViewJob', 750, 500); |
---|
113 | } |
---|
114 | function itemOnClick(evt, itemId) |
---|
115 | { |
---|
116 | viewItem(itemId); |
---|
117 | } |
---|
118 | function deleteAllItems() |
---|
119 | { |
---|
120 | if (!confirm('You are about to PERMANENTLY DELETE all item.\n This can\'t be undone. Continue?')) |
---|
121 | { |
---|
122 | return; |
---|
123 | } |
---|
124 | Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Empty trashcan', 'Progress', 400, 200); |
---|
125 | var frm = document.forms[formId]; |
---|
126 | frm.action = submitPage; |
---|
127 | frm.cmd.value = 'DeleteAllPermanently'; |
---|
128 | frm.submit(); |
---|
129 | } |
---|
130 | function deleteItems() |
---|
131 | { |
---|
132 | var frm = document.forms[formId]; |
---|
133 | var numChecked = Forms.numChecked(frm, /item:/); |
---|
134 | if (numChecked == 0) |
---|
135 | { |
---|
136 | alert('Please select at least one item in the list'); |
---|
137 | return; |
---|
138 | } |
---|
139 | else |
---|
140 | { |
---|
141 | var items = numChecked == 1 ? 'item' : 'items'; |
---|
142 | if (!confirm('You are about to PERMANENTLY DELETE '+numChecked+' '+items+'.\n This can\'t be undone. Continue?')) |
---|
143 | { |
---|
144 | return; |
---|
145 | } |
---|
146 | } |
---|
147 | Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Delete items', 'Progress', 400, 200); |
---|
148 | frm.action = submitPage; |
---|
149 | frm.cmd.value = 'DeleteItemsPermanently'; |
---|
150 | frm.submit(); |
---|
151 | } |
---|
152 | function restoreItems() |
---|
153 | { |
---|
154 | var frm = document.forms[formId]; |
---|
155 | if (Forms.numChecked(frm, /item:/) == 0) |
---|
156 | { |
---|
157 | alert('Please select at least one item in the list'); |
---|
158 | return; |
---|
159 | } |
---|
160 | frm.action = submitPage; |
---|
161 | frm.cmd.value = 'RestoreItems'; |
---|
162 | frm.submit(); |
---|
163 | } |
---|
164 | function configureColumns() |
---|
165 | { |
---|
166 | Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
167 | } |
---|
168 | function presetOnChange() |
---|
169 | { |
---|
170 | Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
171 | } |
---|
172 | function showUsingItems(itemType, itemId) |
---|
173 | { |
---|
174 | var url = 'index.jsp?ID=<%=ID%>&cmd=ViewUsingItems&item_type='+itemType+'&item_id='+itemId; |
---|
175 | location.href = url; |
---|
176 | } |
---|
177 | </script> |
---|
178 | </base:head> |
---|
179 | |
---|
180 | <base:body> |
---|
181 | <h1>Trashcan</h1> |
---|
182 | <div class="content"> |
---|
183 | <tbl:table |
---|
184 | id="trashcan" |
---|
185 | columns="<%=cc.getSetting("columns")%>" |
---|
186 | action="index.jsp" |
---|
187 | sc="<%=sc%>" |
---|
188 | item="<%=itemType%>" |
---|
189 | subcontext="<%=subContext%>" |
---|
190 | subclass="fulltable" |
---|
191 | > |
---|
192 | <tbl:columndef |
---|
193 | id="type" |
---|
194 | property="type" |
---|
195 | datatype="string" |
---|
196 | title="Item type" |
---|
197 | enumeration="<%=items%>" |
---|
198 | filterable="true" |
---|
199 | show="always" |
---|
200 | /> |
---|
201 | <tbl:columndef |
---|
202 | id="name" |
---|
203 | title="Name" |
---|
204 | show="always" |
---|
205 | /> |
---|
206 | <tbl:columndef |
---|
207 | id="id" |
---|
208 | property="id" |
---|
209 | datatype="int" |
---|
210 | title="ID" |
---|
211 | exportable="true" |
---|
212 | /> |
---|
213 | <tbl:columndef |
---|
214 | id="description" |
---|
215 | title="Description" |
---|
216 | /> |
---|
217 | <div class="panelgroup bottomborder"> |
---|
218 | <tbl:toolbar subclass="bottomborder"> |
---|
219 | <tbl:button |
---|
220 | image="deleteall.png" |
---|
221 | onclick="deleteAllItems()" |
---|
222 | title="Empty trash…" |
---|
223 | tooltip="Delete all items from the trashcan" |
---|
224 | disabled="<%=totalCount <= 0%>" |
---|
225 | /> |
---|
226 | <tbl:button |
---|
227 | image="delete_permanently.png" |
---|
228 | onclick="deleteItems()" |
---|
229 | title="Delete permanently…" |
---|
230 | tooltip="Delete the selected items permanently" |
---|
231 | disabled="<%=totalCount <= 0%>" |
---|
232 | /> |
---|
233 | <tbl:button |
---|
234 | image="restore.png" |
---|
235 | onclick="restoreItems()" |
---|
236 | title="Restore" |
---|
237 | tooltip="Restore the selected items" |
---|
238 | disabled="<%=totalCount <= 0%>" |
---|
239 | /> |
---|
240 | <tbl:button |
---|
241 | image="columns.png" |
---|
242 | onclick="configureColumns()" |
---|
243 | title="Columns…" |
---|
244 | tooltip="Show, hide and re-order columns" |
---|
245 | /> |
---|
246 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
247 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
248 | </tbl:toolbar> |
---|
249 | <tbl:panel> |
---|
250 | <tbl:presetselector |
---|
251 | onchange="presetOnChange()" |
---|
252 | /> |
---|
253 | <tbl:navigator |
---|
254 | page="<%=cc.getPage()%>" |
---|
255 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
256 | totalrows="<%=trash == null ? 0 : trash.getTotalCount()%>" |
---|
257 | /> |
---|
258 | </tbl:panel> |
---|
259 | </div> |
---|
260 | <tbl:data> |
---|
261 | <tbl:headers> |
---|
262 | <tbl:headerrow> |
---|
263 | <tbl:header colspan="3" /> |
---|
264 | <tbl:columnheaders /> |
---|
265 | </tbl:headerrow> |
---|
266 | <tbl:headerrow> |
---|
267 | <tbl:header subclass="index" /> |
---|
268 | <tbl:header |
---|
269 | subclass="check" |
---|
270 | ><base:icon |
---|
271 | image="check_uncheck.png" |
---|
272 | tooltip="Check/uncheck all" |
---|
273 | onclick="Forms.checkUncheck(document.forms[formId])" |
---|
274 | /></tbl:header> |
---|
275 | <tbl:header |
---|
276 | subclass="icons" |
---|
277 | /> |
---|
278 | <tbl:propertyfilter /> |
---|
279 | </tbl:headerrow> |
---|
280 | </tbl:headers> |
---|
281 | <tbl:rows> |
---|
282 | <% |
---|
283 | if (cc.getMessage() != null) |
---|
284 | { |
---|
285 | %> |
---|
286 | <tbl:panel clazz="messagepanel"> |
---|
287 | <div class="messagecontainer error"><%=cc.getMessage()%></div> |
---|
288 | </tbl:panel> |
---|
289 | <% |
---|
290 | cc.setMessage(null); |
---|
291 | } |
---|
292 | int index = cc.getPage()*cc.getRowsPerPage(); |
---|
293 | if (trash != null) |
---|
294 | { |
---|
295 | for (Removable item : trash) |
---|
296 | { |
---|
297 | BasicItem basicItem = (BasicItem)item; |
---|
298 | boolean isUsed = basicItem.isUsed(); |
---|
299 | int itemId = item.getId(); |
---|
300 | String name = ""; |
---|
301 | String description = ""; |
---|
302 | if (item instanceof File) |
---|
303 | { |
---|
304 | File file = (File)item; |
---|
305 | name = file.getPath().toString(); |
---|
306 | description = file.getDescription(); |
---|
307 | } |
---|
308 | else if (item instanceof Directory) |
---|
309 | { |
---|
310 | Directory dir = (Directory)item; |
---|
311 | name = dir.getPath().toString(); |
---|
312 | description = dir.getDescription(); |
---|
313 | } |
---|
314 | else if (item instanceof Nameable) |
---|
315 | { |
---|
316 | Nameable nameable = (Nameable)item; |
---|
317 | name = nameable.getName(); |
---|
318 | description = nameable.getDescription(); |
---|
319 | } |
---|
320 | else |
---|
321 | { |
---|
322 | name = item.toString(); |
---|
323 | } |
---|
324 | String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, true); |
---|
325 | index++; |
---|
326 | numListed++; |
---|
327 | %> |
---|
328 | <tbl:row> |
---|
329 | <tbl:header |
---|
330 | clazz="index" |
---|
331 | ><%=index%></tbl:header> |
---|
332 | <tbl:header |
---|
333 | clazz="check" |
---|
334 | ><input |
---|
335 | type="checkbox" |
---|
336 | name="item:<%=item.getType().name()%>" |
---|
337 | value="<%=itemId%>" |
---|
338 | ></tbl:header> |
---|
339 | <tbl:header |
---|
340 | clazz="icons" |
---|
341 | ><base:icon |
---|
342 | image="used.png" |
---|
343 | tooltip="This item is used by other items and cannot be deleted" |
---|
344 | visible="<%=isUsed%>" |
---|
345 | onclick="<%="showUsingItems('" + item.getType().name() + "', " + itemId + ")"%>" |
---|
346 | /> </tbl:header> |
---|
347 | <tbl:cell column="type"><%=item.getType()%></tbl:cell> |
---|
348 | <tbl:cell column="name"><%=link%></tbl:cell> |
---|
349 | <tbl:cell column="id"><%=item.getId()%></tbl:cell> |
---|
350 | <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell> |
---|
351 | </tbl:row> |
---|
352 | <% |
---|
353 | } |
---|
354 | } |
---|
355 | if (numListed == 0) |
---|
356 | { |
---|
357 | %> |
---|
358 | <tbl:panel clazz="messagepanel"> |
---|
359 | <div class="messagecontainer note"> |
---|
360 | <%=trash == null || trash.size() == 0 ? "No items were found" : "No items on this page. Please select another page!" %> |
---|
361 | </div> |
---|
362 | </tbl:panel> |
---|
363 | <% |
---|
364 | } |
---|
365 | %> |
---|
366 | </tbl:rows> |
---|
367 | </tbl:data> |
---|
368 | </tbl:table> |
---|
369 | </div> |
---|
370 | |
---|
371 | </base:body> |
---|
372 | </base:page> |
---|
373 | <% |
---|
374 | } |
---|
375 | finally |
---|
376 | { |
---|
377 | if (dc != null) dc.close(); |
---|
378 | } |
---|
379 | %> |
---|