source: trunk/www/biomaterials/biosources/list_biosources.jsp @ 3190

Last change on this file since 3190 was 3190, checked in by Johan Enell, 16 years ago

Merged log:branches/2.2.2#3116:3186 to trunk.

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