source: trunk/www/biomaterials/events/view_event.jsp @ 6261

Last change on this file since 6261 was 6261, checked in by Nicklas Nordborg, 10 years ago

References #1729 and #1730. Fixed for all biomaterial view pages.

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