source: trunk/www/biomaterials/lists/view_list.jsp @ 4705

Last change on this file since 4705 was 4705, checked in by Nicklas Nordborg, 14 years ago

Fixes #1191: Biomaterial lists manager API and interface

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.5 KB
Line 
1<%-- $Id: view_list.jsp 4705 2008-12-16 13:29:12Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2008 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  @author Nicklas
23  @version 2.10
24--%>
25<%@ page session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.SystemItems"
29  import="net.sf.basedb.core.Group"
30  import="net.sf.basedb.core.Include"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.ItemQuery"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.Permission"
37  import="net.sf.basedb.core.BioMaterialList"
38  import="net.sf.basedb.core.MultiPermissions"
39  import="net.sf.basedb.core.User"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.PluginDefinition"
42  import="net.sf.basedb.core.plugin.GuiContext"
43  import="net.sf.basedb.core.plugin.Plugin"
44  import="net.sf.basedb.core.Project"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.util.Values"
51  import="java.util.Collections"
52  import="java.util.Map"
53  import="java.util.Set"
54%>
55<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
56<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
57<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
58<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
59<%!
60  private static final Item itemType = Item.BIOMATERIALLIST;
61  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
62%>
63<%
64final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
65final String ID = sc.getId();
66final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
67final int itemId = cc.getId();
68final String tab = Values.getString(request.getParameter("tab"), "properties");
69final float scale = Base.getScale(sc);
70final DbControl dc = sc.newDbControl();
71try
72{
73  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
74
75  String title = null;
76  BioMaterialList list = BioMaterialList.getById(dc, itemId);
77 
78  final boolean writePermission = list.hasPermission(Permission.WRITE);
79  final boolean deletePermission = list.hasPermission(Permission.DELETE);
80  final boolean sharePermission = list.hasPermission(Permission.SET_PERMISSION);
81  final boolean usePermission = list.hasPermission(Permission.USE);
82  final boolean setOwnerPermission = list.hasPermission(Permission.SET_OWNER);
83  final boolean isRemoved = list.isRemoved();
84  final boolean isUsed = isRemoved && list.isUsed();
85  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
86  final boolean isOwner = list.isOwner();
87  %>
88  <base:page title="<%=title%>">
89  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
90    <script language="JavaScript">
91    function editItem()
92    {
93      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
94    }
95    function shareItem()
96    {
97      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareBioMaterialList', 600, 400);
98    }
99    function deleteItem()
100    {
101      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
102    }
103    function restoreItem()
104    {
105      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
106    }
107    function deleteItemPermanently()
108    {
109      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
110    }
111    function itemDeleted()
112    {
113      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
114    }
115    function showUsingItems()
116    {
117      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
118    }
119    function setOwner()
120    {
121      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
122    }
123    function runPlugin(cmd)
124    {
125      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
126    }
127    function viewMembers()
128    {
129      location.href = 'members/index.jsp?ID=<%=ID%>&cmd=List&list_id=<%=itemId%>';
130    }
131    function switchTab(tabControlId, tabId)
132    {
133      if (tabId == 'members')
134      {
135        viewMembers();
136      }
137      else
138      {
139        TabControl.setActiveTab(tabControlId, tabId);
140      }
141    }
142    function merge(mergeType)
143    {
144      Main.openPopup('merge.jsp?ID=<%=ID%>&item_id=<%=itemId%>&mergeType='+mergeType, 'Union', 600, 440);
145    }
146    </script>
147  </base:head>
148  <base:body>
149    <p>
150    <p:path>
151      <p:pathelement title="Biomaterial lists" href="<%="index.jsp?ID="+ID%>" />
152      <p:pathelement title="<%=HTML.encodeTags(list.getName())%>" />
153    </p:path>
154   
155    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab">
156    <t:tab id="properties" title="Properties">
157    <tbl:toolbar
158      >
159      <tbl:button 
160        disabled="<%=writePermission ? false : true%>" 
161        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
162        onclick="editItem()" 
163        title="Edit&hellip;" 
164        tooltip="<%=writePermission ? "Edit this list" : "You do not have permission to edit this list"%>" 
165      />
166      <tbl:button 
167        disabled="<%=deletePermission ? false : true%>" 
168        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
169        onclick="deleteItem()" 
170        title="Delete"
171        visible="<%=!list.isRemoved()%>"
172        tooltip="<%=deletePermission ? "Delete this list" : "You do not have permission to delete this list"%>" 
173      />
174      <tbl:button 
175        disabled="<%=writePermission ? false : true%>" 
176        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
177        onclick="restoreItem()" 
178        title="Restore"
179        visible="<%=list.isRemoved()%>"
180        tooltip="<%=writePermission ? "Restore this list" : "You do not have permission to restore this list"%>" 
181      />
182      <tbl:button 
183        disabled="<%=sharePermission ? false : true%>"
184        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
185        onclick="shareItem()" 
186        title="Share&hellip;" 
187        tooltip="<%=sharePermission ? "Share this list to other user, groups and projects" : "You do not have permission to share this list"%>"
188      />
189      <tbl:button 
190        disabled="<%=setOwnerPermission ? false : true%>"
191        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
192        onclick="setOwner()" 
193        title="Set owner&hellip;"
194        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
195      />
196      <tbl:button
197        visible="<%=writePermission%>"
198        image="set_operations/union_small.png"
199        onclick="merge('union')"
200        title="Union&hellip;"
201        tooltip="Add items from other lists to this list"
202      />
203      <tbl:button
204        visible="<%=writePermission%>"
205        image="set_operations/intersection_small.png"
206        onclick="merge('intersection')"
207        title="Intersection&hellip;"
208        tooltip="Keep only items that are present in other lists"
209      />
210      <tbl:button
211        visible="<%=writePermission%>"
212        image="set_operations/complement_small.png"
213        onclick="merge('complement')"
214        title="Complement&hellip;"
215        tooltip="Remove items found in other lists from this list"
216      />
217      <tbl:button 
218        image="import.gif" 
219        onclick="runPlugin('ImportItem')" 
220        title="Import&hellip;" 
221        tooltip="Import data" 
222        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
223      />
224      <tbl:button 
225        image="export.gif" 
226        onclick="runPlugin('ExportItem')" 
227        title="Export&hellip;" 
228        tooltip="Export data" 
229        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
230      />
231      <tbl:button 
232        image="runplugin.gif" 
233        onclick="runPlugin('RunPlugin')" 
234        title="Run plugin&hellip;" 
235        tooltip="Run a plugin" 
236        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
237      />
238      <tbl:button
239        image="help.gif"
240        onclick="<%="Main.openHelp('" + ID +"', 'biomateriallist.view.properties')"%>"
241        title="Help&hellip;"
242        tooltip="Get help about this page"
243      /> 
244      </tbl:toolbar>
245    <div class="boxedbottom">
246      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(list)%></i></div>
247      <%
248      if (list.isRemoved() || list.isShared())
249      {
250        %>
251        <div class="itemstatus">
252          <base:icon 
253            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
254            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
255            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
256            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
257          <base:icon image="used.gif" 
258            onclick="showUsingItems()"
259            tooltip="Show the items that are using this one"
260            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
261          <base:icon image="shared.gif" 
262            visible="<%=list.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
263        </div>
264        <%
265      }
266      %>
267      <table class="form" cellspacing=0>
268      <tr>
269        <td class="prompt">Name</td>
270        <td><%=HTML.encodeTags(list.getName())%></td>
271      </tr>
272      <tr>
273        <td class="prompt">Member type</td>
274        <td><%=list.getMemberType()%></td>
275      </tr>
276      <tr>
277        <td class="prompt">Size</td>
278        <td><%=list.getSize()%></td>
279      </tr>
280      <tr>
281        <td class="prompt">External ID</td>
282        <td><%=HTML.encodeTags(list.getExternalId())%></td>
283      </tr>
284      <tr>
285        <td class="prompt">Owner</td>
286        <td><base:propertyvalue item="<%=list%>" property="owner"/></td>
287      </tr>
288      <tr>
289        <td class="prompt">Description</td>
290        <td><%=HTML.niceFormat(list.getDescription())%></td>
291      </tr>
292      </table>
293      <%     
294     
295      // Tables with users/groups/projects that this item is shared to
296      MultiPermissions mp = new MultiPermissions(Collections.singleton(list));
297      ItemResultIterator<User> users = mp.getUsers().iterate(dc);
298      ItemResultIterator<Group> groups = mp.getGroups().iterate(dc);
299      ItemResultIterator<Project> projects = mp.getProjects().iterate(dc);
300     
301      if (users.hasNext() || groups.hasNext() || projects.hasNext())
302      {
303        %>
304        <h4 class="docked">Shared to</h4>
305        <tbl:table 
306          id="itemsSharedTo"
307          clazz="itemlist"
308          columns="all"
309        >
310          <tbl:columndef 
311            id="itemType"
312            title="Item type"
313          />
314          <tbl:columndef 
315            id="name"
316            title="Name"
317          />
318          <tbl:columndef 
319            id="permissions"
320            title="Permissions"
321          />
322          <tbl:data>
323            <tbl:columns>
324            </tbl:columns>
325            <tbl:rows>
326            <%
327            while(projects.hasNext())
328            {
329              Project project = projects.next();
330              Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
331              %>     
332              <tbl:row>
333                <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
334                <tbl:cell column="name"><base:icon 
335                  image="deleted.gif" 
336                  tooltip="This item has been scheduled for deletion" 
337                  visible="<%=project.isRemoved()%>"
338                /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
339                <tbl:cell column="permissions">
340                  <%=PermissionUtil.translatePermissionsToString(permissions)%>
341                </tbl:cell>
342              </tbl:row>
343              <%
344            }
345            while(groups.hasNext())
346            {
347              Group group = groups.next();
348              Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
349              %>
350              <tbl:row>             
351                <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
352                <tbl:cell column="name"><base:icon 
353                  image="deleted.gif" 
354                  tooltip="This item has been scheduled for deletion" 
355                  visible="<%=group.isRemoved()%>"
356                /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
357                <tbl:cell column="permissions">
358                  <%=PermissionUtil.translatePermissionsToString(permissions)%>
359                </tbl:cell>
360              </tbl:row>
361              <% 
362            }
363            while (users.hasNext())
364            {
365              User user = users.next();
366              Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
367              %>
368              <tbl:row>             
369                <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
370                <tbl:cell column="name"><base:icon 
371                  image="deleted.gif" 
372                  tooltip="This item has been scheduled for deletion" 
373                  visible="<%=user.isRemoved()%>"
374                /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
375                <tbl:cell column="permissions">
376                  <%=PermissionUtil.translatePermissionsToString(permissions)%>
377                </tbl:cell>
378              </tbl:row>
379              <%
380            }
381            %>
382            </tbl:rows>
383          </tbl:data>
384        </tbl:table>
385        <%
386      }
387      else
388      {
389        %>
390        <h4>Shared to</h4>
391        This list is not shared
392        (or, you don't have permission to view the ones it is shared to).
393        <%
394      }     
395      %>
396    </div>
397    </t:tab>
398    <t:tab id="members" title="Members" />
399    </t:tabcontrol>
400
401  </base:body>
402  </base:page>
403  <%
404}
405finally
406{
407  if (dc != null) dc.close();
408}
409
410%>
Note: See TracBrowser for help on using the repository browser.