source: branches/3.2-stable/www/biomaterials/events/view_event.jsp @ 6251

Last change on this file since 6251 was 6251, checked in by Nicklas Nordborg, 9 years ago

Fixes #1746: The original and remaining quantity values are always displayed with 2 decimals

Needed to fix in a lot more places than I thought. Hope I have found all of them...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.3 KB
Line 
1<%-- $Id: view_event.jsp 6251 2013-03-13 14:45:39Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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.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.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.Permission"
32  import="net.sf.basedb.core.Plate"
33  import="net.sf.basedb.core.BioMaterial"
34  import="net.sf.basedb.core.BioMaterialEvent"
35  import="net.sf.basedb.core.BioMaterialEventSource"
36  import="net.sf.basedb.core.BioPlateEventParticipant"
37  import="net.sf.basedb.core.BioPlateEvent"
38  import="net.sf.basedb.core.BioPlate"
39  import="net.sf.basedb.core.MeasuredBioMaterial"
40  import="net.sf.basedb.core.PhysicalBioAssay"
41  import="net.sf.basedb.core.Protocol"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.core.ItemQuery"
44  import="net.sf.basedb.core.SpecialQuery"
45  import="net.sf.basedb.core.ItemResultList"
46  import="net.sf.basedb.core.Include"
47  import="net.sf.basedb.core.PluginDefinition"
48  import="net.sf.basedb.core.query.Orders"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.core.query.ResultList"
51  import="net.sf.basedb.core.plugin.GuiContext"
52  import="net.sf.basedb.core.plugin.Plugin"
53  import="net.sf.basedb.clients.web.Base"
54  import="net.sf.basedb.clients.web.PermissionUtil"
55  import="net.sf.basedb.clients.web.util.HTML"
56  import="net.sf.basedb.util.Values"
57  import="net.sf.basedb.util.formatter.Formatter"
58  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
59  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
60  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
61  import="net.sf.basedb.clients.web.extensions.JspContext"
62  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
63  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
64  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
65  import="java.util.Date"
66  import="java.util.Map"
67  import="java.util.Set"
68%>
69<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
70<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
71<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
72<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
73<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
74<%!
75  private static final Item itemType = Item.BIOMATERIALEVENT;
76  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
77%>
78<%
79final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
80final String ID = sc.getId();
81final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
82final int itemId = cc.getId();
83final Item bioMaterialType = Item.valueOf(request.getParameter("biomaterial_type"));
84final int bioMaterialId = Values.getInt(request.getParameter("biomaterial_id"));
85final float scale = Base.getScale(sc);
86final DbControl dc = sc.newDbControl();
87try
88{
89  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
90  int numDecimals = FormatterSettings.getNumDecimals(sc);
91  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
92
93  String title = null;
94  BioMaterialEvent event = BioMaterialEvent.getById(dc, itemId);
95  MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
96  BioMaterialEvent.Type eventType = event.getEventType();
97  boolean isPlateEvent = event.isPlateEvent();
98 
99  BioPlateEventParticipant participant = null;
100  BioPlateEvent plateEvent = null;
101  BioPlate plate = null;
102  if (isPlateEvent)
103  {
104    try
105    {
106      participant = event.getBioPlateEventParticipant();
107      plateEvent = participant.getEvent();
108      plate = participant.getBioPlate();
109    }
110    catch (RuntimeException ex)
111    {}
112  }
113 
114  String viewPage = null;
115  String listName = null;
116  if (bioMaterialType == Item.SAMPLE)
117  {
118    listName = "Samples";
119    viewPage = "../samples/index.jsp";
120  }
121  else if (bioMaterialType == Item.EXTRACT)
122  {
123    listName = "Extracts";
124    viewPage = "../extracts/index.jsp";
125  }
126
127  final boolean writePermission = event.hasPermission(Permission.WRITE) && eventType == BioMaterialEvent.Type.OTHER;
128  final boolean deletePermission = event.hasPermission(Permission.DELETE);
129  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, event);
130  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
131  %>
132  <base:page title="<%=title%>">
133  <base:head scripts="table.js,tabcontrol.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css">
134    <ext:scripts context="<%=jspContext%>" />
135    <ext:stylesheets context="<%=jspContext%>" />
136    <script language="JavaScript">
137    function editItem()
138    {
139      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true, '&biomaterial_type=<%=bioMaterialType.name()%>&biomaterial_id=<%=bioMaterial.getId()%>');
140    }
141    function deleteItem()
142    {
143      if (confirm('This can\'t be undone. Continue?'))
144      {
145        location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&&biomaterial_id=<%=bioMaterialId%>&biomaterial_type=<%=bioMaterialType.name()%>&item_id=<%=itemId%>');
146      }
147    }
148    function runPlugin(cmd)
149    {
150      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&biomaterial_id=<%=bioMaterialId%>&biomaterial_type=<%=bioMaterialType.name()%>&item_id=<%=itemId%>', 'RunPlugin'+cmd, 750, 500);
151    }
152    </script>
153  </base:head>
154  <base:body>
155    <p:path><p:pathelement 
156      title="<%=listName%>" href="<%=viewPage+"?ID="+ID%>" /><p:pathelement 
157      title="<%=HTML.encodeTags(bioMaterial.getName())%>" 
158        href="<%="index.jsp?ID="+ID+"&biomaterial_id="+bioMaterialId+"&biomaterial_type="+bioMaterialType.name()%>" 
159      /><p:pathelement title="Event" /></p:path>
160   
161    <t:tabcontrol id="main" 
162      subclass="content mastertabcontrol"
163      active="properties" switch="switchTab">
164    <t:tab id="properties" title="Properties">
165      <div>
166      <table class="fullform bottomborder">
167      <tr>
168        <th class="itemstatus"></th>
169        <td style="padding: 0px;" colspan="2">
170          <tbl:toolbar subclass="bottomborder">
171            <tbl:button 
172              disabled="<%=!writePermission%>" 
173              image="edit.png" 
174              onclick="editItem()" 
175              title="Edit&hellip;" 
176              tooltip="<%=writePermission ? "Edit this event" : "You do not have permission to edit this event"%>" 
177            />
178            <tbl:button 
179              disabled="<%=!deletePermission%>" 
180              image="delete.png" 
181              onclick="deleteItem()" 
182              title="Delete"
183              tooltip="<%=deletePermission ? "Delete this event" : "You do not have permission to event this event"%>" 
184            />
185            <tbl:button 
186              image="import.png" 
187              onclick="runPlugin('ImportItem')" 
188              title="Import&hellip;" 
189              tooltip="Import data" 
190              visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
191            />
192            <tbl:button 
193              image="export.png" 
194              onclick="runPlugin('ExportItem')" 
195              title="Export&hellip;" 
196              tooltip="Export data" 
197              visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
198            />
199            <tbl:button 
200              image="runplugin.png" 
201              onclick="runPlugin('RunPlugin')" 
202              title="Run plugin&hellip;" 
203              tooltip="Run a plugin" 
204              visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
205            />
206            <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
207              wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
208          </tbl:toolbar>
209        </td>
210      </tr>
211      <%
212      if (isPlateEvent)
213      {
214        %>
215        <tr>
216          <th>Releated plate event</th>
217          <td><%=Base.getLinkedName(ID, plateEvent, plateEvent == null, true) %></td>
218        </tr>
219        <tr>
220          <th class="subprompt">- bioplate</th>
221          <td><%=Base.getLinkedName(ID, plate, plate == null, true)%>
222          <%
223          if (participant != null)
224          {
225            %>
226            (<%=HTML.encodeTags(participant.getRole())%>)
227            <%
228          }
229          %>
230          </td>
231        </tr>
232        <tr>
233          <th class="subprompt">- event type</th>
234          <td><%
235            if (plateEvent != null)
236            {
237              %>
238              <base:propertyvalue item="<%=plateEvent%>" property="eventType" />
239              <%
240            }
241            %>
242          </td>
243        </tr>
244        <%
245      }
246      %>
247      <tr>
248        <th>Event date</th>
249        <td><%=dateFormatter.format(event.getEventDate())%></td>
250      </tr>
251      <tr>
252        <th>Registration date</th>
253        <td><%=dateFormatter.format(event.getEntryDate())%></td>
254      </tr>
255      <tr>
256        <th>Used quantity</th>
257        <td><%=Values.formatNumber(event.getUsedQuantity(bioMaterial), numDecimals, " µg")%></td>
258      </tr>
259      <tr>
260        <th>Event type</th>
261        <td><%=eventType%></td>
262      </tr>
263      <%
264      if (eventType != BioMaterialEvent.Type.OTHER)
265      {
266        if (eventType == BioMaterialEvent.Type.CREATION)
267        {         
268          %>
269          <tr>
270            <th>Product</th>
271            <td><base:propertyvalue item="<%=event%>" property="bioMaterial"/></td>
272          </tr>
273          <%
274        }
275        else if (eventType == BioMaterialEvent.Type.BIOASSAY)
276        {         
277          %>
278          <tr>
279            <th>Physical bioassay</th>
280            <td><base:propertyvalue item="<%=event%>" property="physicalBioAssay"/></td>
281          </tr>
282          <%
283        }
284        SpecialQuery<BioMaterialEventSource> sourcesQuery = event.getEventSources();
285        sourcesQuery.order(Orders.asc(Hql.property("bioMaterial.name")));
286        ResultList<BioMaterialEventSource> sources = sourcesQuery.list(dc);
287        %>
288        <tr class="big">
289          <th>Sources</th>
290          <td>
291          <%
292          for (BioMaterialEventSource evtSrc : sources)
293          {
294            BioMaterial source = null;
295            Item sourceType = null;
296            try
297            {
298              source = evtSrc.getBioMaterial();
299              sourceType = source.getType();
300            }
301            catch (PermissionDeniedException ex)
302            {}
303            %>
304            <%=Base.getLinkedName(ID, source, source == null, true)%>
305            <%=sourceType != null ? "(" + sourceType + ")" : "" %>
306            <%=Values.formatNumber(evtSrc.getUsedQuantity(), numDecimals, " µg")%>
307            <br>
308            <%
309          }
310          %>
311          </td>
312        </tr>
313        <%
314      }
315      %>
316      <tr>
317        <th>Protocol</th>
318        <td><base:propertyvalue item="<%=event%>" property="protocol"/></td>
319      </tr>
320      <tr>
321        <th>User</th>
322        <td><base:propertyvalue item="<%=event%>" property="user"/></td>
323      </tr>
324      <tr>
325        <th>Permissions</th>
326        <td><%=PermissionUtil.getFullPermissionNames(event)%></td>
327      </tr>
328      <tr>
329        <th>Comment</th>
330        <td><%=HTML.niceFormat(event.getComment())%></td>
331      </tr>
332      </table>
333     
334      <jsp:include page="../../common/anytoany/list_anytoany.jsp">
335        <jsp:param name="ID" value="<%=ID%>" />
336        <jsp:param name="item_type" value="<%=itemType.name()%>" />
337        <jsp:param name="item_id" value="<%=itemId%>" />
338        <jsp:param name="title" value="Other items related to this event" />
339      </jsp:include>
340
341      </t:tab>
342      </t:tabcontrol>
343
344  </base:body>
345  </base:page>
346  <%
347}
348finally
349{
350  if (dc != null) dc.close();
351}
352
353%>
Note: See TracBrowser for help on using the repository browser.