1 | <%-- $Id: list_items.jsp 5951 2012-02-09 14:19:17Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Nicklas Nordborg |
---|
4 | Copyright (C) 2007 Johan Enell, 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.User" |
---|
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.Ownable" |
---|
37 | import="net.sf.basedb.core.Shareable" |
---|
38 | import="net.sf.basedb.core.SharedItem" |
---|
39 | import="net.sf.basedb.core.File" |
---|
40 | import="net.sf.basedb.core.Directory" |
---|
41 | import="net.sf.basedb.core.Metadata" |
---|
42 | import="net.sf.basedb.core.PropertyFilter" |
---|
43 | import="net.sf.basedb.core.query.ResultList" |
---|
44 | import="net.sf.basedb.core.query.Restriction" |
---|
45 | import="net.sf.basedb.core.query.Restrictions" |
---|
46 | import="net.sf.basedb.util.Enumeration" |
---|
47 | import="net.sf.basedb.util.ShareableUtil" |
---|
48 | import="net.sf.basedb.clients.web.Base" |
---|
49 | import="net.sf.basedb.clients.web.ModeInfo" |
---|
50 | import="net.sf.basedb.clients.web.util.HTML" |
---|
51 | import="net.sf.basedb.util.Values" |
---|
52 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
53 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
54 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
55 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
56 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
57 | import="java.util.Set" |
---|
58 | import="java.util.HashSet" |
---|
59 | import="java.util.Iterator" |
---|
60 | %> |
---|
61 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
62 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
63 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
64 | <%! |
---|
65 | private static final Item itemType = Item.SYSTEM; |
---|
66 | private static final String subContext = "allitems"; |
---|
67 | |
---|
68 | private static final Enumeration<String, String> items = new Enumeration<String, String>(); |
---|
69 | static |
---|
70 | { |
---|
71 | for (Item item : Metadata.getOwnableItems()) |
---|
72 | { |
---|
73 | items.add(item.name(), item.toString()); |
---|
74 | } |
---|
75 | } |
---|
76 | %> |
---|
77 | <% |
---|
78 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
79 | final String ID = sc.getId(); |
---|
80 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null); |
---|
81 | final ModeInfo mode = ModeInfo.get(request.getParameter("mode")); |
---|
82 | final DbControl dc = sc.newDbControl(); |
---|
83 | ResultList<Ownable> allItems = null; |
---|
84 | try |
---|
85 | { |
---|
86 | long totalCount = 0; |
---|
87 | try |
---|
88 | { |
---|
89 | String filterItem = cc.getPropertyValue("type"); |
---|
90 | Set<Item> itemTypes = null; |
---|
91 | if (filterItem != null) |
---|
92 | { |
---|
93 | itemTypes = new HashSet<Item>(); |
---|
94 | for (String name : filterItem.split("\\|")) |
---|
95 | { |
---|
96 | itemTypes.add(Item.valueOf(name)); |
---|
97 | } |
---|
98 | } |
---|
99 | Restriction sharedTo = cc.getFilterRestriction("!sharedTo.name", dc, null); |
---|
100 | Restriction name = cc.getFilterRestriction("name", dc, null); |
---|
101 | Restriction description = cc.getFilterRestriction("description", dc, null); |
---|
102 | Restriction id = cc.getFilterRestriction("id", dc, null); |
---|
103 | Restriction restriction = Restrictions.nullSafeAnd(sharedTo, name, description, id); |
---|
104 | if (sharedTo != null) |
---|
105 | { |
---|
106 | // If we filter on "Shared to" we must make sure to only |
---|
107 | // include Shareable items in the query |
---|
108 | if (itemTypes != null) |
---|
109 | { |
---|
110 | itemTypes.retainAll(Metadata.getShareableItems()); |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | itemTypes = Metadata.getShareableItems(); |
---|
115 | } |
---|
116 | } |
---|
117 | User loggedInUser = User.getById(dc, sc.getLoggedInUserId()); |
---|
118 | if (itemTypes == null || itemTypes.size() > 0) |
---|
119 | { |
---|
120 | allItems = loggedInUser.getItems(itemTypes, cc.getPage() * cc.getRowsPerPage(), |
---|
121 | cc.getRowsPerPage(), null, restriction); |
---|
122 | } |
---|
123 | totalCount = allItems.getTotalCount(); |
---|
124 | } |
---|
125 | catch (Throwable t) |
---|
126 | { |
---|
127 | cc.setMessage(t.getMessage()); |
---|
128 | } |
---|
129 | int numListed = 0; |
---|
130 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext); |
---|
131 | ExtensionsInvoker invoker = ExtensionsControl.useExtensions(jspContext, |
---|
132 | "net.sf.basedb.clients.web.toolbar.list.all", |
---|
133 | "net.sf.basedb.clients.web.toolbar.list.allitems"); |
---|
134 | %> |
---|
135 | <base:page title="All items"> |
---|
136 | <base:head scripts="menu.js,table.js" styles="menu.css,table.css,toolbar.css"> |
---|
137 | <ext:scripts context="<%=jspContext%>" /> |
---|
138 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
139 | <script language="JavaScript"> |
---|
140 | var submitPage = 'index.jsp'; |
---|
141 | var formId = 'allItems'; |
---|
142 | function itemOnClick(evt, itemId) |
---|
143 | { |
---|
144 | viewItem(itemId); |
---|
145 | } |
---|
146 | function deleteAllItems() |
---|
147 | { |
---|
148 | if (!confirm('You are about to PERMANENTLY DELETE all item.\n This can\'t be undone. Continue?')) |
---|
149 | { |
---|
150 | return; |
---|
151 | } |
---|
152 | var frm = document.forms[formId]; |
---|
153 | frm.action = submitPage; |
---|
154 | frm.cmd.value = 'DeleteAllPermanently'; |
---|
155 | frm.submit(); |
---|
156 | } |
---|
157 | function deleteItems() |
---|
158 | { |
---|
159 | var frm = document.forms[formId]; |
---|
160 | var numChecked = Forms.numChecked(frm, /item:/); |
---|
161 | if (numChecked == 0) |
---|
162 | { |
---|
163 | alert('Please select at least one item in the list'); |
---|
164 | return; |
---|
165 | } |
---|
166 | frm.action = submitPage; |
---|
167 | frm.cmd.value = 'DeleteItems'; |
---|
168 | frm.submit(); |
---|
169 | } |
---|
170 | function restoreItems() |
---|
171 | { |
---|
172 | var frm = document.forms[formId]; |
---|
173 | if (Forms.numChecked(frm, /item:/) == 0) |
---|
174 | { |
---|
175 | alert('Please select at least one item in the list'); |
---|
176 | return; |
---|
177 | } |
---|
178 | frm.action = submitPage; |
---|
179 | frm.cmd.value = 'RestoreItems'; |
---|
180 | frm.submit(); |
---|
181 | } |
---|
182 | function deleteItemPermanently(itemType, itemId) |
---|
183 | { |
---|
184 | Main.deleteItemPermanently('<%=ID%>', true, itemType, itemId); |
---|
185 | } |
---|
186 | function shareItem(itemType, itemId) |
---|
187 | { |
---|
188 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&&item_type='+itemType+'&item_id='+itemId, 'ShareItem', 600, 400); |
---|
189 | } |
---|
190 | function shareItems() |
---|
191 | { |
---|
192 | Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems', /item:/); |
---|
193 | } |
---|
194 | function setOwner() |
---|
195 | { |
---|
196 | Table.setOwnerOfItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'SetOwnerOfItems', /item:/); |
---|
197 | } |
---|
198 | function configureColumns() |
---|
199 | { |
---|
200 | Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
201 | } |
---|
202 | function presetOnChange() |
---|
203 | { |
---|
204 | Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
205 | } |
---|
206 | </script> |
---|
207 | </base:head> |
---|
208 | |
---|
209 | <base:body> |
---|
210 | <% |
---|
211 | if (cc.getMessage() != null) |
---|
212 | { |
---|
213 | %> |
---|
214 | <div class="error"><%=HTML.encodeTags(cc.getMessage())%></div> |
---|
215 | <% |
---|
216 | cc.setMessage(null); |
---|
217 | } |
---|
218 | %> |
---|
219 | <tbl:table |
---|
220 | id="allItems" |
---|
221 | |
---|
222 | columns="<%=cc.getSetting("columns")%>" |
---|
223 | action="index.jsp" |
---|
224 | sc="<%=sc%>" |
---|
225 | item="<%=itemType%>" |
---|
226 | subcontext="<%=subContext%>" |
---|
227 | > |
---|
228 | <tbl:columndef |
---|
229 | id="type" |
---|
230 | property="type" |
---|
231 | datatype="string" |
---|
232 | title="Item type" |
---|
233 | enumeration="<%=items%>" |
---|
234 | filterable="true" |
---|
235 | show="always" |
---|
236 | /> |
---|
237 | <tbl:columndef |
---|
238 | id="name" |
---|
239 | title="Name" |
---|
240 | property="name" |
---|
241 | filterable="true" |
---|
242 | datatype="string" |
---|
243 | show="always" |
---|
244 | /> |
---|
245 | <tbl:columndef |
---|
246 | id="id" |
---|
247 | property="id" |
---|
248 | datatype="int" |
---|
249 | title="ID" |
---|
250 | filterable="true" |
---|
251 | /> |
---|
252 | <tbl:columndef |
---|
253 | id="description" |
---|
254 | title="Description" |
---|
255 | property="description" |
---|
256 | filterable="true" |
---|
257 | datatype="string" |
---|
258 | /> |
---|
259 | <tbl:columndef |
---|
260 | id="sharedTo" |
---|
261 | title="Shared to" |
---|
262 | filterable="true" |
---|
263 | filterproperty="!sharedTo.name" |
---|
264 | datatype="string" |
---|
265 | /> |
---|
266 | <tbl:toolbar> |
---|
267 | <tbl:button |
---|
268 | image="delete.png" |
---|
269 | onclick="deleteItems()" |
---|
270 | title="Delete" |
---|
271 | tooltip="Mark the selected items for deletion" |
---|
272 | disabled="<%=totalCount <= 0%>" |
---|
273 | /> |
---|
274 | <tbl:button |
---|
275 | image="restore.png" |
---|
276 | onclick="restoreItems()" |
---|
277 | title="Restore" |
---|
278 | tooltip="Restore the selected items" |
---|
279 | disabled="<%=totalCount <= 0%>" |
---|
280 | /> |
---|
281 | <tbl:button |
---|
282 | image="share.png" |
---|
283 | onclick="shareItems()" |
---|
284 | title="Share…" |
---|
285 | tooltip="Share the selected items" |
---|
286 | disabled="<%=totalCount <= 0%>" |
---|
287 | /> |
---|
288 | <tbl:button |
---|
289 | image="take_ownership.png" |
---|
290 | onclick="setOwner()" |
---|
291 | title="Set owner…" |
---|
292 | tooltip="Change owner of the selected items" |
---|
293 | /> |
---|
294 | <tbl:button |
---|
295 | image="columns.png" |
---|
296 | onclick="configureColumns()" |
---|
297 | title="Columns…" |
---|
298 | tooltip="Show, hide and re-order columns" |
---|
299 | /> |
---|
300 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
301 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
302 | </tbl:toolbar> |
---|
303 | <tbl:navigator |
---|
304 | page="<%=cc.getPage()%>" |
---|
305 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
306 | totalrows="<%=allItems == null ? 0 : allItems.getTotalCount()%>" |
---|
307 | /> |
---|
308 | <tbl:data> |
---|
309 | <tbl:headers> |
---|
310 | <tbl:headerrow> |
---|
311 | <tbl:header colspan="3" /> |
---|
312 | <tbl:columnheaders /> |
---|
313 | </tbl:headerrow> |
---|
314 | <tbl:headerrow> |
---|
315 | <tbl:header subclass="index" /> |
---|
316 | <tbl:header |
---|
317 | subclass="check" |
---|
318 | ><base:icon |
---|
319 | image="check_uncheck.png" |
---|
320 | tooltip="Check/uncheck all" |
---|
321 | onclick="Forms.checkUncheck(document.forms[formId])" |
---|
322 | /></tbl:header> |
---|
323 | <tbl:header |
---|
324 | subclass="check" |
---|
325 | visible="<%=mode.hasRadio()%>" |
---|
326 | /> |
---|
327 | <tbl:header |
---|
328 | subclass="icons" |
---|
329 | /> |
---|
330 | <tbl:propertyfilter /> |
---|
331 | </tbl:headerrow> |
---|
332 | </tbl:headers> |
---|
333 | <tbl:rows> |
---|
334 | <% |
---|
335 | int index = cc.getPage()*cc.getRowsPerPage(); |
---|
336 | if (allItems != null) |
---|
337 | { |
---|
338 | for (Ownable item : allItems) |
---|
339 | { |
---|
340 | BasicItem basicItem = (BasicItem)item; |
---|
341 | boolean isRemoved = false; |
---|
342 | boolean isShared = false; |
---|
343 | boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION); |
---|
344 | int itemId = item.getId(); |
---|
345 | String openSharePopup = "shareItem('" + item.getType().name() + "', "+itemId+")"; |
---|
346 | String deletePermanently = "deleteItemPermanently('" + item.getType().name() + "', "+itemId+")"; |
---|
347 | boolean deletePermission = item.hasPermission(Permission.DELETE); |
---|
348 | String name = ""; |
---|
349 | String description = ""; |
---|
350 | if (item instanceof File) |
---|
351 | { |
---|
352 | File file = (File)item; |
---|
353 | name = file.getPath().toString(); |
---|
354 | description = file.getDescription(); |
---|
355 | } |
---|
356 | else if (item instanceof Directory) |
---|
357 | { |
---|
358 | Directory dir = (Directory)item; |
---|
359 | name = dir.getPath().toString(); |
---|
360 | description = dir.getDescription(); |
---|
361 | } |
---|
362 | else if (item instanceof Nameable) |
---|
363 | { |
---|
364 | Nameable nameable = (Nameable)item; |
---|
365 | name = nameable.getName(); |
---|
366 | description = nameable.getDescription(); |
---|
367 | } |
---|
368 | else |
---|
369 | { |
---|
370 | name = item.toString(); |
---|
371 | } |
---|
372 | if (item instanceof Removable) |
---|
373 | { |
---|
374 | isRemoved = ((Removable)item).isRemoved(); |
---|
375 | } |
---|
376 | if (item instanceof Shareable) |
---|
377 | { |
---|
378 | isShared = ((Shareable)item).isShared(); |
---|
379 | } |
---|
380 | String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, true); |
---|
381 | index++; |
---|
382 | numListed++; |
---|
383 | %> |
---|
384 | <tbl:row> |
---|
385 | <tbl:header |
---|
386 | clazz="index" |
---|
387 | ><%=index%></tbl:header> |
---|
388 | <tbl:header |
---|
389 | clazz="check" |
---|
390 | ><input |
---|
391 | type="checkbox" |
---|
392 | name="item:<%=item.getType().name()%>" |
---|
393 | value="<%=itemId%>" |
---|
394 | ></tbl:header> |
---|
395 | <tbl:header |
---|
396 | clazz="icons" |
---|
397 | ><base:icon |
---|
398 | image="deleted.png" |
---|
399 | onclick="<%=deletePermission ? deletePermanently : null%>" |
---|
400 | tooltip="This item has been marked for deletion" |
---|
401 | visible="<%=isRemoved%>" |
---|
402 | /><base:icon |
---|
403 | image="shared.png" |
---|
404 | onclick="<%=sharePermission ? openSharePopup : null%>" |
---|
405 | tooltip="This item is shared to other users, groups and/or projects" |
---|
406 | visible="<%=isShared%>" |
---|
407 | /> </tbl:header> |
---|
408 | <tbl:cell column="type"><%=item.getType()%></tbl:cell> |
---|
409 | <tbl:cell column="name"><%=link%></tbl:cell> |
---|
410 | <tbl:cell column="id"><%=item.getId()%></tbl:cell> |
---|
411 | <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell> |
---|
412 | <tbl:cell column="sharedTo"> |
---|
413 | <% |
---|
414 | if (item instanceof SharedItem) |
---|
415 | { |
---|
416 | Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, (SharedItem)item).iterator(); |
---|
417 | while(sharees.hasNext()) |
---|
418 | { |
---|
419 | Nameable n = sharees.next(); |
---|
420 | if (mode.hasPropertyLink()) |
---|
421 | { |
---|
422 | out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink())); |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | out.write(HTML.encodeTags(n.getName())); |
---|
427 | } |
---|
428 | out.write(sharees.hasNext() ? ", " : ""); |
---|
429 | } |
---|
430 | } |
---|
431 | %> |
---|
432 | </tbl:cell> |
---|
433 | </tbl:row> |
---|
434 | <% |
---|
435 | } |
---|
436 | } |
---|
437 | %> |
---|
438 | </tbl:rows> |
---|
439 | </tbl:data> |
---|
440 | <% |
---|
441 | if (numListed == 0) |
---|
442 | { |
---|
443 | %> |
---|
444 | <tbl:panel><%=allItems == null || allItems.size() == 0 ? "No items were found" : "No items on this page. Please select another page!" %></tbl:panel> |
---|
445 | <% |
---|
446 | } |
---|
447 | else |
---|
448 | { |
---|
449 | %> |
---|
450 | <tbl:navigator |
---|
451 | page="<%=cc.getPage()%>" |
---|
452 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
453 | totalrows="<%=allItems == null ? 0 : allItems.getTotalCount()%>" |
---|
454 | locked="true" |
---|
455 | /> |
---|
456 | <% |
---|
457 | } |
---|
458 | %> |
---|
459 | </tbl:table> |
---|
460 | |
---|
461 | </base:body> |
---|
462 | </base:page> |
---|
463 | <% |
---|
464 | } |
---|
465 | finally |
---|
466 | { |
---|
467 | if (dc != null) dc.close(); |
---|
468 | } |
---|
469 | %> |
---|