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