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