source: trunk/www/biomaterials/extracts/view_extract.jsp @ 2917

Last change on this file since 2917 was 2917, checked in by Nicklas Nordborg, 17 years ago

References #348: Take ownership of items

Implemented on all biomaterial pages

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.6 KB
Line 
1<%-- $Id: view_extract.jsp 2917 2006-11-15 10:28:36Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.SystemItems"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Extract"
35  import="net.sf.basedb.core.LabeledExtract"
36  import="net.sf.basedb.core.Sample"
37  import="net.sf.basedb.core.BioMaterialEvent"
38  import="net.sf.basedb.core.Protocol"
39  import="net.sf.basedb.core.User"
40  import="net.sf.basedb.core.ItemQuery"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.Include"
43  import="net.sf.basedb.core.query.Orders"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.core.query.Restrictions"
46  import="net.sf.basedb.core.query.Expressions"
47  import="net.sf.basedb.core.PermissionDeniedException"
48  import="net.sf.basedb.core.PluginDefinition"
49  import="net.sf.basedb.core.plugin.GuiContext"
50  import="net.sf.basedb.core.plugin.Plugin"
51  import="net.sf.basedb.core.Type"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.PermissionUtil"
54  import="net.sf.basedb.clients.web.util.HTML"
55  import="net.sf.basedb.util.Values"
56  import="java.util.Date"
57  import="java.util.Map"
58  import="java.util.Set"
59  import="java.util.List"
60%>
61<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
62<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
63<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
64<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
65<%!
66  private static final Item itemType = Item.EXTRACT;
67  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
68%>
69<%
70final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
71final String ID = sc.getId();
72final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
73final int itemId = cc.getId();
74final String tab = Values.getString(request.getParameter("tab"), "properties");
75final float scale = Base.getScale(sc);
76final DbControl dc = sc.newDbControl();
77try
78{
79  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
80
81  String title = null;
82  Extract extract = Extract.getById(dc, itemId);
83  BioMaterialEvent creationEvent = extract.getCreationEvent();
84 
85  final boolean writePermission = extract.hasPermission(Permission.WRITE);
86  final boolean deletePermission = extract.hasPermission(Permission.DELETE);
87  final boolean sharePermission = extract.hasPermission(Permission.SET_PERMISSION);
88  final boolean usePermission = extract.hasPermission(Permission.USE);
89  final boolean setOwnerPermission = extract.hasPermission(Permission.SET_OWNER);
90  final boolean isOwner = extract.isOwner(); 
91  %>
92
93  <base:page title="<%=title%>">
94  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
95    <script language="JavaScript">
96    function editItem()
97    {
98      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
99    }
100    function shareItem()
101    {
102      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareExtract', 500, 400);
103    }
104    function deleteItem()
105    {
106      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
107    }
108    function restoreItem()
109    {
110      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
111    }
112    function takeOwnership()
113    {
114      if (confirm('Are you sure that you want to take ownership of this item? It can\'t be undone.'))
115      {
116        location.replace('index.jsp?ID=<%=ID%>&cmd=TakeOwnershipOfItem&item_id=<%=itemId%>');
117      }
118    }
119    function runPlugin(cmd)
120    {
121      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
122    }
123    function viewEvents()
124    {
125      location.href = '../events/index.jsp?ID=<%=ID%>&cmd=List&biomaterial_id=<%=itemId%>&biomaterial_type=<%=itemType.name()%>';
126    }
127    function switchTab(tabControlId, tabId)
128    {
129      if (tabId == 'events')
130      {
131        viewEvents();
132      }
133      else
134      {
135        TabControl.setActiveTab(tabControlId, tabId);
136      }
137    }
138    function newLabeledExtract()
139    {
140      Main.viewOrEditItem('<%=ID%>', 'LABELEDEXTRACT', 0, true, '&extract_id=<%=itemId%>')
141    }
142    </script>
143  </base:head>
144  <base:body>
145    <p>
146    <p:path>
147      <p:pathelement title="Extracts" href="<%="index.jsp?ID="+ID%>" />
148      <p:pathelement title="<%=HTML.encodeTags(extract.getName())%>" />
149    </p:path>
150   
151    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab">
152    <t:tab id="properties" title="Properties">
153
154    <tbl:toolbar
155      >
156      <tbl:button 
157        disabled="<%=writePermission ? false : true%>" 
158        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
159        onclick="editItem()" 
160        title="Edit&hellip;" 
161        tooltip="<%=writePermission ? "Edit this extract" : "You do not have permission to edit this extract"%>" 
162      />
163      <tbl:button 
164        disabled="<%=deletePermission ? false : true%>" 
165        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
166        onclick="deleteItem()" 
167        title="Delete"
168        visible="<%=!extract.isRemoved()%>"
169        tooltip="<%=deletePermission ? "Delete this extract" : "You do not have permission to delete this extract"%>" 
170      />
171      <tbl:button 
172        disabled="<%=writePermission ? false : true%>" 
173        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
174        onclick="restoreItem()" 
175        title="Restore"
176        visible="<%=extract.isRemoved()%>"
177        tooltip="<%=writePermission ? "Restore this extract" : "You do not have permission to restore this extract"%>" 
178      />
179      <tbl:button 
180        disabled="<%=sharePermission ? false : true%>"
181        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
182        onclick="shareItem()" 
183        title="Share&hellip;" 
184        tooltip="<%=sharePermission ? "Share this extract to other user, groups and projects" : "You do not have permission to share this extract"%>"
185      />
186      <tbl:button 
187        disabled="<%=setOwnerPermission ? false : true%>"
188        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
189        onclick="takeOwnership()" 
190        title="Take ownership&hellip;"
191        visible="<%=!isOwner%>"
192        tooltip="<%=setOwnerPermission ? "Take ownership of this item" : "You do not have permission to take ownership of this item"%>"
193      />
194      <tbl:button
195        image="add.png"
196        onclick="newLabeledExtract()"
197        title="New labeled extract&hellip;"
198        tooltip="Create a new labeled extract from this extract"
199        visible="<%=sc.hasPermission(Permission.CREATE, Item.LABELEDEXTRACT) && usePermission %>"
200      />
201      <tbl:button 
202        image="import.gif" 
203        onclick="runPlugin('ImportItem')" 
204        title="Import&hellip;" 
205        tooltip="Import data" 
206        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
207      />
208      <tbl:button 
209        image="export.gif" 
210        onclick="runPlugin('ExportItem')" 
211        title="Export&hellip;" 
212        tooltip="Export data" 
213        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
214      />
215      <tbl:button 
216        image="runplugin.gif" 
217        onclick="runPlugin('RunPlugin')" 
218        title="Run plugin&hellip;" 
219        tooltip="Run a plugin" 
220        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
221      />
222      <tbl:button
223        image="help.gif"
224        onclick="<%="Main.openHelp('" + ID +"', 'extract.view.properties')"%>"
225        title="Help&hellip;"
226        tooltip="Get help about this page"
227      />
228      </tbl:toolbar>
229    <div class="boxedbottom">
230      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(extract)%></i></div>
231      <%
232      if (extract.isRemoved() || extract.isShared())
233      {
234        %>
235        <div class="itemstatus">
236          <base:icon image="deleted.gif" 
237            visible="<%=extract.isRemoved()%>"> This item has been flagged for deletion<br></base:icon>
238          <base:icon image="shared.gif" 
239            visible="<%=extract.isShared()%>"> This item is shared to other user, 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(extract.getName())%></td>
248      </tr>
249      <tr>
250        <td class="prompt">External ID</td>
251        <td><%=HTML.encodeTags(extract.getExternalId())%></td>
252      </tr>
253      <tr>
254        <td class="prompt">Created</td>
255        <td><%=Values.formatDate(creationEvent.getEventDate())%></td>
256      </tr>
257      <tr>
258        <td class="prompt">Registered</td>
259        <td><%=Values.formatDate(creationEvent.getEntryDate())%></td>
260      </tr>
261      <%
262      if (!extract.isPooled())
263      {
264        %>
265        <tr>
266          <td class="prompt">Sample</td>
267          <td><base:propertyvalue item="<%=extract%>" property="parent"/> 
268            <%
269            try
270            {
271            %>
272              <%=extract.getSample() != null ? "(" + Values.formatNumber(creationEvent.getUsedQuantity(extract.getSample()), 2, " µg") + ")" : ""%>
273            <%
274            }
275            catch (PermissionDeniedException ex)
276            {}
277            %> 
278
279          </td>
280        </tr>
281        <%
282      }
283      %>
284      <tr>
285        <td class="prompt">Protocol</td>
286        <td><base:propertyvalue item="<%=creationEvent%>" property="protocol"/></td>
287      </tr>
288      <tr>
289        <td class="prompt">Original quantity</td>
290        <td><%=Values.formatNumber(extract.getOriginalQuantity(), 2, " µg")%></td>
291      </tr>
292      <tr>
293        <td class="prompt">Remaining quantity</td>
294        <td><%=Values.formatNumber(extract.getRemainingQuantity(), 2, " µg")%></td>
295      </tr>
296      <tr>
297        <td class="prompt">Owner</td>
298        <td><base:propertyvalue item="<%=extract%>" property="owner"/></td>
299      </tr>
300      <tr valign="baseline">
301        <td class="prompt">Description</td>
302        <td><%=HTML.niceFormat(extract.getDescription())%></td>
303      </tr>
304      </table>
305 
306      <%
307      if (extract.isPooled())
308      {
309        ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)creationEvent.getSources();
310        extractsQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
311        extractsQuery.order(Orders.asc(Hql.property("name")));
312        ItemResultList<Extract> extracts = extractsQuery.list(dc);
313        String extractLink = "index.jsp?ID="+ID;
314        %>
315        <h4 class="docked">Pooled from extracts</h4>
316        <tbl:table
317          id="pooled"
318          clazz="itemlist"
319          columns="all"
320          >
321        <tbl:columndef 
322          id="name"
323          title="Name"
324        />
325        <tbl:columndef 
326          id="quantity"
327          title="Used quantity (µg)"
328        />
329        <tbl:columndef 
330          id="description"
331          title="Description"
332        />
333        <tbl:data>
334          <tbl:columns>
335          </tbl:columns>
336          <tbl:rows>
337          <%
338          for (Extract item : extracts)
339          {
340            %>
341            <tbl:row>
342              <tbl:cell column="name"><%=Base.getEncodedName(item, false, extractLink)%></tbl:cell>
343              <tbl:cell column="quantity"><%=Values.formatNumber(creationEvent.getUsedQuantity(item), 2)%></tbl:cell>
344              <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
345            </tbl:row>
346            <%
347          }
348          %>
349          </tbl:rows>
350        </tbl:data>
351        </tbl:table>
352        <%
353      }
354      ItemQuery<LabeledExtract> labeledExtractQuery = LabeledExtract.getQuery();
355      labeledExtractQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
356      labeledExtractQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter("extracts")));
357      labeledExtractQuery.setParameter("extracts", itemId, Type.INT);
358      labeledExtractQuery.order(Orders.asc(Hql.property("name")));
359      ItemResultList<LabeledExtract> labeledExtracts = labeledExtractQuery.list(dc);
360     
361      if (labeledExtracts.size() == 0)
362      {
363        %>
364        <h4>Labeled extracts</h4>
365        No labeled extracts have been created from this extract
366        (or you don't have the permission to view them)
367        <%
368      }
369      else
370      {
371        %>
372        <h4 class="docked">Labeled extracts</h4>
373        <tbl:table
374          id="labeledextracts"
375          clazz="itemlist"
376          columns="all"
377          >
378          <tbl:columndef
379            id="name"
380            title="Name"
381          />         
382          <tbl:columndef
383            id="description"
384            title="Description"
385          />
386          <tbl:data>
387            <tbl:columns></tbl:columns>
388            <tbl:rows>
389              <%
390              for (LabeledExtract lbe : labeledExtracts)
391              {
392                %>
393                <tbl:row>
394                  <tbl:cell column="name"><%=Base.getLinkedName(ID, lbe, false, true)%></tbl:cell>
395                  <tbl:cell column="description"><%=HTML.encodeTags(lbe.getDescription())%></tbl:cell>
396                </tbl:row>
397                <%
398              }
399              %>
400            </tbl:rows>
401          </tbl:data>
402        </tbl:table>
403        <%
404      }
405      %>
406     
407    </div>
408      </t:tab>
409     
410      <t:tab id="annotations" title="Annotations &amp; parameters" 
411        tooltip="View annotation values and protocol parameters">
412        <div class="boxed">
413        <jsp:include page="../../common/annotations/list_annotations.jsp">
414          <jsp:param name="item_type" value="<%=itemType.name()%>" />
415          <jsp:param name="item_id" value="<%=itemId%>" />
416          <jsp:param name="ID" value="<%=ID%>" />
417        </jsp:include>
418        </div>
419      </t:tab>
420     
421      <t:tab id="events" title="Events" />
422     
423      </t:tabcontrol>
424
425
426  </base:body>
427  </base:page>
428  <%
429}
430finally
431{
432  if (dc != null) dc.close();
433}
434
435%>
Note: See TracBrowser for help on using the repository browser.