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

Last change on this file since 4882 was 4882, checked in by Nicklas Nordborg, 13 years ago

References #1271: Add extension points to all toolbars

Added code for displaying extensions to all biomaterial pages.

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