source: trunk/www/lims/arraybatches/list_batches.jsp @ 3551

Last change on this file since 3551 was 3551, checked in by Martin Svensson, 16 years ago

References #375. Added column with projects, groups, users that an item is shared to. First list page is done, the rest of the
list pages will also soon be checked in.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.4 KB
Line 
1<%-- $Id: list_batches.jsp 3551 2007-07-05 14:20:49Z 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.ArrayBatch"
32  import="net.sf.basedb.core.ArraySlide"
33  import="net.sf.basedb.core.AnnotationType"
34  import="net.sf.basedb.core.AnnotationSet"
35  import="net.sf.basedb.core.Group"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.Include"
38  import="net.sf.basedb.core.Type"
39  import="net.sf.basedb.core.ItemResultIterator"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.ItemContext"
42  import="net.sf.basedb.core.MultiPermissions"
43  import="net.sf.basedb.core.Permission"
44  import="net.sf.basedb.core.PluginDefinition"
45  import="net.sf.basedb.core.Project"
46  import="net.sf.basedb.core.query.Hql"
47  import="net.sf.basedb.core.query.Restrictions"
48  import="net.sf.basedb.core.query.Expressions"
49  import="net.sf.basedb.core.query.Orders"
50  import="net.sf.basedb.core.plugin.GuiContext"
51  import="net.sf.basedb.core.plugin.Plugin"
52  import="net.sf.basedb.core.User"
53  import="net.sf.basedb.util.Enumeration"
54  import="net.sf.basedb.clients.web.Base"
55  import="net.sf.basedb.clients.web.ModeInfo"
56  import="net.sf.basedb.clients.web.PermissionUtil"
57  import="net.sf.basedb.clients.web.util.HTML"
58  import="net.sf.basedb.util.formatter.Formatter"
59  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
60  import="net.sf.basedb.util.Values"
61  import="java.util.ArrayList"
62  import="java.util.Collections"
63  import="java.util.List"
64  import="java.util.Map"
65%>
66<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
67<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
68<%!
69  private static final Item itemType = Item.ARRAYBATCH;
70  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
71%>
72<%
73final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
74final String ID = sc.getId();
75final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
76final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
77
78final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
79final String callback = request.getParameter("callback");
80final String title = mode.generateTitle("array baatch", "array batches");
81final DbControl dc = sc.newDbControl();
82ItemResultIterator<ArrayBatch> batches = null;
83ItemResultList<AnnotationType> annotationTypes = null;
84try
85{
86  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
87
88  // Query for slide relatated to the current batch
89  final ItemQuery<ArraySlide> slideQuery = ArraySlide.getQuery();
90  slideQuery.include(cc.getInclude());
91  slideQuery.restrict(Restrictions.eq(Hql.property("arrayBatch"), Expressions.parameter("arrayBatch")));
92  slideQuery.order(Orders.asc(Hql.property("name"))); 
93  final boolean createSlidePermission = sc.hasPermission(Permission.CREATE, Item.ARRAYSLIDE);   
94
95  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
96  annotationTypes = annotationTypeQuery.list(dc);
97  try
98  {
99    final ItemQuery<ArrayBatch> query = Base.getConfiguredQuery(cc, true, ArrayBatch.getQuery(), mode);
100    batches = query.iterate(dc);
101  }
102  catch (Throwable t)
103  {
104    cc.setMessage(t.getMessage());
105  }
106  int numListed = 0;
107  %>
108  <base:page title="<%=title==null ? "Array batches" : title%>" type="<%=mode.getPageType()%>">
109  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
110    <script language="JavaScript">
111    var submitPage = 'index.jsp';
112    var formId = 'batches';
113    function newItem()
114    {
115      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
116    }
117    function editItem(itemId)
118    {
119      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
120    }
121    function viewItem(itemId)
122    {
123      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
124    }
125    function itemOnClick(evt, itemId)
126    {
127      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
128    }
129    function deleteItems()
130    {
131      var frm = document.forms[formId];
132      if (Forms.numChecked(frm) == 0)
133      {
134        alert('Please select at least one item in the list');
135        return;
136      }
137      frm.action = submitPage;
138      frm.cmd.value = 'DeleteItems';
139      frm.submit();
140    }
141    function restoreItems()
142    {
143      var frm = document.forms[formId];
144      if (Forms.numChecked(frm) == 0)
145      {
146        alert('Please select at least one item in the list');
147        return;
148      }
149      frm.action = submitPage;
150      frm.cmd.value = 'RestoreItems';
151      frm.submit();
152    }
153    function takeOwnership()
154    {
155      var frm = document.forms[formId];
156      if (Forms.numChecked(frm) == 0)
157      {
158        alert('Please select at least one item in the list');
159        return;
160      }
161      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
162      {
163        frm.action = submitPage;
164        frm.cmd.value = 'TakeOwnershipOfItems';
165        frm.submit();
166      }
167    }
168    function shareItem(itemId)
169    {
170      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareBatches', 500, 400);
171    }
172    function shareItems()
173    {
174      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
175    }
176    function configureColumns()
177    {
178      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
179    }
180    function runPlugin(cmd)
181    {
182      Table.submitToPopup(formId, cmd, 740, 540);
183    }
184    function returnSelected()
185    {
186      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
187      window.close();
188    }
189    function presetOnChange()
190    {
191      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
192    }
193    function newSlide(batchId)
194    {
195      Main.viewOrEditItem('<%=ID%>', 'ARRAYSLIDE', 0, true, '&arraybatch_id='+batchId);
196    }
197    function multipleNewSlides(batchId)
198    {     
199      Main.openPopup('../arrayslides/index.jsp?ID=<%=ID%>&cmd=NewItems&arraybatch_id='+batchId, 'NewArraySlides', 800, 500);
200    }
201    </script>
202  </base:head>
203 
204  <base:body>
205    <%
206    if (cc.getMessage() != null)
207    {
208      %>
209      <div class="error"><%=cc.getMessage()%></div>
210      <%
211      cc.setMessage(null);
212    }
213    %>
214    <tbl:table 
215      id="batches" 
216      clazz="itemlist" 
217      columns="<%=cc.getSetting("columns")%>"
218      sortby="<%=cc.getSortProperty()%>" 
219      direction="<%=cc.getSortDirection()%>"
220      title="<%=title%>"
221      action="index.jsp"
222      sc="<%=sc%>"
223      item="<%=itemType%>"
224      >
225      <tbl:hidden 
226        name="mode" 
227        value="<%=mode.getName()%>" 
228      />
229      <tbl:hidden 
230        name="callback" 
231        value="<%=callback%>" 
232        skip="<%=callback == null%>" 
233      />
234      <tbl:columndef 
235        id="name"
236        property="name"
237        datatype="string"
238        title="Name"
239        sortable="true" 
240        filterable="true"
241        exportable="true"
242        show="always" 
243      />
244      <tbl:columndef 
245        id="arrayDesign"
246        property="arrayDesign.name"
247        datatype="string"
248        title="Array design"
249        sortable="true" 
250        filterable="true"
251        exportable="true"
252      />
253      <tbl:columndef 
254        id="printRobot"
255        property="printRobot.name"
256        datatype="string"
257        title="Print robot"
258        sortable="true" 
259        filterable="true"
260        exportable="true"
261      />
262      <tbl:columndef 
263        id="protocol"
264        property="protocol.name"
265        datatype="string"
266        title="Protocol"
267        sortable="true" 
268        filterable="true"
269        exportable="true"
270      />
271      <tbl:columndef
272        id="slides"
273        title="Slides"
274      />
275      <tbl:columndef 
276        id="owner"
277        property="owner.name"
278        datatype="string"
279        title="Owner"
280        sortable="true" 
281        filterable="true"
282        exportable="true"
283      />
284      <tbl:columndef 
285        id="description"
286        property="description"
287        datatype="string"
288        title="Description" 
289        sortable="true" 
290        filterable="true" 
291        exportable="true"
292      />     
293      <%
294      for (AnnotationType at : annotationTypes)
295      {
296        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
297        Enumeration<String, String> annotationEnum = null;
298        if (at.isEnumeration())
299        {
300          annotationEnum = new Enumeration<String, String>();
301          List<?> values = at.getValues();
302          for (Object value : values)
303          {
304            String encoded = formatter.format(value);
305            annotationEnum.add(encoded, encoded);
306          }
307        }
308        %>
309        <tbl:columndef 
310          id="<%="at"+at.getId()%>"
311          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
312          property="<%="#"+at.getId()%>"
313          annotation="true"
314          datatype="<%=at.getValueType().getStringValue()%>"
315          enumeration="<%=annotationEnum%>"
316          sortable="false" 
317          filterable="true" 
318          exportable="true"
319          formatter="<%=formatter%>"
320        />
321        <%
322      }
323      %>
324      <tbl:columndef
325        id="permission"
326        title="Permission"
327      />
328      <tbl:columndef 
329        id="sharedTo"
330        title="Shared to"       
331      />
332      <tbl:toolbar
333        visible="<%=mode.hasToolbar()%>"
334        >
335        <tbl:button 
336          disabled="<%=createPermission ? false : true%>" 
337          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
338          onclick="newItem()" 
339          title="New&hellip;" 
340          tooltip="<%=createPermission ? "Create new array batche" : "You do not have permission to create array batches"%>" 
341        />
342        <tbl:button 
343          image="delete.gif"
344          onclick="deleteItems()" 
345          title="Delete" 
346          tooltip="Delete the selected items" 
347        />
348        <tbl:button 
349          image="restore.gif"
350          onclick="restoreItems()" 
351          title="Restore" 
352          tooltip="Restore the selected (deleted) items"
353        />
354        <tbl:button 
355          image="share.gif"
356          onclick="shareItems()" 
357          title="Share&hellip;" 
358          tooltip="Share the selected items"
359        />
360        <tbl:button 
361          image="take_ownership.png"
362          onclick="takeOwnership()" 
363          title="Take ownership&hellip;"
364          tooltip="Take ownership of the selected items"
365        />
366        <tbl:button 
367          image="columns.gif" 
368          onclick="configureColumns()" 
369          title="Columns&hellip;" 
370          tooltip="Show, hide and re-order columns" 
371        />
372        <tbl:button 
373          image="import.gif" 
374          onclick="runPlugin('ImportItems')" 
375          title="Import&hellip;" 
376          tooltip="Import data" 
377          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
378        />
379        <tbl:button 
380          image="export.gif" 
381          onclick="runPlugin('ExportItems')" 
382          title="Export&hellip;" 
383          tooltip="Export data" 
384          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
385        />
386        <tbl:button 
387          image="runplugin.gif" 
388          onclick="runPlugin('RunListPlugin')" 
389          title="Run plugin&hellip;" 
390          tooltip="Run a plugin" 
391          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
392        />
393      </tbl:toolbar>
394      <tbl:navigator
395        page="<%=cc.getPage()%>" 
396        rowsperpage="<%=cc.getRowsPerPage()%>" 
397        totalrows="<%=batches == null ? 0 : batches.getTotalCount()%>" 
398        visible="<%=mode.hasNavigator()%>"
399      />
400      <tbl:data>
401        <tbl:columns>
402        <tbl:presetselector 
403          clazz="columnheader"
404          colspan="3"
405          onchange="presetOnChange()"
406        />
407        </tbl:columns>
408
409        <tr>
410          <tbl:header 
411            clazz="index"
412            >&nbsp;</tbl:header>
413          <tbl:header 
414            clazz="check" 
415            visible="<%=mode.hasCheck()%>"
416            ><base:icon 
417              image="check_uncheck.gif" 
418              tooltip="Check/uncheck all" 
419              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
420            /></tbl:header>
421          <tbl:header 
422            clazz="check" 
423            visible="<%=mode.hasRadio()%>"
424            >&nbsp;</tbl:header>
425          <tbl:header 
426            clazz="icons" 
427            visible="<%=mode.hasIcons()%>"
428            >&nbsp;</tbl:header>
429          <tbl:propertyfilter />
430        </tr>
431         
432          <tbl:rows>
433          <%
434          int index = cc.getPage()*cc.getRowsPerPage();
435          int selectedItemId = cc.getId();
436          if (batches != null)
437          { 
438            while (batches.hasNext())
439            {
440              ArrayBatch item = batches.next();
441              int itemId = item.getId();
442              String openSharePopup = "shareItem("+itemId+")";
443              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
444              boolean usePermission = item.hasPermission(Permission.USE);
445              boolean writePermission = item.hasPermission(Permission.WRITE);
446              String tooltip = mode.isSelectionMode() ? 
447                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
448              String name = HTML.encodeTags(item.getName());
449              index++;
450              numListed++;
451              %>
452              <tbl:row>
453                <tbl:header 
454                  clazz="index"
455                  ><%=index%></tbl:header>
456                <tbl:header 
457                  clazz="check" 
458                  visible="<%=mode.hasCheck()%>"
459                  ><input 
460                    type="checkbox" 
461                    name="<%=itemId%>" 
462                    value="<%=itemId%>" 
463                    title="<%=name%>" 
464                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
465                  ></tbl:header>
466                <tbl:header 
467                  clazz="check" 
468                  visible="<%=mode.hasRadio()%>"
469                  ><input 
470                    type="radio" 
471                    name="item_id" 
472                    value="<%=itemId%>" 
473                    title="<%=name%>" 
474                    <%=selectedItemId == itemId ? "checked" : ""%>
475                  ></tbl:header>
476                <tbl:header 
477                  clazz="icons" 
478                  visible="<%=mode.hasIcons()%>"
479                  ><base:icon 
480                    image="deleted.gif" 
481                    tooltip="This item has been scheduled for deletion" 
482                    visible="<%=item.isRemoved()%>"
483                  /><base:icon 
484                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
485                    onclick="<%=sharePermission ? openSharePopup : null%>"
486                    tooltip="This item is shared to other users, groups and/or projects" 
487                    visible="<%=item.isShared()%>"
488                  />&nbsp;</tbl:header>
489                <tbl:cell column="name"><div class="link" 
490                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
491                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
492                <tbl:cell column="arrayDesign"
493                  ><base:propertyvalue 
494                    item="<%=item%>" 
495                    property="arrayDesign"
496                    enableEditLink="<%=mode.hasEditLink()%>" 
497                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
498                  /></tbl:cell>
499                <tbl:cell column="printRobot"
500                  ><base:propertyvalue 
501                    item="<%=item%>" 
502                    property="printRobot"
503                    enableEditLink="<%=mode.hasEditLink()%>" 
504                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
505                  /></tbl:cell>
506                <tbl:cell column="protocol"
507                  ><base:propertyvalue 
508                    item="<%=item%>" 
509                    property="protocol"
510                    enableEditLink="<%=mode.hasEditLink()%>" 
511                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
512                  /></tbl:cell>
513                <tbl:cell column="slides">
514                  <%
515                  slideQuery.setParameter("arrayBatch", itemId, Type.INT);
516                  try
517                  {
518                    %>
519                    <%=slideQuery.count(dc)%>
520                    <%
521                  }
522                  catch (Throwable t)
523                  {
524                    %>
525                    <div class="error"><%=t.getMessage()%></div>
526                    <%
527                  }
528                  %>
529                  <base:icon
530                    image="add.png" 
531                    onclick="<%="newSlide("+itemId+")"%>" 
532                    tooltip="Create new slide" 
533                    visible="<%=mode.hasEditLink() && createSlidePermission && usePermission %>"
534                  />
535                  <base:icon
536                    image="new_wizard.gif" 
537                    onclick="<%="multipleNewSlides("+itemId+")"%>" 
538                    tooltip="Create multiple new slides using a wizard" 
539                    visible="<%=mode.hasEditLink() && createSlidePermission && usePermission %>"
540                  />
541                </tbl:cell>
542                <tbl:cell column="owner"
543                  ><base:propertyvalue 
544                    item="<%=item%>" 
545                    property="owner"
546                    enableEditLink="<%=mode.hasEditLink()%>" 
547                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
548                  /></tbl:cell>
549                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>               
550                <%
551                AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
552                if (as != null)
553                {
554                  for (AnnotationType at : annotationTypes)
555                  {
556                    if (as.hasAnnotation(at))
557                    {
558                      %>
559                      <tbl:cell column="<%="at"+at.getId()%>"
560                        ><tbl:cellvalue 
561                        list="<%=as.getAnnotation(at).getValues()%>" 
562                      /></tbl:cell>
563                      <%
564                    }
565                  }
566                }
567                %>
568                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
569                <tbl:cell column="sharedTo">
570                <%
571                  MultiPermissions mp = new MultiPermissions(Collections.singleton(item));
572                  ItemResultIterator<User> users = mp.getUsers().iterate(dc);
573                  ItemResultIterator<Group> groups = mp.getGroups().iterate(dc);
574                  ItemResultIterator<Project> projects = mp.getProjects().iterate(dc);                 
575                  StringBuilder sb = new StringBuilder();
576                  if (projects.hasNext())
577                  {
578                    while (projects.hasNext())
579                    {
580                      sb.append(projects.next().getName() + "[PROJECT]");
581                      sb.append(projects.hasNext() ? ", " : "");                     
582                    }                 
583                  }
584                  if (groups.hasNext())
585                  {
586                    sb.append(sb.length()>0 ? ", " : "");
587                    while (groups.hasNext())
588                    {
589                      sb.append(groups.next().getName() + "[GROUP]");
590                      sb.append(groups.hasNext() ? ", " : "");
591                    }
592                  }
593                  if (users.hasNext())
594                  {
595                    sb.append(sb.length()>0 ? ", " : "");
596                    while (users.hasNext())
597                    {
598                      sb.append(users.next().getLogin() + "[USER]");
599                      sb.append(users.hasNext() ? ", " : "");
600                    }
601                  }
602                  sb.append(sb.length()== 0 ? "<i>- n/a -</i>" : "");
603                  %>                 
604                  <tbl:cellvalue value="<%=sb.toString()%>" />               
605                </tbl:cell>
606              </tbl:row>
607              <%
608              }
609            }
610          %>
611          </tbl:rows>
612      </tbl:data>
613      <%
614      if (numListed == 0)
615      {
616        %>
617        <tbl:panel><%=batches == null || batches.getTotalCount() == 0 ? "No array batches were found" : "No array batches on this page. Please select another page!" %></tbl:panel>
618        <%
619      }
620      else
621      {
622        %>
623        <tbl:navigator
624          page="<%=cc.getPage()%>" 
625          rowsperpage="<%=cc.getRowsPerPage()%>" 
626          totalrows="<%=batches == null ? 0 : batches.getTotalCount()%>" 
627          visible="<%=mode.hasNavigator()%>"
628          locked="true"
629        />
630        <%
631      }
632      %>
633    </tbl:table>
634    <base:buttongroup align="center" clazz="fixedatbottom">
635      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
636      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
637      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
638    </base:buttongroup>
639    <br><br><br>
640  </base:body>
641  </base:page>
642  <%
643}
644finally
645{
646  if (batches != null) batches.close();
647  if (dc != null) dc.close();
648}
649%>
Note: See TracBrowser for help on using the repository browser.