source: trunk/www/admin/itemsubtypes/view_subtype.jsp @ 5645

Last change on this file since 5645 was 5645, checked in by Nicklas Nordborg, 11 years ago

References #1597: Subtypes of items

Added subtype functionality for sample list, view and edit dialog. Show the inversely related subtypes on the subtype view page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.9 KB
Line 
1<%-- $Id: view_subtype.jsp 5645 2011-05-27 07:48:13Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2011 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  @since 2.0
24--%>
25<%@ page pageEncoding="UTF-8" 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.Include"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.ItemResultList"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.ItemSubtype"
36  import="net.sf.basedb.core.PermissionDeniedException"
37  import="net.sf.basedb.core.PluginDefinition"
38  import="net.sf.basedb.core.plugin.GuiContext"
39  import="net.sf.basedb.core.plugin.Plugin"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.PermissionUtil"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.util.formatter.Formatter"
47  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
48  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
49  import="net.sf.basedb.clients.web.extensions.JspContext"
50  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
51  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
52  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
53  import="java.util.Date"
54  import="java.util.Map"
55%>
56<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
57<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
58<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
59<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
60<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
61<%!
62  private static final Item itemType = Item.ITEMSUBTYPE;
63  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
64%>
65<%
66final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
67final String ID = sc.getId();
68final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
69final int itemId = cc.getId();
70final float scale = Base.getScale(sc);
71final DbControl dc = sc.newDbControl();
72try
73{
74  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
75  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
76
77  String title = null;
78  ItemSubtype subtype = ItemSubtype.getById(dc, itemId);
79 
80  final boolean usePermission = subtype.hasPermission(Permission.USE);
81  final boolean writePermission = subtype.hasPermission(Permission.WRITE);
82  final boolean deletePermission = subtype.hasPermission(Permission.DELETE);
83  final boolean isRemoved = subtype.isRemoved();
84  final boolean isUsed = isRemoved && subtype.isUsed();
85  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
86  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, subtype);
87  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
88  %>
89  <base:page title="<%=title%>">
90  <base:head scripts="tabcontrol.js,table.js" styles="toolbar.css,headertabcontrol.css,path.css,table.css">
91    <ext:scripts context="<%=jspContext%>" />
92    <ext:stylesheets context="<%=jspContext%>" />
93    <script language="JavaScript">
94    function editItem()
95    {
96      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
97    }
98    function deleteItem()
99    {
100      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
101    }
102    function restoreItem()
103    {
104      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
105    }
106    function deleteItemPermanently()
107    {
108      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
109    }
110    function itemDeleted()
111    {
112      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
113    }
114    function showUsingItems()
115    {
116      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
117    }
118    function runPlugin(cmd)
119    {
120      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
121    }
122    </script>
123  </base:head>
124  <base:body>
125    <p>
126    <p:path>
127      <p:pathelement title="Item subtypes" href="<%="index.jsp?ID="+ID%>" />
128      <p:pathelement title="<%=HTML.encodeTags(subtype.getName())%>" />
129    </p:path>
130   
131    <t:tabcontrol id="main" active="properties">
132    <t:tab id="properties" title="Properties">
133   
134    <tbl:toolbar
135      >
136      <tbl:button 
137        disabled="<%=writePermission ? false : true%>" 
138        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
139        onclick="editItem()" 
140        title="Edit&hellip;" 
141        tooltip="<%=writePermission ? "Edit this item subtype" : "You do not have permission to edit this item subtype"%>" 
142      />
143      <tbl:button 
144        disabled="<%=deletePermission ? false : true%>" 
145        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
146        onclick="deleteItem()" 
147        title="Delete"
148        visible="<%=!subtype.isRemoved()%>"
149        tooltip="<%=deletePermission ? "Delete this item subtype" : "You do not have permission to delete this item subtype"%>" 
150      />
151      <tbl:button 
152        disabled="<%=writePermission ? false : true%>" 
153        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
154        onclick="restoreItem()" 
155        title="Restore"
156        visible="<%=subtype.isRemoved()%>"
157        tooltip="<%=writePermission ? "Restore this item subtype" : "You do not have permission to restore this item subtype"%>" 
158      />
159      <tbl:button 
160        image="export.gif" 
161        onclick="runPlugin('ExportItem')" 
162        title="Export&hellip;" 
163        tooltip="Export data" 
164        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
165      />
166      <tbl:button 
167        image="runplugin.gif" 
168        onclick="runPlugin('RunPlugin')" 
169        title="Run plugin&hellip;" 
170        tooltip="Run a plugin" 
171        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
172      />
173      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
174        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
175      <tbl:button
176        image="help.gif"
177        onclick="<%="Main.openHelp('" + ID +"', 'itemsubtype.view.properties')"%>"
178        title="Help&hellip;"
179        tooltip="Get help about this page"
180      />
181      </tbl:toolbar>
182    <div class="boxedbottom">
183      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(subtype)%></i></div>
184      <%
185      if (subtype.isRemoved())
186      {
187        %>
188        <div class="itemstatus">
189          <base:icon 
190            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
191            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
192            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
193            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
194          <base:icon image="used.gif" 
195            onclick="showUsingItems()"
196            tooltip="Show the items that are using this one"
197            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
198        </div>
199        <%
200      }
201      %>
202      <table class="form" cellspacing=0>
203      <tr>
204        <td class="prompt">Name</td>
205        <td><%=HTML.encodeTags(subtype.getName())%></td>
206      </tr>
207      <tr>
208        <td class="prompt">Main item type</td>
209        <td><%=subtype.getMainItemType()%></td>
210      </tr>
211      <tr>
212        <td class="prompt">Registered</td>
213        <td><%=dateFormatter.format(subtype.getEntryDate())%></td>
214      </tr>
215      <tr>
216        <td class="prompt">System ID</td>
217        <td><%=HTML.encodeTags(subtype.getSystemId())%></td>
218      </tr>
219      <tr>
220        <td class="prompt">Description</td>
221        <td><%=HTML.niceFormat(subtype.getDescription())%></td>
222      </tr>
223      <tr>
224        <td class="prompt">Related subtypes</td>
225        <td></td>
226      </tr>
227      <%
228      for (Item relatedItem : ItemSubtype.getRelatedItems(subtype.getMainItemType()))
229      {
230        ItemSubtype related = null;
231        boolean deniedRelated = false;
232        try
233        {
234          related = subtype.getRelatedSubtype(relatedItem);
235        }
236        catch (PermissionDeniedException ex)
237        {
238          deniedRelated = true;
239        }
240        %>
241        <tr>
242          <td class="subprompt"><%=relatedItem%></td>
243          <td><%=Base.getLinkedName(ID, related, deniedRelated, true)%></td>
244        </tr>
245        <%
246      }
247      %>
248      </table>
249
250      <%
251      ItemQuery<ItemSubtype> parentQuery = subtype.getParentSubtypes();
252      parentQuery.include(Include.ALL);
253      parentQuery.order(Orders.asc(Hql.property("name")));
254      ItemResultList<ItemSubtype> parents = parentQuery.list(dc);
255      if (parents.size() == 0)
256      {
257        %>
258        <h4>Subtypes with relation to this subtype</h4>
259        There are no subtypes (or, you don't have permission to view them).
260        <%
261      }
262      else
263      {
264        %>
265        <base:section 
266          id="parents" 
267          title="<%="Subtypes with relation to this subtype (" + parents.size() + ")"%>"
268          context="<%=cc%>"
269          >       
270          <tbl:table
271            id="parents"
272            clazz="itemlist"
273            columns="all"
274            >
275            <tbl:columndef 
276              id="name"
277              title="Name"
278            />
279            <tbl:columndef 
280              id="mainType"
281              title="Main item type"
282            />
283            <tbl:columndef 
284              id="description"
285              title="Description"
286            />
287            <tbl:data>
288              <tbl:columns>
289              </tbl:columns>
290              <tbl:rows>
291              <%
292              for (ItemSubtype parent : parents)
293              {
294                %>
295                <tbl:row>
296                  <tbl:cell column="name"><base:icon 
297                      image="deleted.gif" 
298                      tooltip="This item has been scheduled for deletion" 
299                      visible="<%=parent.isRemoved()%>"
300                    /><%=Base.getLinkedName(ID, parent, false, true)%></tbl:cell>
301                  <tbl:cell column="mainType"><%=parent.getMainItemType() %></tbl:cell>
302                  <tbl:cell column="description"><%=HTML.encodeTags(parent.getDescription())%></tbl:cell>
303                </tbl:row>
304                <%
305              }
306              %>
307              </tbl:rows>
308            </tbl:data>
309          </tbl:table>
310        </base:section>
311        <%
312      }
313      %>
314
315      <jsp:include page="../../common/anytoany/list_anytoany.jsp">
316        <jsp:param name="ID" value="<%=ID%>" />
317        <jsp:param name="item_type" value="<%=itemType.name()%>" />
318        <jsp:param name="item_id" value="<%=itemId%>" />
319        <jsp:param name="title" value="Other items related to this item subtype" />
320      </jsp:include>
321     
322    </div>
323      </t:tab>
324      </t:tabcontrol>
325
326  </base:body>
327  </base:page>
328  <%
329}
330finally
331{
332  if (dc != null) dc.close();
333}
334
335%>
Note: See TracBrowser for help on using the repository browser.