source: trunk/www/views/scans/images/list_images.jsp @ 5064

Last change on this file since 5064 was 5064, checked in by Nicklas Nordborg, 14 years ago

References #108: Logging the change history of an item

  • Added "Change history" tab to hyb, scan and raw bioassay pages
  • Added special logger for scan images
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.4 KB
Line 
1<%-- $Id: list_images.jsp 5064 2009-08-19 12:09:14Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.Scan"
32  import="net.sf.basedb.core.Image"
33  import="net.sf.basedb.core.ItemQuery"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.Permission"
36  import="net.sf.basedb.core.PluginDefinition"
37  import="net.sf.basedb.core.PermissionDeniedException"
38  import="net.sf.basedb.core.query.Restrictions"
39  import="net.sf.basedb.core.query.Expressions"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.core.plugin.GuiContext"
43  import="net.sf.basedb.core.plugin.Plugin"
44  import="net.sf.basedb.util.Enumeration"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.ModeInfo"
47  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
50  import="net.sf.basedb.clients.web.extensions.JspContext"
51  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
52  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
53  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
54  import="net.sf.basedb.util.Values"
55  import="java.util.List"
56  import="java.util.Map"
57%>
58<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
59<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
60<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
61<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
62<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
63<%!
64  private static final Item itemType = Item.IMAGE;
65  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
66%>
67<%
68final int scanId = Values.getInt(request.getParameter("scan_id"));
69final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
70final String ID = sc.getId();
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("image", "images");
76final DbControl dc = sc.newDbControl();
77ItemResultIterator<Image> images = null;
78try
79{
80  final Scan scan = Scan.getById(dc, scanId);
81  final boolean createPermission = scan.hasPermission(Permission.WRITE);
82  final boolean writePermission = createPermission;
83  final boolean deletePermission = createPermission;
84
85  final ItemQuery<Image> query = scan.getImages();
86  cc.configureQuery(query, true);
87
88  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
89  try
90  {
91    images = query.iterate(dc);
92  }
93  catch (Throwable t)
94  {
95    cc.setMessage(t.getMessage());
96  }
97  int numListed = 0;
98  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, scan);
99  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
100  %>
101  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
102  <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css">
103    <ext:scripts context="<%=jspContext%>" />
104    <ext:stylesheets context="<%=jspContext%>" />
105    <script language="JavaScript">
106    var submitPage = 'index.jsp';
107    var formId = 'images';
108    function newItem()
109    {
110      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true, '&scan_id=<%=scanId%>');
111//      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=NewItem&scan_id=<%=scanId%>', 'NewImage', 500, 340);
112    }
113    function editItem(itemId)
114    {
115      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
116//      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=EditItem&scan_id=<%=scanId%>&item_id='+itemId, 'EditImage', 500, 340);
117    }
118    function viewItem(itemId)
119    {
120      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
121//      location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&scan_id=<%=scanId%>&item_id='+itemId;
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    function restoreItems()
140    {
141      var frm = document.forms[formId];
142      if (Forms.numChecked(frm) == 0)
143      {
144        alert('Please select at least one item in the list');
145        return;
146      }
147      frm.action = submitPage;
148      frm.cmd.value = 'RestoreItems';
149      frm.submit();
150    }
151    function deleteItemPermanently(itemId)
152    {
153      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', itemId);
154    }
155    function configureColumns()
156    {
157      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
158    }
159    function runPlugin(cmd)
160    {
161      Table.submitToPopup(formId, cmd, 540, 460);
162    }
163    function returnSelected()
164    {
165      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
166      window.close();
167    }
168    function presetOnChange()
169    {
170      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
171    }
172    function switchTab(tabControlId, tabId)
173    {
174      if (tabId == 'properties' || tabId == 'annotations' || tabId == 'overview' || tabId == 'history')
175      {
176        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=scanId%>&tab='+tabId;
177      }
178      else
179      {
180        TabControl.setActiveTab(tabControlId, tabId);
181      }
182    }
183    </script>
184  </base:head>
185 
186  <base:body>
187    <p>
188    <p:path>
189      <p:pathelement title="Scans" href="<%="../index.jsp?ID="+ID%>" />
190      <p:pathelement title="<%=HTML.encodeTags(scan.getName())%>" />
191    </p:path>
192
193    <t:tabcontrol id="main" active="images" switch="switchTab">
194    <t:tab id="properties" title="Properties" />
195    <t:tab id="annotations" title="Annotations &amp; parameters" 
196      tooltip="View annotation values and protocol parameters" />
197   
198    <t:tab id="images" title="Images">
199   
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="images" 
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="scan_id" 
226        value="<%=String.valueOf(scanId)%>" 
227      />
228      <tbl:hidden 
229        name="callback" 
230        value="<%=callback%>" 
231        skip="<%=callback == null%>" 
232      />
233      <tbl:columndef 
234        id="name"
235        property="name"
236        datatype="string"
237        title="Name"
238        sortable="true" 
239        filterable="true"
240        exportable="true"
241        show="always" 
242      />
243      <tbl:columndef 
244        id="id"
245        clazz="uniquecol"
246        property="id"
247        datatype="int"
248        title="ID"
249        sortable="true"
250        filterable="true"
251        exportable="true"
252      />
253      <tbl:columndef 
254        id="file"
255        property="file.name"
256        datatype="string"
257        title="File"
258        sortable="true" 
259        filterable="true"
260        exportable="true"
261      />
262      <tbl:columndef 
263        id="preview"
264        property="preview"
265        datatype="boolean"
266        title="Is preview"
267        sortable="true" 
268        filterable="true"
269        exportable="true"
270      />
271      <%
272      Enumeration<String, String> formats = new Enumeration<String, String>();
273      for (Image.Format f : Image.Format.values())
274      {
275        formats.add(Integer.toString(f.getValue()), f.toString());
276      }
277      %>
278      <tbl:columndef 
279        id="format"
280        property="format"
281        datatype="int"
282        enumeration="<%=formats%>"
283        title="Format"
284        sortable="true" 
285        filterable="true"
286        exportable="true"
287      />
288      <tbl:columndef 
289        id="description"
290        property="description"
291        datatype="string"
292        title="Description" 
293        sortable="true" 
294        filterable="true" 
295        exportable="true"
296      />
297      <tbl:toolbar
298        visible="<%=mode.hasToolbar()%>"
299        >
300        <tbl:button 
301          disabled="<%=createPermission ? false : true%>" 
302          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
303          onclick="newItem()" 
304          title="New&hellip;" 
305          tooltip="<%=createPermission ? "Create new image" : "You do not have permission to create images"%>" 
306        />
307        <tbl:button 
308          disabled="<%=deletePermission ? false : true%>" 
309          image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
310          title="Delete"
311          onclick="deleteItems()" 
312          tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete images"%>" 
313        />
314        <tbl:button 
315          disabled="<%=writePermission ? false : true%>"
316          image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>"
317          onclick="restoreItems()" 
318          title="Restore" 
319          tooltip="<%=writePermission ? "Restore the selected (deleted) items" : "You do not have permission to restore images"%>"
320        />
321        <tbl:button 
322          image="columns.gif" 
323          onclick="configureColumns()" 
324          title="Columns&hellip;" 
325          tooltip="Show, hide and re-order columns" 
326        />
327        <tbl:button 
328          image="import.gif" 
329          onclick="runPlugin('ImportItems')" 
330          title="Import&hellip;" 
331          tooltip="Import data" 
332          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
333        />
334        <tbl:button 
335          image="export.gif" 
336          onclick="runPlugin('ExportItems')" 
337          title="Export&hellip;" 
338          tooltip="Export data" 
339          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
340        />
341        <tbl:button 
342          image="runplugin.gif" 
343          onclick="runPlugin('RunListPlugin')" 
344          title="Run plugin&hellip;" 
345          tooltip="Run a plugin" 
346          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
347        />
348        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
349          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
350      </tbl:toolbar>
351      <tbl:navigator
352        page="<%=cc.getPage()%>" 
353        rowsperpage="<%=cc.getRowsPerPage()%>" 
354        totalrows="<%=images == null ? 0 : images.getTotalCount()%>" 
355        visible="<%=mode.hasNavigator()%>"
356      />
357      <tbl:data>
358        <tbl:columns>
359        <tbl:presetselector 
360          clazz="columnheader"
361          colspan="3"
362          onchange="presetOnChange()"
363        />
364        </tbl:columns>
365         
366        <tr>
367          <tbl:header 
368            clazz="index"
369            >&nbsp;</tbl:header>
370          <tbl:header 
371            clazz="check" 
372            visible="<%=mode.hasCheck()%>"
373            ><base:icon 
374              image="check_uncheck.gif" 
375              tooltip="Check/uncheck all" 
376              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
377            /></tbl:header>
378          <tbl:header 
379            clazz="check" 
380            visible="<%=mode.hasRadio()%>"
381            />
382          <tbl:header 
383            clazz="icons" 
384            visible="<%=mode.hasIcons()%>"
385            >&nbsp;</tbl:header>
386          <tbl:propertyfilter />
387        </tr>
388   
389          <tbl:rows>
390          <%
391          int index = cc.getPage()*cc.getRowsPerPage();
392          int selectedItemId = cc.getId();
393          if (images != null)
394          {           
395            while (images.hasNext())
396            {
397              Image item = images.next();
398              int itemId = item.getId();
399              String tooltip = mode.isSelectionMode() ?
400                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
401              String deletePermanently = "deleteItemPermanently("+itemId+")";
402              String name = HTML.encodeTags(item.getName());
403              index++;
404              numListed++;
405              %>
406              <tbl:row>
407                <tbl:header 
408                  clazz="index"
409                  ><%=index%></tbl:header>
410                <tbl:header 
411                  clazz="check" 
412                  visible="<%=mode.hasCheck()%>"
413                  ><input 
414                      type="checkbox" 
415                      name="<%=itemId%>" 
416                      value="<%=itemId%>" 
417                      title="<%=name%>" 
418                      <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
419                    ></tbl:header>
420                <tbl:header 
421                  clazz="check" 
422                  visible="<%=mode.hasRadio()%>"
423                  ><input 
424                      type="radio" 
425                      name="item_id" 
426                      value="<%=itemId%>" 
427                      title="<%=name%>" 
428                      <%=selectedItemId == itemId ? "checked" : ""%>
429                    ></tbl:header>
430                <tbl:header 
431                  clazz="icons" 
432                  visible="<%=mode.hasIcons()%>"
433                  ><base:icon 
434                    image="<%=deletePermission ? "deleted.gif" : "deleted_disabled.gif"%>"
435                    onclick="<%=deletePermission ? deletePermanently : null%>"
436                    tooltip="This item has been scheduled for deletion" 
437                    visible="<%=item.isRemoved()%>"
438                  />&nbsp;</tbl:header>
439                <tbl:cell column="name"><div class="link" 
440                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
441                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
442                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
443                <tbl:cell column="file"
444                  ><base:propertyvalue 
445                    item="<%=item%>" 
446                    property="file"
447                    enableEditLink="<%=mode.hasEditLink()%>" 
448                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
449                  /></tbl:cell>
450                <tbl:cell column="preview"><%=item.isPreview()%></tbl:cell>
451                <tbl:cell column="format"><%=item.getFormat()%></tbl:cell>
452                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
453              </tbl:row>
454              <%
455            }
456          }
457          %>
458          </tbl:rows>
459        </tbl:data>
460      <%
461      if (numListed == 0)
462      {
463        %>
464        <tbl:panel><%=images == null || images.getTotalCount() == 0 ? "No images were found" : "No images on this page. Please select another page!" %></tbl:panel>
465        <%
466      }
467      else
468      {
469        %>
470        <tbl:navigator
471          page="<%=cc.getPage()%>" 
472          rowsperpage="<%=cc.getRowsPerPage()%>" 
473          totalrows="<%=images == null ? 0 : images.getTotalCount()%>" 
474          visible="<%=mode.hasNavigator()%>"
475          locked="true"
476        />
477        <%
478      }
479      %>
480    </tbl:table>
481    <base:buttongroup align="center">
482      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
483      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
484      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
485    </base:buttongroup>
486 
487    </t:tab>
488    <t:tab id="overview" title="Overview" 
489      tooltip="Display a tree overview of related items" />
490    <t:tab id="history" title="Change history" 
491        tooltip="Displays a log of all modifications made to this item"
492        visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>" />
493    </t:tabcontrol>
494
495 
496  </base:body>
497  </base:page>
498  <%
499}
500finally
501{
502  if (images != null) images.close();
503  if (dc != null) dc.close();
504}
505%>
Note: See TracBrowser for help on using the repository browser.