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