1 | <%-- $Id $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2011 Nicklas Nordborg |
---|
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 3 |
---|
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 BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | ------------------------------------------------------------------ |
---|
21 | |
---|
22 | --%> |
---|
23 | <%@ page pageEncoding="UTF-8" session="false" |
---|
24 | import="net.sf.basedb.core.SessionControl" |
---|
25 | import="net.sf.basedb.core.DbControl" |
---|
26 | import="net.sf.basedb.core.Item" |
---|
27 | import="net.sf.basedb.core.ReporterCloneTemplate" |
---|
28 | import="net.sf.basedb.core.ItemQuery" |
---|
29 | import="net.sf.basedb.core.Include" |
---|
30 | import="net.sf.basedb.core.ItemResultIterator" |
---|
31 | import="net.sf.basedb.core.ItemResultList" |
---|
32 | import="net.sf.basedb.core.ItemContext" |
---|
33 | import="net.sf.basedb.core.Nameable" |
---|
34 | import="net.sf.basedb.core.Permission" |
---|
35 | import="net.sf.basedb.core.PluginDefinition" |
---|
36 | import="net.sf.basedb.core.query.Orders" |
---|
37 | import="net.sf.basedb.core.query.Hql" |
---|
38 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
39 | import="net.sf.basedb.core.plugin.Plugin" |
---|
40 | import="net.sf.basedb.util.Enumeration" |
---|
41 | import="net.sf.basedb.util.ShareableUtil" |
---|
42 | import="net.sf.basedb.clients.web.Base" |
---|
43 | import="net.sf.basedb.clients.web.ModeInfo" |
---|
44 | import="net.sf.basedb.clients.web.PermissionUtil" |
---|
45 | import="net.sf.basedb.clients.web.util.HTML" |
---|
46 | import="net.sf.basedb.util.Values" |
---|
47 | import="net.sf.basedb.util.formatter.Formatter" |
---|
48 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
49 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
50 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
51 | import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer" |
---|
52 | import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil" |
---|
53 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
54 | import="java.util.Date" |
---|
55 | import="java.util.Iterator" |
---|
56 | import="java.util.List" |
---|
57 | import="java.util.Map" |
---|
58 | %> |
---|
59 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
60 | <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
---|
61 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
62 | <%! |
---|
63 | private static final Item itemType = Item.REPORTERCLONETEMPLATE; |
---|
64 | private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST); |
---|
65 | %> |
---|
66 | <% |
---|
67 | final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType); |
---|
68 | final String ID = sc.getId(); |
---|
69 | final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType); |
---|
70 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
71 | |
---|
72 | final ModeInfo mode = ModeInfo.get(request.getParameter("mode")); |
---|
73 | final String callback = request.getParameter("callback"); |
---|
74 | final String title = mode.generateTitle("reporter clone template", "reporter clone templates"); |
---|
75 | final DbControl dc = sc.newDbControl(); |
---|
76 | ItemResultIterator<ReporterCloneTemplate> templates = null; |
---|
77 | try |
---|
78 | { |
---|
79 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
80 | |
---|
81 | Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext); |
---|
82 | try |
---|
83 | { |
---|
84 | final ItemQuery<ReporterCloneTemplate> query = Base.getConfiguredQuery(dc, cc, true, ReporterCloneTemplate.getQuery(), mode); |
---|
85 | templates = query.iterate(dc); |
---|
86 | } |
---|
87 | catch (Throwable t) |
---|
88 | { |
---|
89 | cc.setMessage(t.getMessage()); |
---|
90 | } |
---|
91 | int numListed = 0; |
---|
92 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null); |
---|
93 | ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext); |
---|
94 | %> |
---|
95 | <base:page title="<%=title==null ? "Reporter clone templates" : title%>" type="<%=mode.getPageType()%>"> |
---|
96 | <base:head scripts="menu.js,table.js" styles="menu.css,table.css"> |
---|
97 | <ext:scripts context="<%=jspContext%>" /> |
---|
98 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
99 | <script language="JavaScript"> |
---|
100 | var submitPage = 'index.jsp'; |
---|
101 | var formId = 'templates'; |
---|
102 | function newItem() |
---|
103 | { |
---|
104 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true); |
---|
105 | } |
---|
106 | function editItem(itemId) |
---|
107 | { |
---|
108 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true); |
---|
109 | } |
---|
110 | function viewItem(itemId) |
---|
111 | { |
---|
112 | Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false); |
---|
113 | } |
---|
114 | function itemOnClick(evt, itemId) |
---|
115 | { |
---|
116 | Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected); |
---|
117 | } |
---|
118 | function deleteItems() |
---|
119 | { |
---|
120 | var frm = document.forms[formId]; |
---|
121 | if (Forms.numChecked(frm) == 0) |
---|
122 | { |
---|
123 | alert('Please select at least one item in the list'); |
---|
124 | return; |
---|
125 | } |
---|
126 | frm.action = submitPage; |
---|
127 | frm.cmd.value = 'DeleteItems'; |
---|
128 | frm.submit(); |
---|
129 | } |
---|
130 | function restoreItems() |
---|
131 | { |
---|
132 | var frm = document.forms[formId]; |
---|
133 | if (Forms.numChecked(frm) == 0) |
---|
134 | { |
---|
135 | alert('Please select at least one item in the list'); |
---|
136 | return; |
---|
137 | } |
---|
138 | frm.action = submitPage; |
---|
139 | frm.cmd.value = 'RestoreItems'; |
---|
140 | frm.submit(); |
---|
141 | } |
---|
142 | function deleteItemPermanently(itemId) |
---|
143 | { |
---|
144 | Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', itemId); |
---|
145 | } |
---|
146 | function setOwner() |
---|
147 | { |
---|
148 | Table.setOwnerOfItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'SetOwnerOfItems'); |
---|
149 | } |
---|
150 | function shareItem(itemId) |
---|
151 | { |
---|
152 | Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareReporterCloneTemplates', 600, 400); |
---|
153 | } |
---|
154 | function shareItems() |
---|
155 | { |
---|
156 | Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems'); |
---|
157 | } |
---|
158 | function configureColumns() |
---|
159 | { |
---|
160 | Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>'); |
---|
161 | } |
---|
162 | function runPlugin(cmd) |
---|
163 | { |
---|
164 | Table.submitToPopup(formId, cmd, 740, 540); |
---|
165 | } |
---|
166 | function returnSelected() |
---|
167 | { |
---|
168 | Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>); |
---|
169 | window.close(); |
---|
170 | } |
---|
171 | function presetOnChange() |
---|
172 | { |
---|
173 | Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>'); |
---|
174 | } |
---|
175 | </script> |
---|
176 | </base:head> |
---|
177 | |
---|
178 | <base:body> |
---|
179 | <% |
---|
180 | if (cc.getMessage() != null) |
---|
181 | { |
---|
182 | %> |
---|
183 | <div class="error"><%=cc.getMessage()%></div> |
---|
184 | <% |
---|
185 | cc.setMessage(null); |
---|
186 | } |
---|
187 | %> |
---|
188 | <tbl:table |
---|
189 | id="templates" |
---|
190 | clazz="itemlist" |
---|
191 | columns="<%=cc.getSetting("columns")%>" |
---|
192 | sortby="<%=cc.getSortProperty()%>" |
---|
193 | direction="<%=cc.getSortDirection()%>" |
---|
194 | title="<%=title%>" |
---|
195 | action="index.jsp" |
---|
196 | sc="<%=sc%>" |
---|
197 | item="<%=itemType%>" |
---|
198 | > |
---|
199 | <tbl:hidden |
---|
200 | name="mode" |
---|
201 | value="<%=mode.getName()%>" |
---|
202 | /> |
---|
203 | <tbl:hidden |
---|
204 | name="callback" |
---|
205 | value="<%=callback%>" |
---|
206 | skip="<%=callback == null%>" |
---|
207 | /> |
---|
208 | <tbl:columndef |
---|
209 | id="name" |
---|
210 | property="name" |
---|
211 | datatype="string" |
---|
212 | title="Name" |
---|
213 | sortable="true" |
---|
214 | filterable="true" |
---|
215 | exportable="true" |
---|
216 | show="always" |
---|
217 | /> |
---|
218 | <tbl:columndef |
---|
219 | id="id" |
---|
220 | clazz="uniquecol" |
---|
221 | property="id" |
---|
222 | datatype="int" |
---|
223 | title="ID" |
---|
224 | sortable="true" |
---|
225 | filterable="true" |
---|
226 | exportable="true" |
---|
227 | /> |
---|
228 | <tbl:columndef |
---|
229 | id="entryDate" |
---|
230 | property="entryDate" |
---|
231 | datatype="date" |
---|
232 | title="Registered" |
---|
233 | sortable="true" |
---|
234 | filterable="true" |
---|
235 | exportable="true" |
---|
236 | formatter="<%=dateFormatter%>" |
---|
237 | /> |
---|
238 | <tbl:columndef |
---|
239 | id="owner" |
---|
240 | property="owner.name" |
---|
241 | datatype="string" |
---|
242 | title="Owner" |
---|
243 | sortable="true" |
---|
244 | filterable="true" |
---|
245 | exportable="true" |
---|
246 | /> |
---|
247 | <tbl:columndef |
---|
248 | id="description" |
---|
249 | property="description" |
---|
250 | datatype="string" |
---|
251 | title="Description" |
---|
252 | sortable="true" |
---|
253 | filterable="true" |
---|
254 | exportable="true" |
---|
255 | /> |
---|
256 | <tbl:columndef |
---|
257 | id="permission" |
---|
258 | title="Permission" |
---|
259 | /> |
---|
260 | <tbl:columndef |
---|
261 | id="sharedTo" |
---|
262 | title="Shared to" |
---|
263 | filterable="true" |
---|
264 | filterproperty="!sharedTo.name" |
---|
265 | datatype="string" |
---|
266 | /> |
---|
267 | <tbl:toolbar |
---|
268 | visible="<%=mode.hasToolbar()%>" |
---|
269 | > |
---|
270 | <tbl:button |
---|
271 | disabled="<%=createPermission ? false : true%>" |
---|
272 | image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" |
---|
273 | onclick="newItem()" |
---|
274 | title="New…" |
---|
275 | tooltip="<%=createPermission ? "Create new template" : "You do not have permission to create templates"%>" |
---|
276 | /> |
---|
277 | <tbl:button |
---|
278 | image="delete.gif" |
---|
279 | onclick="deleteItems()" |
---|
280 | title="Delete" |
---|
281 | tooltip="Delete the selected items" |
---|
282 | /> |
---|
283 | <tbl:button |
---|
284 | image="restore.gif" |
---|
285 | onclick="restoreItems()" |
---|
286 | title="Restore" |
---|
287 | tooltip="Restore the selected (deleted) items" |
---|
288 | /> |
---|
289 | <tbl:button |
---|
290 | image="share.gif" |
---|
291 | onclick="shareItems()" |
---|
292 | title="Share…" |
---|
293 | tooltip="Share the selected items" |
---|
294 | /> |
---|
295 | <tbl:button |
---|
296 | image="take_ownership.png" |
---|
297 | onclick="setOwner()" |
---|
298 | title="Set owner…" |
---|
299 | tooltip="Change owner of the selected items" |
---|
300 | /> |
---|
301 | <tbl:button |
---|
302 | image="columns.gif" |
---|
303 | onclick="configureColumns()" |
---|
304 | title="Columns…" |
---|
305 | tooltip="Show, hide and re-order columns" |
---|
306 | /> |
---|
307 | <tbl:button |
---|
308 | image="import.gif" |
---|
309 | onclick="runPlugin('ImportItems')" |
---|
310 | title="Import…" |
---|
311 | tooltip="Import data" |
---|
312 | visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>" |
---|
313 | /> |
---|
314 | <tbl:button |
---|
315 | image="export.gif" |
---|
316 | onclick="runPlugin('ExportItems')" |
---|
317 | title="Export…" |
---|
318 | tooltip="Export data" |
---|
319 | visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>" |
---|
320 | /> |
---|
321 | <tbl:button |
---|
322 | image="runplugin.gif" |
---|
323 | onclick="runPlugin('RunListPlugin')" |
---|
324 | title="Run plugin…" |
---|
325 | tooltip="Run a plugin" |
---|
326 | visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>" |
---|
327 | /> |
---|
328 | <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" |
---|
329 | wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/> |
---|
330 | </tbl:toolbar> |
---|
331 | <tbl:navigator |
---|
332 | page="<%=cc.getPage()%>" |
---|
333 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
334 | totalrows="<%=templates == null ? 0 : templates.getTotalCount()%>" |
---|
335 | visible="<%=mode.hasNavigator()%>" |
---|
336 | /> |
---|
337 | <tbl:data> |
---|
338 | <tbl:columns> |
---|
339 | <tbl:presetselector |
---|
340 | clazz="columnheader" |
---|
341 | colspan="3" |
---|
342 | onchange="presetOnChange()" |
---|
343 | /> |
---|
344 | </tbl:columns> |
---|
345 | |
---|
346 | <tr> |
---|
347 | <tbl:header |
---|
348 | clazz="index" |
---|
349 | > </tbl:header> |
---|
350 | <tbl:header |
---|
351 | clazz="check" |
---|
352 | visible="<%=mode.hasCheck()%>" |
---|
353 | ><base:icon |
---|
354 | image="check_uncheck.gif" |
---|
355 | tooltip="Check/uncheck all" |
---|
356 | onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;" |
---|
357 | /></tbl:header> |
---|
358 | <tbl:header |
---|
359 | clazz="check" |
---|
360 | visible="<%=mode.hasRadio()%>" |
---|
361 | > </tbl:header> |
---|
362 | <tbl:header |
---|
363 | clazz="icons" |
---|
364 | visible="<%=mode.hasIcons()%>" |
---|
365 | > </tbl:header> |
---|
366 | <tbl:propertyfilter /> |
---|
367 | </tr> |
---|
368 | |
---|
369 | <tbl:rows> |
---|
370 | <% |
---|
371 | int index = cc.getPage()*cc.getRowsPerPage(); |
---|
372 | int selectedItemId = Values.getInt(request.getParameter("item_id")); |
---|
373 | if (templates != null) |
---|
374 | { |
---|
375 | while (templates.hasNext()) |
---|
376 | { |
---|
377 | ReporterCloneTemplate item = templates.next(); |
---|
378 | int itemId = item.getId(); |
---|
379 | String openSharePopup = "shareItem("+itemId+")"; |
---|
380 | String deletePermanently = "deleteItemPermanently("+itemId+")"; |
---|
381 | boolean deletePermission = item.hasPermission(Permission.DELETE); |
---|
382 | boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION); |
---|
383 | boolean writePermission = item.hasPermission(Permission.WRITE); |
---|
384 | String name = HTML.encodeTags(item.getName()); |
---|
385 | String tooltip = mode.isSelectionMode() ? |
---|
386 | "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : ""); |
---|
387 | index++; |
---|
388 | numListed++; |
---|
389 | %> |
---|
390 | <tbl:row> |
---|
391 | <tbl:header |
---|
392 | clazz="index" |
---|
393 | ><%=index%></tbl:header> |
---|
394 | <tbl:header |
---|
395 | clazz="check" |
---|
396 | visible="<%=mode.hasCheck()%>" |
---|
397 | ><input |
---|
398 | type="checkbox" |
---|
399 | name="<%=itemId%>" |
---|
400 | value="<%=itemId%>" |
---|
401 | title="<%=name%>" |
---|
402 | <%=cc.getSelected().contains(itemId) ? "checked" : ""%> |
---|
403 | ></tbl:header> |
---|
404 | <tbl:header |
---|
405 | clazz="check" |
---|
406 | visible="<%=mode.hasRadio()%>" |
---|
407 | ><input |
---|
408 | type="radio" |
---|
409 | name="item_id" |
---|
410 | value="<%=itemId%>" |
---|
411 | title="<%=name%>" |
---|
412 | <%=selectedItemId == itemId ? "checked" : ""%> |
---|
413 | ></tbl:header> |
---|
414 | <tbl:header |
---|
415 | clazz="icons" |
---|
416 | visible="<%=mode.hasIcons()%>" |
---|
417 | ><base:icon |
---|
418 | image="<%=deletePermission ? "deleted.gif" : "deleted_disabled.gif"%>" |
---|
419 | onclick="<%=deletePermission ? deletePermanently : null%>" |
---|
420 | tooltip="This item has been scheduled for deletion" |
---|
421 | visible="<%=item.isRemoved()%>" |
---|
422 | /><base:icon |
---|
423 | image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" |
---|
424 | onclick="<%=sharePermission ? openSharePopup : null%>" |
---|
425 | tooltip="This item is shared to other users, groups and/or projects" |
---|
426 | visible="<%=item.isShared()%>" |
---|
427 | /> </tbl:header> |
---|
428 | <tbl:cell column="name"><div class="link" |
---|
429 | onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" |
---|
430 | title="<%=tooltip%>"><%=name%></div></tbl:cell> |
---|
431 | <tbl:cell column="id"><%=item.getId()%></tbl:cell> |
---|
432 | <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" /> |
---|
433 | <tbl:cell column="owner" |
---|
434 | ><base:propertyvalue |
---|
435 | item="<%=item%>" |
---|
436 | property="owner" |
---|
437 | enableEditLink="<%=mode.hasEditLink()%>" |
---|
438 | enablePropertyLink="<%=mode.hasPropertyLink()%>" |
---|
439 | /></tbl:cell> |
---|
440 | <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell> |
---|
441 | <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell> |
---|
442 | <tbl:cell column="sharedTo"> |
---|
443 | <% |
---|
444 | Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator(); |
---|
445 | while(sharees.hasNext()) |
---|
446 | { |
---|
447 | Nameable n = sharees.next(); |
---|
448 | if (mode.hasPropertyLink()) |
---|
449 | { |
---|
450 | out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink())); |
---|
451 | } |
---|
452 | else |
---|
453 | { |
---|
454 | out.write(HTML.encodeTags(n.getName())); |
---|
455 | } |
---|
456 | out.write(sharees.hasNext() ? ", " : ""); |
---|
457 | } |
---|
458 | %> |
---|
459 | </tbl:cell> |
---|
460 | </tbl:row> |
---|
461 | <% |
---|
462 | } |
---|
463 | } |
---|
464 | %> |
---|
465 | </tbl:rows> |
---|
466 | </tbl:data> |
---|
467 | <% |
---|
468 | if (numListed == 0) |
---|
469 | { |
---|
470 | %> |
---|
471 | <tbl:panel><%=templates == null || templates.getTotalCount() == 0 ? "No templates were found" : "No templates on this page. Please select another page!" %></tbl:panel> |
---|
472 | <% |
---|
473 | } |
---|
474 | else |
---|
475 | { |
---|
476 | %> |
---|
477 | <tbl:navigator |
---|
478 | page="<%=cc.getPage()%>" |
---|
479 | rowsperpage="<%=cc.getRowsPerPage()%>" |
---|
480 | totalrows="<%=templates == null ? 0 : templates.getTotalCount()%>" |
---|
481 | visible="<%=mode.hasNavigator()%>" |
---|
482 | locked="true" |
---|
483 | /> |
---|
484 | <% |
---|
485 | } |
---|
486 | %> |
---|
487 | </tbl:table> |
---|
488 | <base:buttongroup align="center" clazz="fixedatbottom"> |
---|
489 | <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" /> |
---|
490 | <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" /> |
---|
491 | <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" /> |
---|
492 | </base:buttongroup> |
---|
493 | <br><br><br> |
---|
494 | </base:body> |
---|
495 | </base:page> |
---|
496 | <% |
---|
497 | } |
---|
498 | finally |
---|
499 | { |
---|
500 | if (templates != null) templates.close(); |
---|
501 | if (dc != null) dc.close(); |
---|
502 | } |
---|
503 | %> |
---|