source: trunk/www/admin/annotationtypes/view_annotationtype.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 Date Id
File size: 16.4 KB
Line 
1<%-- $Id: view_annotationtype.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.Item"
31  import="net.sf.basedb.core.Include"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.AnnotationType"
35  import="net.sf.basedb.core.AnnotationTypeCategory"
36  import="net.sf.basedb.core.User"
37  import="net.sf.basedb.core.Type"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.MultiPermissions"
41  import="net.sf.basedb.core.Group"
42  import="net.sf.basedb.core.Project"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.core.PluginDefinition"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.core.query.Orders"
48  import="net.sf.basedb.core.query.Hql"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.PermissionUtil"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.Values"
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.Map"
61  import="java.util.Collections"
62  import="java.util.Date"
63  import="java.util.Set"
64%>
65<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
66<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
67<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
68<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
69<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
70<%!
71  private static final Item itemType = Item.ANNOTATIONTYPE;
72  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
73%>
74<%
75final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
76final String ID = sc.getId();
77final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
78final int itemId = cc.getId();
79final float scale = Base.getScale(sc);
80final DbControl dc = sc.newDbControl();
81try
82{
83  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
84
85  String title = null;
86  AnnotationType annotationType = AnnotationType.getById(dc, itemId);
87 
88  final boolean writePermission = annotationType.hasPermission(Permission.WRITE);
89  final boolean deletePermission = annotationType.hasPermission(Permission.DELETE);
90  final boolean sharePermission = annotationType.hasPermission(Permission.SET_PERMISSION);
91  final boolean setOwnerPermission = annotationType.hasPermission(Permission.SET_OWNER);
92  final boolean isOwner = annotationType.isOwner();
93  final boolean isRemoved = annotationType.isRemoved();
94  final boolean isUsed = isRemoved && annotationType.isUsed();
95  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
96  Formatter dateFormatter = FormatterFactory.getDateFormatter(sc);
97  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, annotationType);
98  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
99  %>
100  <base:page title="<%=title%>">
101  <base:head scripts="tabcontrol.js ,table.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css">
102    <ext:scripts context="<%=jspContext%>" />
103    <ext:stylesheets context="<%=jspContext%>" />
104    <script language="JavaScript">
105    function editItem()
106    {
107      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
108    }
109    function shareItem()
110    {
111      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareAnnotationType', 600, 400);
112    }
113    function deleteItem()
114    {
115      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
116    }
117    function restoreItem()
118    {
119      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
120    }
121    function deleteItemPermanently()
122    {
123      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
124    }
125    function itemDeleted()
126    {
127      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
128    }
129    function showUsingItems()
130    {
131      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
132    }
133    function setOwner()
134    {
135      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
136    }
137    function runPlugin(cmd)
138    {
139      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
140    }
141    </script>
142  </base:head>
143  <base:body>
144    <p>
145    <p:path>
146      <p:pathelement title="Annotation types" href="<%="index.jsp?ID="+ID%>" />
147      <p:pathelement title="<%=HTML.encodeTags(annotationType.getName())%>" />
148    </p:path>
149   
150    <t:tabcontrol id="main" active="properties">
151    <t:tab id="properties" title="Properties">
152   
153    <tbl:toolbar
154      >
155      <tbl:button 
156        disabled="<%=writePermission ? false : true%>" 
157        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
158        onclick="editItem()" 
159        title="Edit&hellip;" 
160        tooltip="<%=writePermission ? "Edit this annotation type" : "You do not have permission to edit this annotation type"%>" 
161      />
162      <tbl:button 
163        disabled="<%=deletePermission ? false : true%>" 
164        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
165        onclick="deleteItem()" 
166        title="Delete"
167        visible="<%=!annotationType.isRemoved()%>"
168        tooltip="<%=deletePermission ? "Delete this annotation type" : "You do not have permission to delete this annotation type"%>" 
169      />
170      <tbl:button 
171        disabled="<%=writePermission ? false : true%>" 
172        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
173        onclick="restoreItem()" 
174        title="Restore"
175        visible="<%=annotationType.isRemoved()%>"
176        tooltip="<%=writePermission ? "Restore this annotation type" : "You do not have permission to restore this annotation type"%>" 
177      />
178      <tbl:button 
179        disabled="<%=sharePermission ? false : true%>"
180        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
181        onclick="shareItem()" 
182        title="Share&hellip;" 
183        tooltip="<%=sharePermission ? "Share this annotation type to other user, groups and projects" : "You do not have permission to share this annotation type"%>"
184      />
185      <tbl:button 
186        disabled="<%=setOwnerPermission ? false : true%>"
187        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
188        onclick="setOwner()" 
189        title="Set ownership&hellip;"
190        tooltip="<%=setOwnerPermission ? "Set owner of this item" : "You do not have permission to change ownership of this item"%>"
191      />
192      <tbl:button 
193        image="import.gif" 
194        onclick="runPlugin('ImportItem')" 
195        title="Import&hellip;" 
196        tooltip="Import data" 
197        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
198      />
199      <tbl:button 
200        image="export.gif" 
201        onclick="runPlugin('ExportItem')" 
202        title="Export&hellip;" 
203        tooltip="Export data" 
204        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
205      />
206      <tbl:button 
207        image="runplugin.gif" 
208        onclick="runPlugin('RunPlugin')" 
209        title="Run plugin&hellip;" 
210        tooltip="Run a plugin" 
211        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
212      />
213      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
214        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
215      <tbl:button
216        image="help.gif"
217        onclick="<%="Main.openHelp('" + ID +"', 'annotationtype.view.properties')"%>"
218        title="Help&hellip;"
219        tooltip="Get help about this page"
220      />
221      </tbl:toolbar>
222    <div class="boxedbottom">
223      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(annotationType)%></i></div>
224      <%
225      if (annotationType.isRemoved() || annotationType.isShared())
226      {
227        %>
228        <div class="itemstatus">
229          <base:icon 
230            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
231            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
232            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
233            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
234          <base:icon image="used.gif" 
235            onclick="showUsingItems()"
236            tooltip="Show the items that are using this one"
237            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
238          <base:icon image="shared.gif" 
239            visible="<%=annotationType.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
240        </div>
241        <%
242      }
243      %>
244      <table class="form" cellspacing=0>
245      <tr>
246        <td class="prompt">Name</td>
247        <td><%=HTML.encodeTags(annotationType.getName())%></td>
248      </tr>
249      <tr>
250        <td class="prompt">Registered</td>
251        <td><%=dateFormatter.format(annotationType.getEntryDate())%></td>
252      </tr>
253      <tr>
254        <td class="prompt">External ID</td>
255        <td><%=HTML.encodeTags(annotationType.getExternalId())%></td>
256      </tr>
257      <tr>
258        <td class="prompt">Value type</td>
259        <td><%=annotationType.getValueType()%></td>
260      </tr>
261      <tr>
262        <td class="prompt">Default unit</td>
263        <td><base:propertyvalue item="<%=annotationType%>" property="quantity" />
264          <base:icon image="submenu.gif" style="vertical-align: baseline;"/>
265          <base:propertyvalue item="<%=annotationType%>" property="defaultUnit" />
266        </td>
267      </tr>
268      <tr>
269        <td class="prompt">Enumeration</td>
270        <td><%=annotationType.isEnumeration() ? 
271          HTML.encodeTags(Values.getString(annotationType.getValues(), ", ", true, 
272            annotationType.getValueType() == Type.DATE ? dateFormatter : null)) : "no"%></td>
273      </tr>
274      <tr>
275        <td class="prompt">Default value</td>
276        <td><%=HTML.encodeTags(annotationType.getDefaultValue())%></td>
277      </tr>
278      <tr>
279        <td class="prompt">Multiplicity</td>
280        <td><%=annotationType.getMultiplicity() == 0 ? "<i>- unlimited -</i>" : annotationType.getMultiplicity()%></td>
281      </tr>
282      <tr>
283        <td class="prompt">Required by MIAME</td>
284        <td><%=annotationType.isRequiredForMiame() ? "yes" : "no"%></td>
285      </tr>
286      <tr>
287        <td class="prompt">Protocol parameter</td>
288        <td><%=annotationType.isProtocolParameter() ? "yes" : "no"%></td>
289      </tr>
290      <tr>
291        <td class="prompt">Items</td>
292        <td><%=Values.getString(annotationType.getEnabledItems(), ", ", true)%></td>
293      </tr>
294      <tr>
295        <td class="prompt">Owner</td>
296        <td><base:propertyvalue item="<%=annotationType%>" property="owner" /></td>
297      </tr>
298      <tr valign="baseline">
299        <td class="prompt">Description</td>
300        <td><%=HTML.niceFormat(annotationType.getDescription())%></td>
301      </tr>
302      </table>
303     
304
305      <%
306      ItemQuery<AnnotationTypeCategory> categoryQuery = 
307        annotationType.getCategories();
308      categoryQuery.include(Include.ALL);
309      categoryQuery.order(Orders.asc(Hql.property("name")));
310      ItemResultList<AnnotationTypeCategory> categories = categoryQuery.list(dc);
311     
312      if (categories.size() == 0)
313      {
314        %>
315        <h4>Categories</h4>
316        This annotation type isn't a member of any category (or, you don't have permission to view them).
317        <%
318      }
319      else
320      {
321        %>
322        <base:section 
323          id="categories" 
324          title="<%="Categories (" + categories.size() + ")"%>"
325          context="<%=cc%>"
326          >
327          <tbl:table
328            id="members"
329            clazz="itemlist"
330            columns="all"
331            >
332          <tbl:columndef 
333            id="name"
334            title="Name"
335          />
336          <tbl:columndef 
337            id="description"
338            title="Description"
339          />
340          <tbl:data>
341            <tbl:columns>
342            </tbl:columns>
343            <tbl:rows>
344            <%
345           
346            for (AnnotationTypeCategory category : categories)
347            {
348              %>
349              <tbl:row>
350                <tbl:cell column="name"><base:icon 
351                    image="deleted.gif" 
352                    tooltip="This item has been scheduled for deletion" 
353                    visible="<%=category.isRemoved()%>"
354                  /><%=Base.getLinkedName(ID, category, false, true)%></tbl:cell>
355                <tbl:cell column="description"><%=HTML.encodeTags(category.getDescription())%></tbl:cell>
356              </tbl:row>
357              <%
358            }
359            %>
360            </tbl:rows>
361          </tbl:data>
362          </tbl:table>
363        </base:section>
364        <%
365      }
366
367      // Tables with users/groups/projects that this item is shared to
368      MultiPermissions mp = new MultiPermissions(Collections.singleton(annotationType));
369      ItemResultList<User> users = mp.getUsers().list(dc);
370      ItemResultList<Group> groups = mp.getGroups().list(dc);
371      ItemResultList<Project> projects = mp.getProjects().list(dc);
372      int totalShare = users.size() + groups.size() + projects.size();
373     
374      if (totalShare > 0)
375      {
376        %>
377        <base:section 
378          id="sharedTo" 
379          title="<%="Shared to (" + totalShare + ")"%>" 
380          context="<%=cc%>"
381          >
382          <tbl:table 
383            id="itemsSharedTo"
384            clazz="itemlist"
385            columns="all"
386          >
387            <tbl:columndef 
388              id="itemType"
389              title="Item type"
390            />
391            <tbl:columndef 
392              id="name"
393              title="Name"
394            />
395            <tbl:columndef 
396              id="permissions"
397              title="Permissions"
398            />
399            <tbl:data>
400              <tbl:columns>
401              </tbl:columns>
402              <tbl:rows>
403              <%
404              for (Project project : projects)
405              {
406                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
407                %>     
408                <tbl:row>
409                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
410                  <tbl:cell column="name"><base:icon 
411                    image="deleted.gif" 
412                    tooltip="This item has been scheduled for deletion" 
413                    visible="<%=project.isRemoved()%>"
414                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
415                  <tbl:cell column="permissions">
416                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
417                  </tbl:cell>
418                </tbl:row>
419                <%
420              }
421              for (Group group : groups)
422              {
423                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
424                %>
425                <tbl:row>             
426                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
427                  <tbl:cell column="name"><base:icon 
428                    image="deleted.gif" 
429                    tooltip="This item has been scheduled for deletion" 
430                    visible="<%=group.isRemoved()%>"
431                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
432                  <tbl:cell column="permissions">
433                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
434                  </tbl:cell>
435                </tbl:row>
436                <% 
437              }
438              for (User user : users)
439              {
440                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
441                %>
442                <tbl:row>             
443                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
444                  <tbl:cell column="name"><base:icon 
445                    image="deleted.gif" 
446                    tooltip="This item has been scheduled for deletion" 
447                    visible="<%=user.isRemoved()%>"
448                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
449                  <tbl:cell column="permissions">
450                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
451                  </tbl:cell>
452                </tbl:row>
453                <%
454              }
455              %>
456              </tbl:rows>
457            </tbl:data>
458          </tbl:table>
459        </base:section>
460        <%
461      }
462      else
463      {
464        %>
465        <h4>Shared to</h4>
466        This annotation type is not shared
467        (or, you don't have permission to view the ones it is shared to).
468        <%
469      }
470      %>
471     
472    </div>
473      </t:tab>
474      </t:tabcontrol>
475
476  </base:body>
477  </base:page>
478  <%
479}
480finally
481{
482  if (dc != null) dc.close();
483}
484
485%>
Note: See TracBrowser for help on using the repository browser.