source: trunk/www/views/hybridizations/view_hybridization.jsp @ 5045

Last change on this file since 5045 was 5045, checked in by Martin Svensson, 14 years ago

Fixes #360 Make subsections on view pages hideable.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.6 KB
Line 
1<%-- $Id: view_hybridization.jsp 5045 2009-08-12 07:42:51Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.SystemItems"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.Permission"
33  import="net.sf.basedb.core.AnnotationType"
34  import="net.sf.basedb.core.AnnotationSet"
35  import="net.sf.basedb.core.Hybridization"
36  import="net.sf.basedb.core.ArraySlide"
37  import="net.sf.basedb.core.BioMaterialEvent"
38  import="net.sf.basedb.core.Protocol"
39  import="net.sf.basedb.core.Scan"
40  import="net.sf.basedb.core.Group"
41  import="net.sf.basedb.core.Hardware"
42  import="net.sf.basedb.core.User"
43  import="net.sf.basedb.core.LabeledExtract"
44  import="net.sf.basedb.core.Label"
45  import="net.sf.basedb.core.MultiPermissions"
46  import="net.sf.basedb.core.ItemQuery"
47  import="net.sf.basedb.core.Include"
48  import="net.sf.basedb.core.ItemResultList"
49  import="net.sf.basedb.core.ItemResultList"
50  import="net.sf.basedb.core.PermissionDeniedException"
51  import="net.sf.basedb.core.PluginDefinition"
52  import="net.sf.basedb.core.plugin.GuiContext"
53  import="net.sf.basedb.core.plugin.Plugin"
54  import="net.sf.basedb.core.Project"
55  import="net.sf.basedb.core.query.Orders"
56  import="net.sf.basedb.core.query.Hql"
57  import="net.sf.basedb.clients.web.Base"
58  import="net.sf.basedb.clients.web.PermissionUtil"
59  import="net.sf.basedb.clients.web.util.HTML"
60  import="net.sf.basedb.util.Values"
61  import="net.sf.basedb.util.formatter.Formatter"
62  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
63  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
64  import="net.sf.basedb.clients.web.extensions.JspContext"
65  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
66  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
67  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
68  import="java.util.Collections"
69  import="java.util.Date"
70  import="java.util.Map"
71  import="java.util.Set"
72  import="java.util.List"
73%>
74<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
75<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
76<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
77<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
78<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
79<%!
80  private static final Item itemType = Item.HYBRIDIZATION;
81  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
82%>
83<%
84final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
85final String ID = sc.getId();
86final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
87final int itemId = cc.getId();
88final String tab = Values.getString(request.getParameter("tab"), "properties");
89final float scale = Base.getScale(sc);
90final DbControl dc = sc.newDbControl();
91try
92{
93  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
94  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
95
96  String title = null;
97  Hybridization hyb = Hybridization.getById(dc, itemId);
98  BioMaterialEvent creationEvent = hyb.getCreationEvent();
99 
100  final boolean usePermission = hyb.hasPermission(Permission.USE);
101  final boolean writePermission = hyb.hasPermission(Permission.WRITE);
102  final boolean deletePermission = hyb.hasPermission(Permission.DELETE);
103  final boolean sharePermission = hyb.hasPermission(Permission.SET_PERMISSION);
104  final boolean setOwnerPermission = hyb.hasPermission(Permission.SET_OWNER);
105  final boolean isRemoved = hyb.isRemoved();
106  final boolean isUsed = isRemoved && hyb.isUsed();
107  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
108  final boolean isOwner = hyb.isOwner();
109  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, hyb);
110  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
111  %>
112  <base:page title="<%=title%>">
113  <base:head scripts="table.js,tabcontrol.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css">
114    <ext:scripts context="<%=jspContext%>" />
115    <ext:stylesheets context="<%=jspContext%>" />
116    <script language="JavaScript">
117    function editItem()
118    {
119      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
120    }
121    function shareItem()
122    {
123      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareHybridization', 600, 400);
124    }
125    function deleteItem()
126    {
127      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
128    }
129    function restoreItem()
130    {
131      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
132    }
133    function deleteItemPermanently()
134    {
135      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
136    }
137    function itemDeleted()
138    {
139      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
140    }
141    function showUsingItems()
142    {
143      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
144    }
145    function setOwner()
146    {
147      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
148    }
149    function runPlugin(cmd)
150    {
151      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
152    }
153    function newScan()
154    {
155      Main.viewOrEditItem('<%=ID%>', 'SCAN', 0, true, '&hybridization_id=<%=itemId%>');
156    }
157    function switchTab(tabControlId, tabId)
158    {
159      if (TabControl.isActive(tabControlId, tabId)) return;
160      if (tabId == 'overview' && tabId != '<%=tab%>')
161      {
162        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=itemId%>&tab='+tabId;
163      }
164      else
165      {
166        TabControl.setActiveTab(tabControlId, tabId);
167      }
168    }
169   
170    </script>
171  </base:head>
172  <base:body>
173    <p>
174    <p:path>
175      <p:pathelement title="Hybridizations" href="<%="index.jsp?ID="+ID%>" />
176      <p:pathelement title="<%=HTML.encodeTags(hyb.getName())%>" />
177    </p:path>
178    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab" remember="false">
179    <t:tab id="properties" title="Properties">
180   
181    <tbl:toolbar
182      >
183      <tbl:button 
184        disabled="<%=writePermission ? false : true%>" 
185        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
186        onclick="editItem()" 
187        title="Edit&hellip;" 
188        tooltip="<%=writePermission ? "Edit this hybridization" : "You do not have permission to edit this hybridization"%>" 
189      />
190      <tbl:button 
191        disabled="<%=deletePermission ? false : true%>" 
192        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
193        onclick="deleteItem()" 
194        title="Delete"
195        visible="<%=!hyb.isRemoved()%>"
196        tooltip="<%=deletePermission ? "Delete this hybridization" : "You do not have permission to delete this hybridization"%>" 
197      />
198      <tbl:button 
199        disabled="<%=writePermission ? false : true%>" 
200        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
201        onclick="restoreItem()" 
202        title="Restore"
203        visible="<%=hyb.isRemoved()%>"
204        tooltip="<%=writePermission ? "Restore this hybridization" : "You do not have permission to restore this hybridization"%>" 
205      />
206      <tbl:button 
207        disabled="<%=sharePermission ? false : true%>"
208        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
209        onclick="shareItem()" 
210        title="Share&hellip;" 
211        tooltip="<%=sharePermission ? "Share this hybridization to other user, groups and projects" : "You do not have permission to share this hybridization"%>"
212      />
213      <tbl:button 
214        disabled="<%=setOwnerPermission ? false : true%>"
215        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
216        onclick="setOwner()" 
217        title="Set owner&hellip;"
218        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
219      />
220      <tbl:button
221        image="add.png"
222        onclick="newScan()"
223        title="New scan&hellip;"
224        tooltip="Create a new scan from this hybridization"
225        visible="<%=sc.hasPermission(Permission.CREATE, Item.SCAN) && usePermission%>"
226      />
227      <tbl:button 
228        image="import.gif" 
229        onclick="runPlugin('ImportItem')" 
230        title="Import&hellip;" 
231        tooltip="Import data" 
232        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
233      />
234      <tbl:button 
235        image="export.gif" 
236        onclick="runPlugin('ExportItem')" 
237        title="Export&hellip;" 
238        tooltip="Export data" 
239        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
240      />
241      <tbl:button 
242        image="runplugin.gif" 
243        onclick="runPlugin('RunPlugin')" 
244        title="Run plugin&hellip;" 
245        tooltip="Run a plugin" 
246        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
247      />
248      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
249        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
250      <tbl:button
251        image="help.gif"
252        onclick="<%="Main.openHelp('" + ID +"', 'hybridization.view.properties')"%>"
253        title="Help&hellip;"
254        tooltip="Get help about this page"
255      />
256      </tbl:toolbar>
257    <div class="boxedbottom">
258      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(hyb)%></i></div>
259      <%
260      if (hyb.isRemoved() || hyb.isShared())
261      {
262        %>
263        <div class="itemstatus">
264          <base:icon 
265            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
266            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
267            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
268            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
269          <base:icon image="used.gif" 
270            onclick="showUsingItems()"
271            tooltip="Show the items that are using this one"
272            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
273          <base:icon image="shared.gif" 
274            visible="<%=hyb.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
275        </div>
276        <%
277      }
278      %>
279      <table class="form" cellspacing="0">
280      <tr>
281        <td class="prompt">Name</td>
282        <td><%=HTML.encodeTags(hyb.getName())%></td>
283      </tr>
284      <tr>
285        <td class="prompt">Arrays</td>
286        <td><%=hyb.getNumArrays()%></td>
287      </tr>
288      <tr>
289        <td class="prompt">Array slide</td>
290        <td><base:propertyvalue item="<%=hyb%>" property="arraySlide" /></td>
291      </tr>
292      <tr>
293        <td class="subprompt">-barcode</td>
294        <td><base:propertyvalue item="<%=hyb%>" property="arraySlide.barcode" /></td>
295      </tr>
296      <tr>
297        <td class="prompt">Created</td>
298        <td><%=dateFormatter.format(creationEvent.getEventDate())%></td>
299      </tr>
300      <tr>
301        <td class="prompt">Registered</td>
302        <td><%=dateFormatter.format(creationEvent.getEntryDate())%></td>
303      </tr>
304      <tr>
305        <td class="prompt">Protocol</td>
306        <td><base:propertyvalue item="<%=creationEvent%>" property="protocol" /></td>
307      </tr>
308      <tr>
309        <td class="prompt">Hardware</td>
310        <td><base:propertyvalue item="<%=creationEvent%>" property="hardware" /></td>
311      </tr>
312      <tr>
313        <td class="prompt">Owner</td>
314        <td><base:propertyvalue item="<%=hyb%>" property="owner" /></td>
315      </tr>
316      <tr>
317        <td class="prompt">Description</td>
318        <td><%=HTML.niceFormat(hyb.getDescription())%></td>
319      </tr>
320      </table>
321     
322      <%
323      ItemQuery<LabeledExtract> labeledExtractsQuery = (ItemQuery<LabeledExtract>)creationEvent.getSources();
324      labeledExtractsQuery.include(Include.ALL);
325      labeledExtractsQuery.order(Orders.asc(Hql.property("name")));
326      ItemResultList<LabeledExtract> labeledExtracts = labeledExtractsQuery.list(dc);
327      if (labeledExtracts.size() == 0)
328      {
329        %>
330        <h4>Labeled extracts</h4>
331        No labeled extracts has been added to this hybridization
332        (or, you don't have permission to view them).
333        <%
334      }
335      else
336      {
337        %>
338        <base:section
339          id="labeledExtractSection"
340          title="<%="Labeled extracts (" + labeledExtracts.size() + ")"%>"
341          context="<%=cc%>"
342          >
343          <tbl:table
344            id="labeledextracts"
345            clazz="itemlist"
346            columns="all"
347            >
348          <tbl:columndef 
349            id="arrayNum"
350            title="Array"
351            show="<%=hyb.getNumArrays() > 1 ? "always" : "never"%>"
352          />
353          <tbl:columndef 
354            id="name"
355            title="Name"
356          />
357          <tbl:columndef 
358            id="label"
359            title="Label"
360          />
361          <tbl:columndef 
362            id="quantity"
363            title="Used quantity (µg)"
364          />
365          <tbl:columndef 
366            id="description"
367            title="Description"
368          />
369          <tbl:data>
370            <tbl:columns>
371            </tbl:columns>
372            <tbl:rows>
373            <%
374            for (LabeledExtract item : labeledExtracts)
375            {
376              %>
377              <tbl:row>
378                <tbl:cell column="arrayNum"><%=creationEvent.getSourceGroup(item)%></tbl:cell>
379                <tbl:cell column="name"><base:icon 
380                    image="deleted.gif" 
381                    tooltip="This item has been scheduled for deletion" 
382                    visible="<%=item.isRemoved()%>"
383                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
384                <tbl:cell column="label"><base:propertyvalue item="<%=item%>" property="label" /></tbl:cell>
385                <tbl:cell column="quantity"><%=Values.formatNumber(creationEvent.getUsedQuantity(item), 2)%></tbl:cell>
386                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
387              </tbl:row>
388              <%
389            }
390            %>
391            </tbl:rows>
392          </tbl:data>
393          </tbl:table>
394        </base:section>
395        <%
396      }
397      %>
398     
399      <%
400      ItemQuery<Scan> scanQuery = (ItemQuery<Scan>)hyb.getScans();
401      scanQuery.include(Include.ALL);
402      scanQuery.order(Orders.asc(Hql.property("name")));
403      ItemResultList<Scan> scans = scanQuery.list(dc);
404      if (scans.size() == 0)
405      {
406        %>
407        <h4>Scans</h4>
408        No scans has been created from this hybridization
409        (or, you don't have permission to view them).
410        <%
411      }
412      else
413      {
414        %>
415        <base:section
416          id="scanSection"
417          title="<%="Scans (" + scans.size() + ")"%>"
418          context="<%=cc%>"
419          >
420          <tbl:table
421            id="scans"
422            clazz="itemlist"
423            columns="all"
424            >
425          <tbl:columndef 
426            id="name"
427            title="Name"
428          />
429          <tbl:columndef 
430            id="scanner"
431            title="Scanner"
432          />
433 
434          <tbl:columndef 
435            id="description"
436            title="Description"
437          />
438          <tbl:data>
439            <tbl:columns>
440            </tbl:columns>
441            <tbl:rows>
442            <%
443            for (Scan item : scans)
444            {
445              %>
446              <tbl:row>
447                <tbl:cell column="name"><base:icon 
448                    image="deleted.gif" 
449                    tooltip="This item has been scheduled for deletion" 
450                    visible="<%=item.isRemoved()%>"
451                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
452                <tbl:cell column="scanner"><base:propertyvalue item="<%=item%>" property="scanner" /></tbl:cell>
453                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
454              </tbl:row>
455              <%
456            }
457            %>
458            </tbl:rows>
459          </tbl:data>
460          </tbl:table>
461        </base:section>
462        <%
463      }     
464     
465      // Tables with users/groups/projects that this item is shared to
466      MultiPermissions mp = new MultiPermissions(Collections.singleton(hyb));
467      ItemResultList<User> users = mp.getUsers().list(dc);
468      ItemResultList<Group> groups = mp.getGroups().list(dc);
469      ItemResultList<Project> projects = mp.getProjects().list(dc);
470      int totalShare = users.size() + groups.size() + projects.size();
471     
472      if (totalShare > 0)
473      {
474        %>
475        <base:section
476          id="sharedTo"
477          title="<%="Shared to (" + totalShare + ")"%>"
478          context="<%=cc%>"
479          >
480          <tbl:table 
481            id="itemsSharedTo"
482            clazz="itemlist"
483            columns="all"
484          >
485            <tbl:columndef 
486              id="itemType"
487              title="Item type"
488            />
489            <tbl:columndef 
490              id="name"
491              title="Name"
492            />
493            <tbl:columndef 
494              id="permissions"
495              title="Permissions"
496            />
497            <tbl:data>
498              <tbl:columns>
499              </tbl:columns>
500              <tbl:rows>
501              <%
502              for (Project project : projects)
503              {
504                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
505                %>     
506                <tbl:row>
507                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
508                  <tbl:cell column="name"><base:icon 
509                    image="deleted.gif" 
510                    tooltip="This item has been scheduled for deletion" 
511                    visible="<%=project.isRemoved()%>"
512                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
513                  <tbl:cell column="permissions">
514                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
515                  </tbl:cell>
516                </tbl:row>
517                <%
518              }
519              for (Group group : groups)
520              {
521                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
522                %>
523                <tbl:row>             
524                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
525                  <tbl:cell column="name"><base:icon 
526                    image="deleted.gif" 
527                    tooltip="This item has been scheduled for deletion" 
528                    visible="<%=group.isRemoved()%>"
529                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
530                  <tbl:cell column="permissions">
531                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
532                  </tbl:cell>
533                </tbl:row>
534                <% 
535              }
536              for (User user : users)
537              {
538                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
539                %>
540                <tbl:row>             
541                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
542                  <tbl:cell column="name"><base:icon 
543                    image="deleted.gif" 
544                    tooltip="This item has been scheduled for deletion" 
545                    visible="<%=user.isRemoved()%>"
546                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
547                  <tbl:cell column="permissions">
548                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
549                  </tbl:cell>
550                </tbl:row>
551                <%
552              }
553              %>
554              </tbl:rows>
555            </tbl:data>
556          </tbl:table>
557        </base:section>
558        <%
559      }
560      else
561      {
562        %>
563        <h4>Shared to</h4>
564        This hybridization is not shared
565        (or, you don't have permission to view the ones it is shared to).
566        <%
567      }
568      %>
569     
570    </div>
571      </t:tab>
572     
573      <t:tab id="annotations" title="Annotations &amp; parameters" 
574        tooltip="View annotation values and protocol parameters">
575        <div class="boxed">
576        <jsp:include page="../../common/annotations/list_annotations.jsp">
577          <jsp:param name="item_type" value="<%=itemType.name()%>" />
578          <jsp:param name="item_id" value="<%=itemId%>" />
579          <jsp:param name="ID" value="<%=ID%>" />
580        </jsp:include>
581        </div>
582      </t:tab>
583
584      <t:tab id="overview" title="Overview" 
585        tooltip="Display a tree overview of related items">
586        <%
587        if ("overview".equals(tab))
588        {
589          %>
590          <jsp:include page="../../common/overview/overview.jsp">
591            <jsp:param name="item_type" value="<%=itemType.name()%>" />
592            <jsp:param name="item_id" value="<%=itemId%>" />
593            <jsp:param name="ID" value="<%=ID%>" />
594          </jsp:include>
595          <%
596        }
597        %>
598      </t:tab>
599      </t:tabcontrol>
600
601  </base:body>
602  </base:page>
603  <%
604}
605finally
606{
607  if (dc != null) dc.close();
608}
609
610%>
Note: See TracBrowser for help on using the repository browser.