source: trunk/www/views/experiments/list_experiments.jsp @ 3552

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

References #375. Only wants to do a commit before the weekend.

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