source: trunk/www/views/trashcan/view_item.jsp @ 3548

Last change on this file since 3548 was 3548, checked in by Martin Svensson, 16 years ago

References #375.Missed one view-page in the last commit

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.0 KB
Line 
1<%-- $Id: view_item.jsp 3548 2007-07-04 09:36:49Z martin $
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.Group"
38  import="net.sf.basedb.core.Item"
39  import="net.sf.basedb.core.ItemProxy"
40  import="net.sf.basedb.core.ItemContext"
41  import="net.sf.basedb.core.ItemResultIterator"
42  import="net.sf.basedb.core.MultiPermissions"
43  import="net.sf.basedb.core.Permission"
44  import="net.sf.basedb.core.Project"
45  import="net.sf.basedb.core.Session"
46  import="net.sf.basedb.core.User"
47  import="net.sf.basedb.core.Client"
48  import="net.sf.basedb.core.PermissionDeniedException"
49  import="net.sf.basedb.core.PluginDefinition"
50  import="net.sf.basedb.core.plugin.GuiContext"
51  import="net.sf.basedb.core.plugin.Plugin"
52  import="net.sf.basedb.core.SharedItem"
53  import="net.sf.basedb.clients.web.Base"
54  import="net.sf.basedb.clients.web.PermissionUtil"
55  import="net.sf.basedb.clients.web.util.HTML"
56  import="net.sf.basedb.util.Values"
57  import="java.util.Collections"
58  import="java.util.Date"
59  import="java.util.Map"
60  import="java.util.Set"
61  import="java.util.List"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
65<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
66<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
67
68<%
69final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
70final String ID = sc.getId();
71final int itemId = Values.getInt(request.getParameter("item_id"));
72final Item itemType = Item.valueOf(request.getParameter("item_type"));
73final DbControl dc = sc.newDbControl();
74try
75{
76  BasicItem item = itemType.getById(dc, itemId);
77  Set<ItemProxy> usingItems = item.getUsingItems();
78  final boolean isUsed = usingItems != null && usingItems.size() > 0;
79  final boolean writePermission = item.hasPermission(Permission.WRITE);
80  final boolean deletePermission = item.hasPermission(Permission.DELETE);
81  final boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
82  final Shareable shareable = item instanceof Shareable ? (Shareable)item : null;
83  final boolean isShared = shareable != null && shareable.isShared();
84  final Removable removable = item instanceof Removable ? (Removable)item : null;
85  final boolean isRemoved = removable != null && removable.isRemoved();
86  String name = "";
87  String description = "";
88  if (item instanceof File)
89  {
90    File file = (File)item;
91    name = file.getPath().toString();
92    description = file.getDescription();
93  }
94  else if (item instanceof Directory)
95  {
96    Directory dir = (Directory)item;
97    name = dir.getPath().toString();
98    description = dir.getDescription();
99  }
100  else if (item instanceof Nameable)
101  {
102    Nameable nameable = (Nameable)item;
103    name = nameable.getName();
104    description = nameable.getDescription();
105  }
106  else
107  {
108    name = item.toString();
109  }
110  String link = Base.getLink(ID, HTML.encodeTags(name), item.getType(), itemId, writePermission);
111  %>
112
113  <base:page>
114  <base:head scripts="tabcontrol.js,table.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
115  <script language="JavaScript">
116    var submitPage = 'index.jsp';
117    var formId = 'usingItems';
118    function editItem()
119    {
120      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
121    }
122    function shareItem()
123    {
124      var controller = Main.getController('<%=itemType.name()%>');
125      var url = getRoot() + controller.url + '?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>';
126      Main.openPopup(url, 'ShareItem', 500, 400);
127    }
128    function restoreItem()
129    {
130      url = 'index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_type=<%=itemType.name()%>&item_id=<%=itemId%>';
131      location.replace(url);
132    }
133    function deleteItem()
134    {
135      if (!confirm('You are about to PERMANENTLY DELETE this item.\n This can\'t be undone. Continue?'))
136      {
137        return;
138      }
139      var url = 'index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_type=<%=itemType.name()%>&item_id=<%=itemId%>';
140      location.replace(url);
141    }
142    function deleteItems()
143    {
144      var frm = document.forms[formId];
145      var numChecked = Forms.numChecked(frm, /item:/);
146      if (numChecked == 0)
147      {
148        alert('Please select at least one item in the list');
149        return;
150      }
151      frm.action = submitPage;
152      frm.cmd.value = 'DeleteItems';
153      frm.submit();
154    }
155    function restoreItems()
156    {
157      var frm = document.forms[formId];
158      var numChecked = Forms.numChecked(frm, /item:/);
159      if (numChecked == 0)
160      {
161        alert('Please select at least one item in the list');
162        return;
163      }
164      frm.action = submitPage;
165      frm.cmd.value = 'RestoreItems';
166      frm.submit();
167    }
168   
169  </script>
170  </base:head>
171  <base:body>
172    <p>
173    <p:path>
174      <p:pathelement title="Trashcan" href="<%="index.jsp?ID="+ID%>" />
175      <p:pathelement title="<%=itemType.toString() + ": " + HTML.encodeTags(name)%>" />
176    </p:path>
177
178    <t:tabcontrol id="main">
179    <t:tab id="properties" title="Properties">
180
181    <tbl:toolbar
182      >
183      <tbl:button 
184        disabled="<%=writePermission ? false : true%>" 
185        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
186        onclick="editItem()" 
187        title="Edit&hellip;" 
188        tooltip="<%=writePermission ? "Edit this item" : "You do not have permission to edit this item"%>" 
189      />
190      <tbl:button 
191        disabled="<%=deletePermission ? false : true%>" 
192        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
193        onclick="deleteItem()" 
194        title="Delete"
195        visible="<%=!isUsed%>"
196        tooltip="<%=deletePermission ? "Permanently delete this item" : "You do not have permission to delete this item"%>" 
197      />
198      <tbl:button 
199        disabled="<%=writePermission ? false : true%>" 
200        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
201        onclick="restoreItem()" 
202        title="Restore"
203        visible="<%=isRemoved%>"
204        tooltip="<%=writePermission ? "Restore this item" : "You do not have permission to restore this item"%>" 
205      />
206      <tbl:button 
207        disabled="<%=sharePermission ? false : true%>"
208        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
209        onclick="shareItem()" 
210        title="Share&hellip;" 
211        visible="<%=shareable != null%>"
212        tooltip="<%=sharePermission ? "Share this item to other user, groups and projects" : "You do not have permission to share this scan"%>"
213      />
214      <tbl:button
215        image="help.gif"
216        onclick="<%="Main.openHelp('" + ID +"', 'trash.view.properties')"%>"
217        title="Help&hellip;"
218        tooltip="Get help about this page"
219      />
220    </tbl:toolbar>
221
222    <div class="boxedbottom">
223      <div class="itemstatus">Permissions on this item:
224        <i><%=PermissionUtil.getFullPermissionNames(item)%></i></div>
225      <%
226      if (isRemoved || isShared || isUsed)
227      {
228        %>
229        <div class="itemstatus">
230          <base:icon image="deleted.gif" 
231            visible="<%=isRemoved%>" style="margin-bottom: 2px;"> This item has been flagged for deletion<br></base:icon>
232          <base:icon image="shared.gif" 
233            visible="<%=isShared%>" style="margin-bottom: 2px;"> This item is shared to other user, groups and/or projects<br></base:icon>
234          <base:icon image="used.gif" 
235            visible="<%=isUsed%>" style="margin-bottom: 2px;"> This item is used by other items and can't be permanently deleted</base:icon>
236        </div>
237        <%
238      }
239      %>
240      <table class="form" cellspacing=0>
241      <tr>
242        <td class="prompt">Type</td>
243        <td><%=itemType.toString()%></td>
244      </tr>
245      <tr>
246        <td class="prompt">Name</td>
247        <td><%=link%></td>
248      </tr>
249      <tr>
250        <td class="prompt">Description</td>
251        <td><%=HTML.niceFormat(description)%></td>
252      </tr>
253      </table>
254
255      <%
256      if (isUsed)
257      {
258        %>
259        <h4 class="docked">Items using <%=itemType.toString()%>: <%=HTML.encodeTags(name)%></h4>
260        <tbl:table
261          id="usingItems"
262          clazz="itemlist"
263          columns="all"
264        >
265        <tbl:hidden 
266          name="item_type"
267          value="<%=itemType.name()%>"
268        />
269        <tbl:hidden 
270          name="item_id"
271          value="<%=String.valueOf(itemId)%>"
272        />
273        <tbl:columndef 
274          id="name"
275          title="Name/ID"
276        />
277        <tbl:columndef
278          id="type"
279          title="Type"
280        />
281        <tbl:columndef 
282          id="description"
283          title="Description"
284        />
285      <tbl:toolbar>
286        <tbl:button 
287          image="delete.gif"
288          onclick="deleteItems()" 
289          title="Delete" 
290          tooltip="Mark the selected items for deletion" 
291        />
292        <tbl:button 
293          image="restore.gif"
294          onclick="restoreItems()" 
295          title="Restore" 
296          tooltip="Restore the selected item" 
297        />
298      </tbl:toolbar>
299        <tbl:data>
300          <tbl:columns>
301          <tbl:header 
302            clazz="index"
303            >&nbsp;</tbl:header>
304          <tbl:header 
305            clazz="check" 
306            ><base:icon 
307              image="check_uncheck.gif" 
308              tooltip="Check/uncheck all" 
309              onclick="Forms.checkUncheck(document.forms['usingItems'], /item:/)" style="align: left;"
310            /></tbl:header>
311          <tbl:header 
312            clazz="icons" 
313            >&nbsp;</tbl:header>
314          </tbl:columns>
315          <tbl:rows>
316          <%
317          int index = 0;
318          for (ItemProxy proxy : usingItems)
319          {
320            index++;
321            boolean denied = false;
322            boolean writePermissionOnUsedBy = false;
323            boolean usedByIsRemoved = false;
324            boolean usedByRemovable = false;
325            BasicItem usedBy = null;
326            String usedByName = String.valueOf(proxy.getId());
327            String usedByDescription = "";
328            try
329            {
330              usedBy = proxy.getItem(dc);
331              writePermissionOnUsedBy = usedBy.hasPermission(Permission.WRITE);
332              if (usedBy instanceof Removable)
333              {
334                usedByRemovable = true;
335                usedByIsRemoved = ((Removable)usedBy).isRemoved();
336              }
337              if (usedBy instanceof File)
338              {
339                File file = (File)usedBy;
340                usedByName = file.getPath().toString();
341                usedByDescription = file.getDescription();
342              }
343              else if (usedBy instanceof Directory)
344              {
345                Directory dir = (Directory)usedBy;
346                usedByName = dir.getPath().toString();
347                usedByDescription = dir.getDescription();
348              }
349              else if (usedBy instanceof Nameable)
350              {
351                Nameable nameable = (Nameable)usedBy;
352                usedByName = nameable.getName();
353                usedByDescription = nameable.getDescription();
354              }
355              else
356              {
357                usedByName = usedBy.toString();
358              }
359            }
360            catch (PermissionDeniedException ex)
361            {
362              denied = true;
363            }
364            %>
365            <tbl:row>
366              <tbl:header 
367                clazz="index"
368                ><%=index%></tbl:header>
369              <tbl:header 
370                clazz="check"
371                ><%
372                if (usedByRemovable)
373                {
374                  %><input 
375                    type="checkbox" 
376                    name="item:<%=proxy.getType().name()%>" 
377                    value="<%=proxy.getId()%>"
378                  ><%
379                }
380                %></tbl:header>
381              <tbl:header 
382                clazz="icons" 
383                ><base:icon 
384                  image="deleted.gif" 
385                  tooltip="This item has been scheduled for deletion" 
386                  visible="<%=usedByIsRemoved%>"
387                />&nbsp;</tbl:header>
388              <tbl:cell column="name"><%=Base.getLink(ID, HTML.encodeTags(usedByName), proxy.getType(), proxy.getId(), writePermissionOnUsedBy)%></tbl:cell>
389              <tbl:cell column="type"><%=proxy.getType().toString()%></tbl:cell>
390              <tbl:cell column="description"><%=HTML.niceFormat(usedByDescription)%></tbl:cell>
391            </tbl:row>
392            <%
393          }
394          %>
395          </tbl:rows>
396        </tbl:data>
397        </tbl:table>
398        <%
399      }
400      if (item instanceof SharedItem)
401      {
402        // Tables with users/groups/projects that this item is shared to
403        MultiPermissions mp = new MultiPermissions(Collections.singleton((SharedItem)item));
404        ItemResultIterator<User> users = mp.getUsers().iterate(dc);
405        ItemResultIterator<Group> groups = mp.getGroups().iterate(dc);
406        ItemResultIterator<Project> projects = mp.getProjects().iterate(dc);
407       
408        if (users.hasNext() || groups.hasNext() || projects.hasNext())
409        {
410          %>
411          <h4 class="docked">Shared to</h4>
412          <tbl:table 
413            id="itemsSharedTo"
414            clazz="itemlist"
415            columns="all"
416          >
417            <tbl:columndef 
418              id="itemType"
419              title="Item type"
420            />
421            <tbl:columndef 
422              id="name"
423              title="Name"
424            />
425            <tbl:columndef 
426              id="permissions"
427              title="Permissions"
428            />
429            <tbl:data>
430              <tbl:columns>
431              </tbl:columns>
432              <tbl:rows>
433              <%
434              while(projects.hasNext())
435              {
436                Project project = projects.next();
437                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
438                %>     
439                <tbl:row>
440                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
441                  <tbl:cell column="name"><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
442                  <tbl:cell column="permissions">
443                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
444                  </tbl:cell>
445                </tbl:row>
446                <%
447              }
448              while(groups.hasNext())
449              {
450                Group group = groups.next();
451                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
452                %>
453                <tbl:row>             
454                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
455                  <tbl:cell column="name"><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
456                  <tbl:cell column="permissions">
457                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
458                  </tbl:cell>
459                </tbl:row>
460                <% 
461              }
462              while (users.hasNext())
463              {
464                User user = users.next();
465                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
466                %>
467                <tbl:row>             
468                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
469                  <tbl:cell column="name"><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
470                  <tbl:cell column="permissions">
471                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
472                  </tbl:cell>
473                </tbl:row>
474                <%
475              }
476              %>
477              </tbl:rows>
478            </tbl:data>
479          </tbl:table>
480          <%
481        }
482        else
483        {
484          %>
485          <h4>Shared to</h4>
486          This <%=itemType %> is not shared
487          (or, you don't have permission to view the ones it is shared to).
488          <%
489        }
490      }
491      %>
492
493    </t:tab>
494    </t:tabcontrol>
495
496  </base:body>
497  </base:page>
498  <%
499}
500finally
501{
502  if (dc != null) dc.commit();
503}
504
505%>
Note: See TracBrowser for help on using the repository browser.