source: trunk/www/lims/plates/view_plate.jsp @ 5044

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

References #360 Covering the submenu items in 'Biomaterial LIMS' and 'Array LIMS' menus.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.5 KB
Line 
1<%-- $Id: view_plate.jsp 5044 2009-08-11 14:35:03Z 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.Group"
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.AnnotationType"
35  import="net.sf.basedb.core.AnnotationSet"
36  import="net.sf.basedb.core.Plate"
37  import="net.sf.basedb.core.PlateType"
38  import="net.sf.basedb.core.PlateGeometry"
39  import="net.sf.basedb.core.PlateMapping"
40  import="net.sf.basedb.core.User"
41  import="net.sf.basedb.core.ItemQuery"
42  import="net.sf.basedb.core.Include"
43  import="net.sf.basedb.core.ItemResultIterator"
44  import="net.sf.basedb.core.ItemResultList"
45  import="net.sf.basedb.core.MultiPermissions"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.PluginDefinition"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.core.plugin.Plugin"
50  import="net.sf.basedb.core.Project"
51  import="net.sf.basedb.core.query.Orders"
52  import="net.sf.basedb.core.query.Hql"
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.Collections"
65  import="java.util.Date"
66  import="java.util.Map"
67  import="java.util.Set"
68  import="java.util.List"
69%>
70<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
71<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
72<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
73<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
74<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
75<%!
76  private static final Item itemType = Item.PLATE;
77  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
78%>
79<%
80final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
81final String ID = sc.getId();
82final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
83final int itemId = cc.getId();
84final String tab = Values.getString(request.getParameter("tab"), "properties");
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  Plate plate = Plate.getById(dc, itemId);
94 
95  PlateMapping currentPlateMapping = null;
96  try
97  {
98    currentPlateMapping = plate.getPlateMapping();
99  }
100  catch (PermissionDeniedException ex)
101  {}
102 
103  final boolean writePermission = plate.hasPermission(Permission.WRITE);
104  final boolean deletePermission = plate.hasPermission(Permission.DELETE);
105  final boolean sharePermission = plate.hasPermission(Permission.SET_PERMISSION);
106  final boolean setOwnerPermission = plate.hasPermission(Permission.SET_OWNER);
107  final boolean isRemoved = plate.isRemoved();
108  final boolean isUsed = isRemoved && plate.isUsed();
109  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
110  final boolean isOwner = plate.isOwner();
111  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, plate);
112  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
113  %>
114  <base:page title="<%=title%>">
115  <base:head scripts="tabcontrol.js,table.js" styles="toolbar.css,table.css,headertabcontrol.css,path.css">
116    <ext:scripts context="<%=jspContext%>" />
117    <ext:stylesheets context="<%=jspContext%>" />
118    <script language="JavaScript">
119    function editItem()
120    {
121      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
122    }
123    function shareItem()
124    {
125      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'SharePlate', 600, 400);
126    }
127    function deleteItem()
128    {
129      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
130    }
131    function restoreItem()
132    {
133      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
134    }
135    function deleteItemPermanently()
136    {
137      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
138    }
139    function itemDeleted()
140    {
141      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
142    }
143    function showUsingItems()
144    {
145      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
146    }
147    function setOwner()
148    {
149      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
150    }
151    function runPlugin(cmd)
152    {
153      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
154    }
155    function viewWells()
156    {
157      location.href = 'wells/index.jsp?ID=<%=ID%>&plate_id=<%=itemId%>';
158    }
159    function viewEvents()
160    {
161      location.href = 'events/index.jsp?ID=<%=ID%>&plate_id=<%=itemId%>';
162    }
163    function switchTab(tabControlId, tabId)
164    {
165      if (tabId == 'events')
166      {
167        viewEvents();
168      }
169      else if (tabId == 'wells')
170      {
171        viewWells();
172      }
173      else
174      {
175        TabControl.setActiveTab(tabControlId, tabId);
176      }
177    }
178    </script>
179  </base:head>
180  <base:body>
181    <p>
182    <p:path>
183      <p:pathelement title="Plates" href="<%="index.jsp?ID="+ID%>" />
184      <p:pathelement title="<%=HTML.encodeTags(plate.getName())%>" />
185    </p:path>
186   
187    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab">
188    <t:tab id="properties" title="Properties">
189    <tbl:toolbar
190      >
191      <tbl:button 
192        disabled="<%=writePermission ? false : true%>" 
193        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
194        onclick="editItem()" 
195        title="Edit&hellip;" 
196        tooltip="<%=writePermission ? "Edit this plate" : "You do not have permission to edit this plate"%>" 
197      />
198      <tbl:button 
199        disabled="<%=deletePermission ? false : true%>" 
200        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
201        onclick="deleteItem()" 
202        title="Delete"
203        visible="<%=!plate.isRemoved()%>"
204        tooltip="<%=deletePermission ? "Delete this plate" : "You do not have permission to delete this plate"%>" 
205      />
206      <tbl:button 
207        disabled="<%=writePermission ? false : true%>" 
208        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
209        onclick="restoreItem()" 
210        title="Restore"
211        visible="<%=plate.isRemoved()%>"
212        tooltip="<%=writePermission ? "Restore this plate" : "You do not have permission to restore this plate"%>" 
213      />
214      <tbl:button 
215        disabled="<%=sharePermission ? false : true%>"
216        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
217        onclick="shareItem()" 
218        title="Share&hellip;" 
219        tooltip="<%=sharePermission ? "Share this plate to other user, groups and projects" : "You do not have permission to share this plate"%>"
220      />
221      <tbl:button 
222        disabled="<%=setOwnerPermission ? false : true%>"
223        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
224        onclick="setOwner()" 
225        title="Set owner&hellip;"
226        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
227      />
228      <tbl:button 
229        image="import.gif" 
230        onclick="runPlugin('ImportItem')" 
231        title="Import&hellip;" 
232        tooltip="Import data" 
233        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
234      />
235      <tbl:button 
236        image="export.gif" 
237        onclick="runPlugin('ExportItem')" 
238        title="Export&hellip;" 
239        tooltip="Export data" 
240        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
241      />
242      <tbl:button 
243        image="runplugin.gif" 
244        onclick="runPlugin('RunPlugin')" 
245        title="Run plugin&hellip;" 
246        tooltip="Run a plugin" 
247        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
248      />
249      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
250        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
251      <tbl:button
252        image="help.gif"
253        onclick="<%="Main.openHelp('" + ID +"', 'plate.view.properties')"%>"
254        title="Help&hellip;"
255        tooltip="Get help about this page"
256      />
257      </tbl:toolbar>
258    <div class="boxedbottom">
259      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(plate)%></i></div>
260      <%
261      if (plate.isRemoved() || plate.isShared())
262      {
263        %>
264        <div class="itemstatus">
265          <base:icon 
266            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
267            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
268            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
269            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
270          <base:icon image="used.gif" 
271            onclick="showUsingItems()"
272            tooltip="Show the items that are using this one"
273            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
274          <base:icon image="shared.gif" 
275            visible="<%=plate.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
276        </div>
277        <%
278      }
279      %>
280      <table class="form" cellspacing="0">
281      <tr>
282        <td class="prompt">Name</td>
283        <td><%=HTML.encodeTags(plate.getName())%></td>
284      </tr>
285      <tr>
286        <td class="prompt">Registered</td>
287        <td><%=dateFormatter.format(plate.getEntryDate())%></td>
288      </tr>
289      <tr>
290        <td class="prompt">Barcode</td>
291        <td><%=HTML.encodeTags(plate.getBarcode())%></td>
292      </tr>
293      <tr>
294        <td class="prompt">Destroyed</td>
295        <td><%=plate.isDestroyed() ? "yes" : "no"%></td>
296      </tr>
297      <tr>
298        <td class="prompt">Type</td>
299        <td><base:propertyvalue item="<%=plate%>" property="plateType" /></td>
300      </tr>
301      <tr>
302        <td class="prompt">Geometry</td>
303        <td><base:propertyvalue item="<%=plate%>" property="plateType.plateGeometry" /></td>
304      </tr>
305      <tr valign="baseline">
306        <td class="prompt">Merge mapping</td>
307        <td><%
308          if (currentPlateMapping != null && currentPlateMapping.getImage() != null)
309          {
310            %>
311            <img id="mappingImage" src="../../images/platemappings/<%=currentPlateMapping.getImage()%>" align="right">
312            <%
313          }
314          %>
315          <base:propertyvalue item="<%=plate%>" property="plateMapping" />
316        </td>
317      </tr>
318      <tr>
319        <td class="prompt">Owner</td>
320        <td><base:propertyvalue item="<%=plate%>" property="owner" /></td>
321      </tr>
322      <tr>
323        <td class="prompt">Description</td>
324        <td><%=HTML.niceFormat(plate.getDescription())%></td>
325      </tr>
326      </table>
327     
328      <%
329      ItemQuery<Plate> parentPlatesQuery = plate.getParentPlates();
330      parentPlatesQuery.include(Include.ALL);
331      parentPlatesQuery.order(Orders.asc(Hql.property("name")));
332      ItemResultList<Plate> parentPlates = parentPlatesQuery.list(dc);
333      if (parentPlates.size() == 0)
334      {
335        %>
336        <h4>Parent plates</h4>
337        This plate doesn't have any parents (or, you don't have permission to view them).
338        <%
339      }
340      else
341      {
342        %>
343        <base:section
344          id="parents"
345          title="<%="Parent plates (" + parentPlates.size() + ")"%>"
346          context="<%=cc%>"
347          >
348          <tbl:table
349            id="parentplates"
350            clazz="itemlist"
351            columns="all"
352            >
353          <tbl:columndef 
354            id="name"
355            title="Name"
356          />
357          <tbl:columndef 
358            id="index"
359            title="Index"
360          />
361          <tbl:columndef 
362            id="description"
363            title="Description"
364          />
365          <tbl:data>
366            <tbl:columns>
367            </tbl:columns>
368            <tbl:rows>
369            <%
370            for (Plate item : parentPlates)
371            {
372              %>
373              <tbl:row>
374                <tbl:cell column="name"><base:icon 
375                    image="deleted.gif" 
376                    tooltip="This item has been scheduled for deletion" 
377                    visible="<%=item.isRemoved()%>"
378                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
379                <tbl:cell column="index"><%=plate.getSourceIndex(item)+1%></tbl:cell>
380                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
381              </tbl:row>
382              <%
383            }
384            %>
385            </tbl:rows>
386          </tbl:data>
387          </tbl:table>
388        </base:section>
389        <%
390      }
391      %>
392      <%
393      ItemQuery<Plate> childPlatesQuery = plate.getChildPlates();
394      childPlatesQuery.include(Include.ALL);
395      childPlatesQuery.order(Orders.asc(Hql.property("name")));
396      ItemResultList<Plate> childPlates = childPlatesQuery.list(dc);
397      if (childPlates.size() == 0)
398      {
399        %>
400        <h4>Child plates</h4>
401        This plate doesn't have any children (or, you don't have permission to view them).
402        <%
403      }
404      else
405      {
406        %>
407        <base:section
408          id="children"
409          title="<%="Child plates (" + childPlates.size() + ")"%>"
410          context="<%=cc%>"
411          >
412          <tbl:table
413            id="childplates"
414            clazz="itemlist"
415            columns="all"
416            >
417          <tbl:columndef 
418            id="name"
419            title="Name"
420          />
421          <tbl:columndef
422            id="mapping"
423            title="Mapping"
424          />
425          <tbl:columndef 
426            id="index"
427            title="Index"
428          />
429          <tbl:columndef 
430            id="description"
431            title="Description"
432          />
433          <tbl:data>
434            <tbl:columns>
435            </tbl:columns>
436            <tbl:rows>
437            <%
438            for (Plate item : childPlates)
439            {
440              %>
441              <tbl:row>
442                <tbl:cell column="name"><base:icon 
443                    image="deleted.gif" 
444                    tooltip="This item has been scheduled for deletion" 
445                    visible="<%=item.isRemoved()%>"
446                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
447                <tbl:cell column="mapping"><base:propertyvalue item="<%=item%>" property="plateMapping" /></tbl:cell>
448                <tbl:cell column="index"><%=item.getSourceIndex(plate) + 1%></tbl:cell>
449                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
450              </tbl:row>
451              <%
452            }
453            %>
454            </tbl:rows>
455          </tbl:data>
456          </tbl:table>
457        </base:section>
458        <%
459      }     
460     
461      // Tables with users/groups/projects that this item is shared to
462      MultiPermissions mp = new MultiPermissions(Collections.singleton(plate));
463      ItemResultList<User> users = mp.getUsers().list(dc);
464      ItemResultList<Group> groups = mp.getGroups().list(dc);
465      ItemResultList<Project> projects = mp.getProjects().list(dc);
466      int totalShare = users.size() + groups.size() + projects.size();
467     
468      if (totalShare > 0)
469      {
470        %>
471        <base:section
472          id="sharedTo"
473          title="<%="Shared to (" + totalShare + ")"%>"
474          context="<%=cc%>"
475          >
476          <tbl:table 
477            id="itemsSharedTo"
478            clazz="itemlist"
479            columns="all"
480          >
481            <tbl:columndef 
482              id="itemType"
483              title="Item type"
484            />
485            <tbl:columndef 
486              id="name"
487              title="Name"
488            />
489            <tbl:columndef 
490              id="permissions"
491              title="Permissions"
492            />
493            <tbl:data>
494              <tbl:columns>
495              </tbl:columns>
496              <tbl:rows>
497              <%
498              for (Project project : projects)               
499              {
500                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
501                %>     
502                <tbl:row>
503                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
504                  <tbl:cell column="name"><base:icon 
505                    image="deleted.gif" 
506                    tooltip="This item has been scheduled for deletion" 
507                    visible="<%=project.isRemoved()%>"
508                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
509                  <tbl:cell column="permissions">
510                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
511                  </tbl:cell>
512                </tbl:row>
513                <%
514              }
515              for (Group group : groups)
516              {
517                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
518                %>
519                <tbl:row>             
520                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
521                  <tbl:cell column="name"><base:icon 
522                    image="deleted.gif" 
523                    tooltip="This item has been scheduled for deletion" 
524                    visible="<%=group.isRemoved()%>"
525                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
526                  <tbl:cell column="permissions">
527                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
528                  </tbl:cell>
529                </tbl:row>
530                <% 
531              }
532              for (User user : users)
533              {
534                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
535                %>
536                <tbl:row>             
537                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
538                  <tbl:cell column="name"><base:icon 
539                    image="deleted.gif" 
540                    tooltip="This item has been scheduled for deletion" 
541                    visible="<%=user.isRemoved()%>"
542                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
543                  <tbl:cell column="permissions">
544                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
545                  </tbl:cell>
546                </tbl:row>
547                <%
548              }
549              %>
550              </tbl:rows>
551            </tbl:data>
552          </tbl:table>
553        </base:section>
554        <%
555      }
556      else
557      {
558        %>
559        <h4>Shared to</h4>
560        This plate is not shared
561        (or, you don't have permission to view the ones it is shared to).
562        <%
563      }
564      %>
565
566
567    </div>
568      </t:tab>
569     
570      <t:tab id="annotations" title="Annotations" >
571        <div class="boxed">
572        <jsp:include page="../../common/annotations/list_annotations.jsp">
573          <jsp:param name="item_type" value="<%=itemType.name()%>" />
574          <jsp:param name="item_id" value="<%=itemId%>" />
575          <jsp:param name="ID" value="<%=ID%>" />
576        </jsp:include>
577        </div>
578      </t:tab>
579     
580      <t:tab id="events" title="Events" />
581      <t:tab id="wells" title="Wells" />
582      </t:tabcontrol>
583
584  </base:body>
585  </base:page>
586  <%
587}
588finally
589{
590  if (dc != null) dc.close();
591}
592
593%>
Note: See TracBrowser for help on using the repository browser.