source: trunk/www/admin/annotationtypecategories/view_category.jsp @ 4886

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

References #1271: Add extension points to all toolbars

Added code for displaying extensions to all pages in the administration menu.

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