source: trunk/www/admin/protocols/view_protocol.jsp @ 5042

Last change on this file since 5042 was 5042, checked in by Martin Svensson, 14 years ago

References #360 Covering the submenu items in 'Administrate' menu.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.6 KB
Line 
1<%-- $Id: view_protocol.jsp 5042 2009-08-11 10:48:42Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.SystemItems"
30  import="net.sf.basedb.core.Group"
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.Protocol"
35  import="net.sf.basedb.core.ProtocolType"
36  import="net.sf.basedb.core.AnnotationType"
37  import="net.sf.basedb.core.File"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.PluginDefinition"
41  import="net.sf.basedb.core.ItemQuery"
42  import="net.sf.basedb.core.ItemResultList"
43  import="net.sf.basedb.core.Include"
44  import="net.sf.basedb.core.MultiPermissions"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.core.Project"
48  import="net.sf.basedb.core.query.Orders"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.PermissionUtil"
52  import="net.sf.basedb.clients.web.util.HTML"
53  import="net.sf.basedb.util.formatter.Formatter"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
56  import="net.sf.basedb.clients.web.extensions.JspContext"
57  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
58  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
59  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
60  import="java.util.Date"
61  import="net.sf.basedb.util.Values"
62  import="java.util.Collections"
63  import="java.util.Map"
64  import="java.util.Set"
65%>
66<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
67<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
68<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
69<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
70<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
71<%!
72  private static final Item itemType = Item.PROTOCOL;
73  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
74%>
75<%
76final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
77final String ID = sc.getId();
78final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
79final int itemId = cc.getId();
80final float scale = Base.getScale(sc);
81final DbControl dc = sc.newDbControl();
82try
83{
84  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
85  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
86
87  String title = null;
88  Protocol protocol = Protocol.getById(dc, itemId);
89 
90  final boolean writePermission = protocol.hasPermission(Permission.WRITE);
91  final boolean deletePermission = protocol.hasPermission(Permission.DELETE);
92  final boolean sharePermission = protocol.hasPermission(Permission.SET_PERMISSION);
93  final boolean setOwnerPermission = protocol.hasPermission(Permission.SET_OWNER);
94  final boolean isRemoved = protocol.isRemoved();
95  final boolean isUsed = isRemoved && protocol.isUsed();
96  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
97  final boolean isOwner = protocol.isOwner();
98  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, protocol);
99  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
100  %>
101  <base:page title="<%=title%>">
102  <base:head scripts="tabcontrol.js,table.js" styles="toolbar.css,headertabcontrol.css,path.css,table.css">
103    <ext:scripts context="<%=jspContext%>" />
104    <ext:stylesheets context="<%=jspContext%>" />
105    <script language="JavaScript">
106    function editItem()
107    {
108      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
109    }
110    function shareItem()
111    {
112      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareProtocol', 600, 400);
113    }
114    function deleteItem()
115    {
116      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
117    }
118    function restoreItem()
119    {
120      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
121    }
122    function deleteItemPermanently()
123    {
124      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
125    }
126    function itemDeleted()
127    {
128      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
129    }
130    function showUsingItems()
131    {
132      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
133    }
134    function setOwner()
135    {
136      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
137    }
138    function runPlugin(cmd)
139    {
140      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
141    }
142    </script>
143  </base:head>
144  <base:body>
145    <p>
146    <p:path>
147      <p:pathelement title="Protocols" href="<%="index.jsp?ID="+ID%>" />
148      <p:pathelement title="<%=HTML.encodeTags(protocol.getName())%>" />
149    </p:path>
150   
151    <t:tabcontrol id="main" active="properties">
152    <t:tab id="properties" title="Properties">
153   
154    <tbl:toolbar
155      >
156      <tbl:button 
157        disabled="<%=writePermission ? false : true%>" 
158        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
159        onclick="editItem()" 
160        title="Edit&hellip;" 
161        tooltip="<%=writePermission ? "Edit this protocol" : "You do not have permission to edit this protocol"%>" 
162      />
163      <tbl:button 
164        disabled="<%=deletePermission ? false : true%>" 
165        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
166        onclick="deleteItem()" 
167        title="Delete"
168        visible="<%=!protocol.isRemoved()%>"
169        tooltip="<%=deletePermission ? "Delete this protocol" : "You do not have permission to delete this protocol"%>" 
170      />
171      <tbl:button 
172        disabled="<%=writePermission ? false : true%>" 
173        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
174        onclick="restoreItem()" 
175        title="Restore"
176        visible="<%=protocol.isRemoved()%>"
177        tooltip="<%=writePermission ? "Restore this protocol" : "You do not have permission to restore this protocol"%>" 
178      />
179      <tbl:button 
180        disabled="<%=sharePermission ? false : true%>"
181        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
182        onclick="shareItem()" 
183        title="Share&hellip;" 
184        tooltip="<%=sharePermission ? "Share this protocol to other user, groups and projects" : "You do not have permission to share this protocol"%>"
185      />
186      <tbl:button 
187        disabled="<%=setOwnerPermission ? false : true%>"
188        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
189        onclick="setOwner()" 
190        title="Set owner&hellip;"
191        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
192      />
193      <tbl:button 
194        image="import.gif" 
195        onclick="runPlugin('ImportItem')" 
196        title="Import&hellip;" 
197        tooltip="Import data" 
198        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
199      />
200      <tbl:button 
201        image="export.gif" 
202        onclick="runPlugin('ExportItem')" 
203        title="Export&hellip;" 
204        tooltip="Export data" 
205        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
206      />
207      <tbl:button 
208        image="runplugin.gif" 
209        onclick="runPlugin('RunPlugin')" 
210        title="Run plugin&hellip;" 
211        tooltip="Run a plugin" 
212        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
213      />
214      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
215        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
216      <tbl:button
217        image="help.gif"
218        onclick="<%="Main.openHelp('" + ID +"', 'protocol.view.properties')"%>"
219        title="Help&hellip;"
220        tooltip="Get help about this page"
221      />
222      </tbl:toolbar>
223    <div class="boxedbottom">
224      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(protocol)%></i></div>
225      <%
226      if (protocol.isRemoved() || protocol.isShared())
227      {
228        %>
229        <div class="itemstatus">
230          <base:icon 
231            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
232            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
233            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
234            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
235          <base:icon image="used.gif" 
236            onclick="showUsingItems()"
237            tooltip="Show the items that are using this one"
238            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
239          <base:icon image="shared.gif" 
240            visible="<%=protocol.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
241        </div>
242        <%
243      }
244      %>
245      <table class="form" cellspacing="0">
246      <tr>
247        <td class="prompt">Name</td>
248        <td><%=HTML.encodeTags(protocol.getName())%></td>
249      </tr>
250      <tr>
251        <td class="prompt">Type</td>
252        <td><base:propertyvalue item="<%=protocol%>" property="protocolType" /></td>
253      </tr>
254      <tr>
255        <td class="prompt">Registered</td>
256        <td><%=dateFormatter.format(protocol.getEntryDate())%></td>
257      </tr>
258      <tr>
259        <td class="prompt">File</td>
260        <td><base:propertyvalue item="<%=protocol%>" property="file" /></td>
261      </tr>
262      <tr>
263        <td class="prompt">Owner</td>
264        <td><base:propertyvalue item="<%=protocol%>" property="owner" /></td>
265      </tr>
266      <tr>
267        <td class="prompt">Description</td>
268        <td><%=HTML.niceFormat(protocol.getDescription())%></td>
269      </tr>
270      </table>
271
272      <%
273      ItemQuery<AnnotationType> parameterQuery = protocol.getParameters();
274      parameterQuery.include(Include.ALL);
275      parameterQuery.order(Orders.asc(Hql.property("name")));
276      ItemResultList<AnnotationType> parameters = parameterQuery.list(dc);
277      if (parameters.size() == 0)
278      {
279        %>
280        <h4>Parameters</h4>
281        No parameters has been added to this protocol
282        (or, you don't have permission to view them).
283        <%
284      }
285      else
286      {
287        %>
288        <base:section
289          id="parameters"
290          title="<%="Parameters (" + parameters.size() + ")"%>"
291          context="<%=cc%>"
292          >       
293          <tbl:table
294            id="parameters"
295            clazz="itemlist"
296            columns="all"
297            >
298          <tbl:columndef 
299            id="name"
300            title="Name"
301          />
302          <tbl:columndef
303            id="values"
304            title="Values"
305          />
306          <tbl:columndef 
307            id="description"
308            title="Description"
309          />
310          <tbl:data>
311            <tbl:columns>
312            </tbl:columns>
313            <tbl:rows>
314            <%
315            for (AnnotationType item : parameters)
316            {
317              %>
318              <tbl:row>
319                <tbl:cell column="name"><base:icon 
320                    image="deleted.gif" 
321                    tooltip="This item has been scheduled for deletion" 
322                    visible="<%=item.isRemoved()%>"
323                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
324                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
325                <tbl:cell column="values">
326                <%=item.isEnumeration() ? 
327                  "Enumeration: " + HTML.encodeTags(Values.getString(item.getValues(), ", ", true)) :
328                  item.getValueType()%>
329                </tbl:cell>
330              </tbl:row>
331              <%
332            }
333            %>
334            </tbl:rows>
335          </tbl:data>
336          </tbl:table>
337        </base:section>
338        <%
339      }     
340     
341      // Tables with users/groups/projects that this item is shared to
342      MultiPermissions mp = new MultiPermissions(Collections.singleton(protocol));
343      ItemResultList<User> users = mp.getUsers().list(dc);
344      ItemResultList<Group> groups = mp.getGroups().list(dc);
345      ItemResultList<Project> projects = mp.getProjects().list(dc);
346      int totalShare = (users.size() + groups.size() + projects.size());
347      if (totalShare > 0)
348      {
349        %>
350        <base:section 
351          id="sharedTo" 
352          title="<%="Shared to (" + totalShare + ")"%>"
353          context="<%=cc%>"
354          >       
355          <tbl:table 
356            id="itemsSharedTo"
357            clazz="itemlist"
358            columns="all"
359          >
360            <tbl:columndef 
361              id="itemType"
362              title="Item type"
363            />
364            <tbl:columndef 
365              id="name"
366              title="Name"
367            />
368            <tbl:columndef 
369              id="permissions"
370              title="Permissions"
371            />
372            <tbl:data>
373              <tbl:columns>
374              </tbl:columns>
375              <tbl:rows>
376              <%
377              for (Project project : projects)
378              {
379                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
380                %>     
381                <tbl:row>
382                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
383                  <tbl:cell column="name"><base:icon 
384                    image="deleted.gif" 
385                    tooltip="This item has been scheduled for deletion" 
386                    visible="<%=project.isRemoved()%>"
387                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
388                  <tbl:cell column="permissions">
389                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
390                  </tbl:cell>
391                </tbl:row>
392                <%
393              }
394              for (Group group : groups)
395              {
396                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
397                %>
398                <tbl:row>             
399                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
400                  <tbl:cell column="name"><base:icon 
401                    image="deleted.gif" 
402                    tooltip="This item has been scheduled for deletion" 
403                    visible="<%=group.isRemoved()%>"
404                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
405                  <tbl:cell column="permissions">
406                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
407                  </tbl:cell>
408                </tbl:row>
409                <% 
410              }
411              for (User user : users)
412              {
413                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
414                %>
415                <tbl:row>             
416                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
417                  <tbl:cell column="name"><base:icon 
418                    image="deleted.gif" 
419                    tooltip="This item has been scheduled for deletion" 
420                    visible="<%=user.isRemoved()%>"
421                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
422                  <tbl:cell column="permissions">
423                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
424                  </tbl:cell>
425                </tbl:row>
426                <%
427              }
428              %>
429              </tbl:rows>
430            </tbl:data>
431          </tbl:table>
432        </base:section>
433        <%
434      }
435      else
436      {
437        %>
438        <h4>Shared to</h4>
439        This protocol is not shared
440        (or, you don't have permission to view the ones it is shared to).
441        <%
442      }
443      %> 
444    </div>
445    </t:tab>
446     
447    <t:tab id="annotations" title="Annotations" 
448      tooltip="View annotation values">
449      <div class="boxed">
450      <jsp:include page="../../common/annotations/list_annotations.jsp">
451        <jsp:param name="item_type" value="<%=itemType.name()%>" />
452        <jsp:param name="item_id" value="<%=itemId%>" />
453        <jsp:param name="ID" value="<%=ID%>" />
454      </jsp:include>
455      </div>
456    </t:tab>
457     
458    </t:tabcontrol>
459
460  </base:body>
461  </base:page>
462  <%
463}
464finally
465{
466  if (dc != null) dc.close();
467}
468
469%>
Note: See TracBrowser for help on using the repository browser.