source: trunk/www/lims/arraydesigns/list_designs.jsp @ 3476

Last change on this file since 3476 was 3476, checked in by Nicklas Nordborg, 16 years ago

Fixes #372

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