source: trunk/www/lims/platemappings/list_mappings.jsp @ 3095

Last change on this file since 3095 was 3095, checked in by Martin Svensson, 17 years ago

Fixed so the list page of plate mappings not are corrupt when user doesn't have read permission on
plate geometry.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.4 KB
Line 
1<%-- $Id: list_mappings.jsp 3095 2007-02-05 09:58:59Z martin $
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 session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.PlateMapping"
32  import="net.sf.basedb.core.PlateGeometry"
33  import="net.sf.basedb.core.ItemQuery"
34  import="net.sf.basedb.core.Include"
35  import="net.sf.basedb.core.ItemResultIterator"
36  import="net.sf.basedb.core.ItemResultList"
37  import="net.sf.basedb.core.ItemContext"
38  import="net.sf.basedb.core.Permission"
39  import="net.sf.basedb.core.PluginDefinition"
40  import="net.sf.basedb.core.query.Hql"
41  import="net.sf.basedb.core.query.Restrictions"
42  import="net.sf.basedb.core.query.Expressions"
43  import="net.sf.basedb.core.plugin.GuiContext"
44  import="net.sf.basedb.core.plugin.Plugin"
45  import="net.sf.basedb.core.query.Orders"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.util.Enumeration"
48  import="net.sf.basedb.clients.web.Base"
49  import="net.sf.basedb.clients.web.ModeInfo"
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.List"
54  import="java.util.Map"
55%>
56<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
57<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
58<%!
59  private static final Item itemType = Item.PLATEMAPPING;
60  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
61%>
62<%
63final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
64final String ID = sc.getId();
65final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
66final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
67
68final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
69final String callback = request.getParameter("callback");
70final String title = mode.generateTitle("plate mapping", "plate mappings");
71final DbControl dc = sc.newDbControl();
72ItemResultIterator<PlateMapping> mappings = null;
73try
74{
75  final ItemQuery<PlateMapping> query = Base.getConfiguredQuery(cc, true, PlateMapping.getQuery(), mode);
76
77  final ItemQuery<PlateGeometry> geometryQuery = PlateGeometry.getQuery();
78  geometryQuery.order(Orders.asc(Hql.property("name")));
79  geometryQuery.setCacheResult(true);
80 
81  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
82  try
83  {
84    mappings = query.iterate(dc);
85  }
86  catch (Throwable t)
87  {
88    cc.setMessage(t.getMessage());
89  }
90  int numListed = 0;
91  %>
92  <base:page title="<%=title==null ? "Plate mappings" : title%>" type="<%=mode.getPageType()%>">
93  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
94    <script language="JavaScript">
95    var submitPage = 'index.jsp';
96    var formId = 'mappings';
97    function newItem()
98    {
99      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
100    }
101    function editItem(itemId)
102    {
103      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
104    }
105    function viewItem(itemId)
106    {
107      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
108    }
109    function itemOnClick(evt, itemId)
110    {
111      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
112    }
113    function deleteItems()
114    {
115      var frm = document.forms[formId];
116      if (Forms.numChecked(frm) == 0)
117      {
118        alert('Please select at least one item in the list');
119        return;
120      }
121      frm.action = submitPage;
122      frm.cmd.value = 'DeleteItems';
123      frm.submit();
124    }
125    function restoreItems()
126    {
127      var frm = document.forms[formId];
128      if (Forms.numChecked(frm) == 0)
129      {
130        alert('Please select at least one item in the list');
131        return;
132      }
133      frm.action = submitPage;
134      frm.cmd.value = 'RestoreItems';
135      frm.submit();
136    }
137    function takeOwnership()
138    {
139      var frm = document.forms[formId];
140      if (Forms.numChecked(frm) == 0)
141      {
142        alert('Please select at least one item in the list');
143        return;
144      }
145      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
146      {
147        frm.action = submitPage;
148        frm.cmd.value = 'TakeOwnershipOfItems';
149        frm.submit();
150      }
151    }
152    function shareItem(itemId)
153    {
154      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareMappings', 500, 400);
155    }
156    function shareItems()
157    {
158      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
159    }
160    function configureColumns()
161    {
162      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
163    }
164    function runPlugin(cmd)
165    {
166      Table.submitToPopup(formId, cmd, 740, 540);
167    }
168    function returnSelected()
169    {
170      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
171      window.close();
172    }
173    function presetOnChange()
174    {
175      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
176    }
177    </script>
178  </base:head>
179 
180  <base:body>
181    <%
182    if (cc.getMessage() != null)
183    {
184      %>
185      <div class="error"><%=cc.getMessage()%></div>
186      <%
187      cc.setMessage(null);
188    }
189    %>
190    <tbl:table 
191      id="mappings" 
192      clazz="itemlist" 
193      columns="<%=cc.getSetting("columns")%>"
194      sortby="<%=cc.getSortProperty()%>" 
195      direction="<%=cc.getSortDirection()%>"
196      title="<%=title%>"
197      action="index.jsp"
198      sc="<%=sc%>"
199      item="<%=itemType%>"
200      >
201      <tbl:hidden 
202        name="mode" 
203        value="<%=mode.getName()%>" 
204      />
205      <tbl:hidden 
206        name="callback" 
207        value="<%=callback%>" 
208        skip="<%=callback == null%>" 
209      />
210      <tbl:columndef 
211        id="name"
212        property="name"
213        datatype="string"
214        title="Name"
215        sortable="true" 
216        filterable="true"
217        exportable="true"
218        show="always" 
219      />
220      <%
221      Enumeration<String, String> geometries = new Enumeration<String, String>();
222      ItemResultList<PlateGeometry> plateGeometries = geometryQuery.list(dc);
223      if (sc.hasPermission(Permission.READ, Item.PLATEGEOMETRY))
224      {
225        for (PlateGeometry pg : plateGeometries)
226        {
227          geometries.add(Integer.toString(pg.getId()), HTML.encodeTags(pg.getName()));
228        }
229      }
230      %>
231      <tbl:columndef 
232        id="sourceGeometry"
233        property="sourceGeometry"
234        sortproperty="sourceGeometry.name"
235        exportproperty="sourceGeometry.name"
236        datatype="int"
237        enumeration="<%=geometries%>"
238        title="Source geometry"
239        sortable="true" 
240        filterable="true"
241        exportable="true"
242      />
243      <tbl:columndef 
244        id="sourceCount"
245        property="sourceCount"
246        datatype="int"
247        title="Source plates"
248        sortable="true" 
249        filterable="true"
250        exportable="true"
251      />
252      <tbl:columndef 
253        id="destinationGeometry"
254        property="destinationGeometry"
255        sortproperty="destinationGeometry.name"
256        exportproperty="destinationGeometry.name"
257        datatype="int"
258        enumeration="<%=geometries%>"
259        title="Destination geometry"
260        sortable="true" 
261        filterable="true"
262        exportable="true"
263      />
264      <tbl:columndef 
265        id="destinationCount"
266        property="destinationCount"
267        datatype="int"
268        title="Destination plates"
269        sortable="true" 
270        filterable="true"
271        exportable="true"
272      />
273      <tbl:columndef 
274        id="owner"
275        property="owner.name"
276        datatype="string"
277        title="Owner"
278        sortable="true" 
279        filterable="true"
280        exportable="true"
281      />
282      <tbl:columndef 
283        id="description"
284        property="description"
285        datatype="string"
286        title="Description" 
287        sortable="true" 
288        filterable="true" 
289        exportable="true"
290      />
291      <tbl:columndef 
292        id="image"
293        property="image"
294        datatype="string"
295        title="Image" 
296        sortable="false" 
297        filterable="false" 
298        exportable="true"
299      />
300      <tbl:columndef
301        id="permission"
302        title="Permission"
303      />
304      <tbl:toolbar
305        visible="<%=mode.hasToolbar()%>"
306        >
307        <tbl:button 
308          image="delete.gif"
309          onclick="deleteItems()" 
310          title="Delete" 
311          tooltip="Delete the selected items" 
312        />
313        <tbl:button 
314          image="restore.gif"
315          onclick="restoreItems()" 
316          title="Restore" 
317          tooltip="Restore the selected (deleted) items"
318        />
319        <tbl:button 
320          image="share.gif"
321          onclick="shareItems()" 
322          title="Share&hellip;" 
323          tooltip="Share the selected items"
324        />
325        <tbl:button 
326          image="take_ownership.png"
327          onclick="takeOwnership()" 
328          title="Take ownership&hellip;"
329          tooltip="Take ownership of the selected items"
330        />
331        <tbl:button 
332          image="columns.gif" 
333          onclick="configureColumns()" 
334          title="Columns&hellip;" 
335          tooltip="Show, hide and re-order columns" 
336        />
337        <tbl:button 
338          image="import.gif" 
339          onclick="runPlugin('ImportItems')" 
340          title="Import&hellip;" 
341          tooltip="Import data" 
342          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
343        />
344        <tbl:button 
345          image="export.gif" 
346          onclick="runPlugin('ExportItems')" 
347          title="Export&hellip;" 
348          tooltip="Export data" 
349          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
350        />
351        <tbl:button 
352          image="runplugin.gif" 
353          onclick="runPlugin('RunListPlugin')" 
354          title="Run plugin&hellip;" 
355          tooltip="Run a plugin" 
356          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
357        />
358      </tbl:toolbar>
359      <tbl:navigator
360        page="<%=cc.getPage()%>" 
361        rowsperpage="<%=cc.getRowsPerPage()%>" 
362        totalrows="<%=mappings == null ? 0 : mappings.getTotalCount()%>" 
363        visible="<%=mode.hasNavigator()%>"
364      />
365      <tbl:data>
366        <tbl:columns>
367        <tbl:presetselector 
368          clazz="columnheader"
369          colspan="3"
370          onchange="presetOnChange()"
371        />
372        </tbl:columns>
373
374        <tr>
375          <tbl:header 
376            clazz="index"
377            >&nbsp;</tbl:header>
378          <tbl:header 
379            clazz="check" 
380            visible="<%=mode.hasCheck()%>"
381            ><base:icon 
382              image="check_uncheck.gif" 
383              tooltip="Check/uncheck all" 
384              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
385            /></tbl:header>
386          <tbl:header 
387            clazz="check" 
388            visible="<%=mode.hasRadio()%>"
389            >&nbsp;</tbl:header>
390          <tbl:header 
391            clazz="icons" 
392            visible="<%=mode.hasIcons()%>"
393            >&nbsp;</tbl:header>
394          <tbl:propertyfilter />
395        </tr>
396         
397          <tbl:rows>
398          <%
399          int index = cc.getPage()*cc.getRowsPerPage();
400          int selectedItemId = cc.getId();
401          if (mappings != null)
402          {           
403            while (mappings.hasNext())
404            {
405              PlateMapping item = mappings.next();
406              int itemId = item.getId();
407              String openSharePopup = "shareItem("+itemId+")";
408              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
409              boolean writePermission = item.hasPermission(Permission.WRITE);
410              String tooltip = mode.isSelectionMode() ? 
411                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
412              String name = HTML.encodeTags(item.getName());
413              index++;
414              numListed++;
415              %>
416              <tbl:row>
417                <tbl:header 
418                  clazz="index"
419                  ><%=index%></tbl:header>
420                <tbl:header 
421                  clazz="check" 
422                  visible="<%=mode.hasCheck()%>"
423                  ><input 
424                    type="checkbox" 
425                    name="<%=itemId%>" 
426                    value="<%=itemId%>" 
427                    title="<%=name%>" 
428                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
429                  ></tbl:header>
430                <tbl:header 
431                  clazz="check" 
432                  visible="<%=mode.hasRadio()%>"
433                  ><input 
434                    type="radio" 
435                    name="item_id" 
436                    value="<%=itemId%>" 
437                    title="<%=name%>" 
438                    <%=selectedItemId == itemId ? "checked" : ""%>
439                  ></tbl:header>
440                <tbl:header 
441                  clazz="icons" 
442                  visible="<%=mode.hasIcons()%>"
443                  ><base:icon 
444                    image="deleted.gif" 
445                    tooltip="This item has been scheduled for deletion" 
446                    visible="<%=item.isRemoved()%>"
447                  /><base:icon 
448                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
449                    onclick="<%=sharePermission ? openSharePopup : null%>"
450                    tooltip="This item is shared to other users, groups and/or projects" 
451                    visible="<%=item.isShared()%>"
452                  />&nbsp;</tbl:header>
453                <tbl:cell column="name"><div class="link" 
454                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
455                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
456                <tbl:cell column="sourceGeometry"
457                  ><base:propertyvalue 
458                    item="<%=item%>" 
459                    property="sourceGeometry"
460                    enableEditLink="<%=mode.hasEditLink()%>" 
461                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
462                  /></tbl:cell>
463                <tbl:cell column="sourceCount"><%=item.getSourceCount()%></tbl:cell>
464                <tbl:cell column="destinationGeometry"
465                  ><base:propertyvalue 
466                    item="<%=item%>" 
467                    property="destinationGeometry"
468                    enableEditLink="<%=mode.hasEditLink()%>" 
469                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
470                  /></tbl:cell>
471                <tbl:cell column="destinationCount"><%=item.getDestinationCount()%></tbl:cell>
472                <tbl:cell column="owner"
473                  ><base:propertyvalue 
474                    item="<%=item%>" 
475                    property="owner"
476                    enableEditLink="<%=mode.hasEditLink()%>" 
477                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
478                  /></tbl:cell>
479                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
480                <tbl:cell column="image"><%=item.getImage() == null ? "" : "<img src=\"../../images/platemappings/"+item.getImage()+"\">" %></tbl:cell>
481                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
482              </tbl:row>
483              <%
484              }
485            }
486          %>
487          </tbl:rows>
488      </tbl:data>
489      <%
490      if (numListed == 0)
491      {
492        %>
493        <tbl:panel><%=mappings == null || mappings.getTotalCount() == 0 ? "No plate mappings where found" : "No plate mappings on this page. Please select another page!" %></tbl:panel>
494        <%
495      }
496      else
497      {
498        %>
499        <tbl:navigator
500          page="<%=cc.getPage()%>" 
501          rowsperpage="<%=cc.getRowsPerPage()%>" 
502          totalrows="<%=mappings == null ? 0 : mappings.getTotalCount()%>" 
503          visible="<%=mode.hasNavigator()%>"
504          locked="true"
505        />
506        <%
507      }
508      %>
509    </tbl:table>
510    <base:buttongroup align="center" clazz="fixedatbottom">
511      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
512      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
513      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
514    </base:buttongroup>
515    <br><br><br>
516  </base:body>
517  </base:page>
518  <%
519}
520finally
521{
522  if (mappings != null) mappings.close();
523  if (dc != null) dc.close();
524}
525%>
Note: See TracBrowser for help on using the repository browser.