1 | <%-- $Id: list_items.jsp 3501 2007-06-15 09:16:30Z enell $ |
---|
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.Trashcan" |
---|
31 | import="net.sf.basedb.core.Item" |
---|
32 | import="net.sf.basedb.core.ItemContext" |
---|
33 | import="net.sf.basedb.core.Permission" |
---|
34 | import="net.sf.basedb.core.Project" |
---|
35 | import="net.sf.basedb.core.BasicItem" |
---|
36 | import="net.sf.basedb.core.Shareable" |
---|
37 | import="net.sf.basedb.core.Nameable" |
---|
38 | import="net.sf.basedb.core.Removable" |
---|
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.query.ResultList" |
---|
43 | import="net.sf.basedb.util.Enumeration" |
---|
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 | %> |
---|
49 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
50 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
51 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
52 | <%@ taglib prefix="p" uri="/WEB-INF/path.tld" %> |
---|
53 | <%! |
---|
54 | private static final Item itemType = Item.PROJECT; |
---|
55 | private static final String subContext = "items"; |
---|
56 | |
---|
57 | private static final Enumeration<String, String> itemTypes = new Enumeration<String, String>(); |
---|
58 | static |
---|
59 | { |
---|
60 | for (Item item : Metadata.getShareableItems()) |
---|
61 | { |
---|
62 | itemTypes.add(item.name(), item.toString()); |
---|
63 | } |
---|
64 | } |
---|
65 | %> |
---|
66 | <% |
---|
67 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
68 | final String ID = sc.getId(); |
---|
69 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, null, null); |
---|
70 | final int projectId = Values.getInt(request.getParameter("project_id")); |
---|
71 | final int activeProjectId = sc.getActiveProjectId(); |
---|
72 | final DbControl dc = sc.newDbControl(); |
---|
73 | ResultList<Shareable> items = null; |
---|
74 | try |
---|
75 | { |
---|
76 | String filterItem = cc.getPropertyValue("type"); |
---|
77 | Project project = Project.getById(dc, projectId); |
---|
78 | try |
---|
79 | { |
---|
80 | items = project.getItems(filterItem == null ? null : Item.valueOf(filterItem), |
---|
81 | cc.getPage() * cc.getRowsPerPage(), cc.getRowsPerPage(), cc.getItemPermission(), |
---|
82 | cc.getInclude()); |
---|
83 | } |
---|
84 | catch (Throwable t) |
---|
85 | { |
---|
86 | cc.setMessage(t.getMessage()); |
---|
87 | } |
---|
88 | int numListed = 0; |
---|
89 | %> |
---|
90 | <base:page> |
---|
91 | <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css"> |
---|
92 | <script language="JavaScript"> |
---|
93 | var submitPage = 'index.jsp'; |
---|
94 | var formId = 'items'; |
---|
95 | function deleteItems() |
---|
96 | { |
---|
97 | var frm = document.forms[formId]; |
---|
98 | var numChecked = Forms.numChecked(frm, /item:/); |
---|
99 | if (numChecked == 0) |
---|
100 | { |
---|
101 | alert('Please select at least one item in the list'); |
---|
102 | return; |
---|
103 | } |
---|
104 | frm.action = submitPage; |
---|
105 | frm.cmd.value = 'DeleteItems'; |
---|
106 | frm.submit(); |
---|
107 | } |
---|
108 | function restoreItems() |
---|
109 | { |
---|
110 | var frm = document.forms[formId]; |
---|
111 | if (Forms.numChecked(frm, /item:/) == 0) |
---|
112 | { |
---|
113 | alert('Please select at least one item in the list'); |
---|
114 | return; |
---|
115 | } |
---|
116 | frm.action = submitPage; |
---|
117 | frm.cmd.value = 'RestoreItems'; |
---|
118 | frm.submit(); |
---|
119 | } |
---|
120 | function takeOwnership() |
---|
121 | { |
---|
122 | var frm = document.forms[formId]; |
---|
123 | if (Forms.numChecked(frm, /item:/) == 0) |
---|
124 | { |
---|
125 | alert('Please select at least one item in the list'); |
---|
126 | return; |
---|
127 | } |
---|
128 | if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.')) |
---|
129 | { |
---|
130 | frm.action = submitPage; |
---|
131 | frm.cmd.value = 'TakeOwnershipOfItems'; |
---|
132 | frm.submit(); |
---|
133 | } |
---|
134 | } |
---|
135 | function shareItem(itemId) |
---|
136 | { |
---|
137 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareProjectItems', 500, 400); |
---|
138 | } |
---|
139 | function shareItems() |
---|
140 | { |
---|
141 | Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems', /item:/); |
---|
142 | } |
---|
143 | function configureColumns() |
---|
144 | { |
---|
145 | Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
146 | } |
---|
147 | function presetOnChange() |
---|
148 | { |
---|
149 | Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>', '<%=subContext%>'); |
---|
150 | } |
---|
151 | function setToActive() |
---|
152 | { |
---|
153 | Main.openPopup('../set_active.jsp?ID=<%=ID%>&project_id=<%=projectId%>', 'ActivateProject', 300, 140); |
---|
154 | } |
---|
155 | function switchTab(tabControlId, tabId) |
---|
156 | { |
---|
157 | if (tabId == 'properties') |
---|
158 | { |
---|
159 | location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=projectId%>&tab='+tabId; |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | TabControl.setActiveTab(tabControlId, tabId); |
---|
164 | } |
---|
165 | } |
---|
166 | </script> |
---|
167 | </base:head> |
---|
168 | |
---|
169 | <base:body> |
---|
170 | <p> |
---|
171 | <p:path> |
---|
172 | <p:pathelement title="Projects" href="<%="../index.jsp?ID="+ID%>" /> |
---|
173 | <p:pathelement title="<%=HTML.encodeTags(project.getName())%>" /> |
---|
174 | </p:path> |
---|
175 | |
---|
176 | <t:tabcontrol id="main" active="items" switch="switchTab"> |
---|
177 | <t:tab id="properties" title="Properties" /> |
---|
178 | |
---|
179 | <t:tab id="items" title="Items"> |
---|
180 | |
---|
181 | <% |
---|
182 | if (cc.getMessage() != null) |
---|
183 | { |
---|
184 | %> |
---|
185 | <div class="error"><%=cc.getMessage()%></div> |
---|
186 | <% |
---|
187 | cc.setMessage(null); |
---|
188 | } |
---|
189 | %> |
---|
190 | <tbl:table |
---|
191 | id="items" |
---|
192 | clazz="itemlist" |
---|
193 | columns="<%=cc.getSetting("columns")%>" |
---|
194 | action="index.jsp" |
---|
195 | sc="<%=sc%>" |
---|
196 | item="<%=itemType%>" |
---|
197 | subcontext="<%=subContext%>" |
---|
198 | > |
---|
199 | <tbl:hidden |
---|
200 | name="project_id" |
---|
201 | value="<%=Integer.toString(projectId)%>" |
---|
202 | /> |
---|
203 | <tbl:columndef |
---|
204 | id="type" |
---|
205 | property="type" |
---|
206 | datatype="string" |
---|
207 | title="Item type" |
---|
208 | enumeration="<%=itemTypes%>" |
---|
209 | filterable="true" |
---|
210 | show="always" |
---|
211 | /> |
---|
212 | <tbl:columndef |
---|
213 | id="name" |
---|
214 | title="Name" |
---|
215 | show="always" |
---|
216 | /> |
---|
217 | <tbl:columndef |
---|
218 | id="owner" |
---|
219 | title="Owner" |
---|
220 | /> |
---|
221 | <tbl:columndef |
---|
222 | id="description" |
---|
223 | title="Description" |
---|
224 | /> |
---|
225 | <tbl:columndef |
---|
226 | id="permission" |
---|
227 | title="Permission" |
---|
228 | /> |
---|
229 | <tbl:toolbar> |
---|
230 | <tbl:button |
---|
231 | image="delete.gif" |
---|
232 | onclick="deleteItems()" |
---|
233 | title="Delete" |
---|
234 | tooltip="Delete the selected items" |
---|
235 | /> |
---|
236 | <tbl:button |
---|
237 | image="restore.gif" |
---|
238 | onclick="restoreItems()" |
---|
239 | title="Restore" |
---|
240 | tooltip="Restore the selected items" |
---|
241 | /> |
---|
242 | <tbl:button |
---|
243 | image="share.gif" |
---|
244 | onclick="shareItems()" |
---|
245 | title="Share…" |
---|
246 | tooltip="Share the selected items" |
---|
247 | /> |
---|
248 | <tbl:button |
---|
249 | image="take_ownership.png" |
---|
250 | onclick="takeOwnership()" |
---|
251 | title="Take ownership…" |
---|
252 | tooltip="Take ownership of the selected items" |
---|
253 | /> |
---|
254 | <tbl:button |
---|
255 | image="columns.gif" |
---|
256 | onclick="configureColumns()" |
---|
257 | title="Columns…" |
---|
258 | tooltip="Show, hide and re-order columns" |
---|
259 | /> |
---|
260 | </tbl:toolbar> |
---|
261 | <% |
---|
262 | if (projectId != activeProjectId) |
---|
263 | { |
---|
264 | %> |
---|
265 | <tbl:panel> |
---|
266 | <div class="error" onclick="setToActive()" style="cursor: pointer;" |
---|
267 | title="Click to make this project the active project"> |
---|
268 | This project is not the active project. The list can't display items |
---|
269 | that are owned by other members of the project. |
---|
270 | </div> |
---|
271 | </tbl:panel> |
---|
272 | <% |
---|
273 | } |
---|
274 | %> |
---|
275 | <tbl:navigator |
---|
276 | page="<%=cc.getPage()%>" |
---|
277 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
278 | totalrows="<%=items == null ? 0 : items.getTotalCount()%>" |
---|
279 | /> |
---|
280 | <tbl:data> |
---|
281 | <tbl:columns> |
---|
282 | <tbl:presetselector |
---|
283 | clazz="columnheader" |
---|
284 | colspan="3" |
---|
285 | onchange="presetOnChange()" |
---|
286 | disablesharedto="true" |
---|
287 | disableothers="<%=projectId != activeProjectId%>" |
---|
288 | /> |
---|
289 | </tbl:columns> |
---|
290 | <tr> |
---|
291 | <tbl:header |
---|
292 | clazz="index" |
---|
293 | > </tbl:header> |
---|
294 | <tbl:header |
---|
295 | clazz="check" |
---|
296 | ><base:icon |
---|
297 | image="check_uncheck.gif" |
---|
298 | tooltip="Check/uncheck all" |
---|
299 | onclick="Forms.checkUncheck(document.forms[formId], /item:/)" style="align: left;" |
---|
300 | /></tbl:header> |
---|
301 | <tbl:header |
---|
302 | clazz="icons" |
---|
303 | > </tbl:header> |
---|
304 | |
---|
305 | <tbl:propertyfilter /> |
---|
306 | </tr> |
---|
307 | |
---|
308 | <tbl:rows> |
---|
309 | <% |
---|
310 | int index = cc.getPage()*cc.getRowsPerPage(); |
---|
311 | if (items != null) |
---|
312 | { |
---|
313 | for (Shareable item : items) |
---|
314 | { |
---|
315 | BasicItem basicItem = (BasicItem)item; |
---|
316 | int itemId = item.getId(); |
---|
317 | boolean removed = item instanceof Removable && ((Removable)item).isRemoved(); |
---|
318 | String name = ""; |
---|
319 | String description = ""; |
---|
320 | if (item instanceof File) |
---|
321 | { |
---|
322 | File file = (File)item; |
---|
323 | name = file.getPath().toString(); |
---|
324 | description = file.getDescription(); |
---|
325 | } |
---|
326 | else if (item instanceof Directory) |
---|
327 | { |
---|
328 | Directory dir = (Directory)item; |
---|
329 | name = dir.getPath().toString(); |
---|
330 | description = dir.getDescription(); |
---|
331 | } |
---|
332 | else if (item instanceof Nameable) |
---|
333 | { |
---|
334 | Nameable nameable = (Nameable)item; |
---|
335 | name = nameable.getName(); |
---|
336 | description = nameable.getDescription(); |
---|
337 | } |
---|
338 | else |
---|
339 | { |
---|
340 | name = item.toString(); |
---|
341 | } |
---|
342 | String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, true); |
---|
343 | index++; |
---|
344 | numListed++; |
---|
345 | %> |
---|
346 | <tbl:row> |
---|
347 | <tbl:header |
---|
348 | clazz="index" |
---|
349 | ><%=index%></tbl:header> |
---|
350 | <tbl:header |
---|
351 | clazz="check" |
---|
352 | ><input |
---|
353 | type="checkbox" |
---|
354 | name="item:<%=item.getType().name()%>" |
---|
355 | value="<%=itemId%>" |
---|
356 | ></tbl:header> |
---|
357 | <tbl:header |
---|
358 | clazz="icons" |
---|
359 | ><base:icon |
---|
360 | image="deleted.gif" |
---|
361 | tooltip="This item has been scheduled for deletion" |
---|
362 | visible="<%=removed%>" |
---|
363 | /> </tbl:header> |
---|
364 | <tbl:cell column="type"><%=item.getType()%></tbl:cell> |
---|
365 | <tbl:cell column="name"><%=link%></tbl:cell> |
---|
366 | <tbl:cell column="owner"><base:propertyvalue item="<%=item%>" property="owner" /></tbl:cell> |
---|
367 | <tbl:cell column="description"><%=HTML.encodeTags(description)%></tbl:cell> |
---|
368 | <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell> |
---|
369 | </tbl:row> |
---|
370 | <% |
---|
371 | } |
---|
372 | } |
---|
373 | %> |
---|
374 | </tbl:rows> |
---|
375 | </tbl:data> |
---|
376 | <% |
---|
377 | if (numListed == 0) |
---|
378 | { |
---|
379 | %> |
---|
380 | <tbl:panel><%=items == null || items.size() == 0 ? "No items were found" : "No items on this page. Please select another page!" %></tbl:panel> |
---|
381 | <% |
---|
382 | } |
---|
383 | else |
---|
384 | { |
---|
385 | %> |
---|
386 | <tbl:navigator |
---|
387 | page="<%=cc.getPage()%>" |
---|
388 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
389 | totalrows="<%=items == null ? 0 : items.getTotalCount()%>" |
---|
390 | locked="true" |
---|
391 | /> |
---|
392 | <% |
---|
393 | } |
---|
394 | %> |
---|
395 | </tbl:table> |
---|
396 | |
---|
397 | </t:tab> |
---|
398 | </t:tabcontrol> |
---|
399 | |
---|
400 | </base:body> |
---|
401 | </base:page> |
---|
402 | <% |
---|
403 | } |
---|
404 | finally |
---|
405 | { |
---|
406 | if (dc != null) dc.close(); |
---|
407 | } |
---|
408 | %> |
---|