source: trunk/www/views/reporters/list_reporters.jsp @ 5425

Last change on this file since 5425 was 5425, checked in by Nicklas Nordborg, 13 years ago

References #1514: Fix character encoding of jsp files

I hope this fixes most of the issues, including the reporter list filtering in many places. Let's keep an eye open for more issues until it is time to release 2.16

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 16.3 KB
Line 
1<%-- $Id: list_reporters.jsp 5425 2010-09-23 13:30:07Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5  Copyright (C) 2007 Johan Enell, Nicklas Nordborg
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
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.SystemItems"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Reporter"
34  import="net.sf.basedb.core.ReporterType"
35  import="net.sf.basedb.core.PluginDefinition"
36  import="net.sf.basedb.core.data.ReporterData"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.DataQuery"
40  import="net.sf.basedb.core.DataResultIterator"
41  import="net.sf.basedb.core.ExtendedProperty"
42  import="net.sf.basedb.core.ExtendedProperties"
43  import="net.sf.basedb.core.Permission"
44  import="net.sf.basedb.core.query.Orders"
45  import="net.sf.basedb.core.query.Hql"
46  import="net.sf.basedb.core.plugin.GuiContext"
47  import="net.sf.basedb.core.plugin.Plugin"
48  import="net.sf.basedb.util.Enumeration"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.ModeInfo"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.Values"
53  import="net.sf.basedb.util.formatter.Formatter"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
56  import="net.sf.basedb.clients.web.extensions.JspContext"
57  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
58  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
59  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
60  import="java.util.Date"
61  import="java.util.Map"
62  import="java.util.List"
63%>
64<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
65<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
66<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
67<%!
68  private static final Item itemType = Item.REPORTER;
69  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
70%>
71<%
72final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
73final String ID = sc.getId();
74final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
75final boolean writePermission = sc.hasPermission(Permission.WRITE, itemType);
76final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType);
77
78final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
79
80final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
81final String callback = request.getParameter("callback");
82final String title = mode.generateTitle("reporter", "reporters");
83final DbControl dc = sc.newDbControl();
84DataResultIterator<ReporterData> reporters = null;
85ItemResultList<ReporterType> reporterTypes = null;
86try
87{
88  final DataQuery<ReporterData> query = Reporter.getQuery();
89  cc.configureQuery(dc, query, true);
90
91  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
92  final ItemQuery<ReporterType> typeQuery = ReporterType.getQuery();
93  typeQuery.order(Orders.asc(Hql.property("name")));
94  typeQuery.setCacheResult(true);
95  List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData");
96  try
97  {
98    reporters = query.iterate(dc);
99  }
100  catch (Throwable t)
101  {
102    cc.setMessage(t.getMessage());
103    t.printStackTrace();
104  }
105  int numListed = 0;
106  Formatter<Date> timeFormatter = FormatterFactory.getDateTimeFormatter(sc);
107  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
108  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
109  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
110  %>
111  <base:page title="<%=title==null ? "Reporters" : title%>" type="<%=mode.getPageType()%>">
112  <base:head scripts="table.js" styles="table.css">
113    <ext:scripts context="<%=jspContext%>" />
114    <ext:stylesheets context="<%=jspContext%>" />
115    <script language="JavaScript">
116    var submitPage = 'index.jsp';
117    var formId = 'reporters';
118    function newItem()
119    {
120      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
121    }
122    function editItem(itemId)
123    {
124      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
125    }
126    function viewItem(itemId)
127    {
128      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
129    }
130    function itemOnClick(evt, itemId)
131    {
132      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
133    }
134    function deleteItems()
135    {
136      var frm = document.forms[formId];
137      var numChecked = Forms.numChecked(frm);
138      if (numChecked == 0)
139      {
140        alert('Please select at least one item in the list');
141        return;
142      }
143      else
144      {
145        var rep = numChecked == 1 ? 'reporter' : 'reporters';
146        if (!confirm('You are about to delete '+numChecked+' '+rep+'. This can\'t be undone. Continue?'))
147        {
148          return;
149        }
150      }
151      frm.action = submitPage;
152      frm.cmd.value = 'DeleteItems';
153      frm.submit();
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, 740, 540);
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 newReporterList()
173    {
174      Table.submitToPopup(formId, 'CreateReporterList', 540, 400);
175    }
176    </script>
177  </base:head>
178 
179  <base:body>
180    <%
181    if (cc.getMessage() != null)
182    {
183      %>
184      <div class="error"><%=cc.getMessage()%></div>
185      <%
186      cc.setMessage(null);
187    }
188    %>
189    <tbl:table 
190      id="reporters" 
191      clazz="itemlist" 
192      columns="<%=cc.getSetting("columns")%>"
193      sortby="<%=cc.getSortProperty()%>" 
194      direction="<%=cc.getSortDirection()%>"
195      title="<%=title%>"
196      action="index.jsp"
197      sc="<%=sc%>"
198      item="<%=itemType%>"
199      >
200      <tbl:hidden 
201        name="mode" 
202        value="<%=mode.getName()%>" 
203      />
204      <tbl:hidden 
205        name="callback" 
206        value="<%=callback%>" 
207        skip="<%=callback == null%>" 
208      />
209      <tbl:columndef 
210        id="externalId"
211        clazz="uniquecol"
212        property="externalId"
213        datatype="string"
214        title="External ID"
215        sortable="true" 
216        filterable="true"
217        exportable="true"
218      />
219      <tbl:columndef 
220        id="name"
221        property="name"
222        datatype="string"
223        title="Name"
224        sortable="true" 
225        filterable="true"
226        exportable="true"
227        show="always" 
228      />
229      <tbl:columndef 
230        id="id"
231        clazz="uniquecol"
232        property="id"
233        datatype="int"
234        title="ID"
235        sortable="true"
236        filterable="true"
237        exportable="true"
238      />
239      <tbl:columndef 
240        id="symbol"
241        property="symbol"
242        datatype="string"
243        title="Gene symbol"
244        sortable="true" 
245        filterable="true"
246        exportable="true"
247      />
248      <tbl:columndef 
249        id="description"
250        property="description"
251        datatype="string"
252        title="Description" 
253        sortable="true" 
254        filterable="true" 
255        exportable="true"
256      />
257      <tbl:columndef
258        id="reporterList"
259        property="£reporterListScores"
260        datatype="int"
261        title="Reporter list"
262        filterable="true"
263        enumeration="<%=Base.getReporterListsEnum(dc)%>"
264        multiple="false"
265      />
266      <tbl:columndef 
267        id="entryDate"
268        property="entryDate"
269        datatype="date"
270        title="Registered"
271        sortable="true" 
272        filterable="true"
273        exportable="true"
274        formatter="<%=dateFormatter%>"
275      />
276      <tbl:columndef 
277        id="lastUpdate"
278        property="lastUpdate"
279        datatype="timestamp"
280        title="Last update" 
281        sortable="true" 
282        filterable="true" 
283        exportable="true"
284        formatter="<%=timeFormatter%>"
285      />
286      <tbl:columndef 
287        id="lastSource"
288        property="lastSource"
289        datatype="string"
290        title="Last source"
291        sortable="true"
292        filterable="true"
293        exportable="true"
294      />
295      <%
296      Enumeration<String, String> types = new Enumeration<String, String>();
297      reporterTypes = typeQuery.list(dc);
298      types.add("", "- none -");
299      for (ReporterType rt : reporterTypes)
300      {
301        types.add(Integer.toString(rt.getId()), HTML.encodeTags(rt.getName()));
302      }
303      %>
304      <tbl:columndef 
305        id="reporterType"
306        property="reporterType"
307        sortproperty="reporterType.name"
308        exportproperty="reporterType.name"
309        datatype="int"
310        enumeration="<%=types%>"
311        title="Type"
312        sortable="true" 
313        filterable="true"
314        exportable="true"
315      />
316      <%
317      if (reporterProperties != null)
318      {
319        for (ExtendedProperty ep : reporterProperties)
320        {
321          String name = ep.getName();
322          %>
323          <tbl:columndef
324            id="<%=name%>"
325            property="<%=name%>"
326            datatype="<%=ep.getType().getStringValue()%>"
327            title="<%=HTML.encodeTags(ep.getTitle())%>"
328            sortable="true"
329            filterable="true"
330            exportable="true"
331            formatter="<%=FormatterFactory.getExtendedPropertyFormatter(sc, ep)%>"
332          />
333          <%
334        }
335      }
336      %>
337      <tbl:toolbar
338        visible="<%=mode.hasToolbar()%>"
339        >
340        <tbl:button 
341          disabled="<%=createPermission ? false : true%>" 
342          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
343          onclick="newItem()" 
344          title="New&hellip;" 
345          tooltip="<%=createPermission ? "Create a new reporter" : "You do not have permission to create reporter"%>" 
346        />
347        <tbl:button 
348          disabled="<%=deletePermission ? false : true%>" 
349          image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
350          onclick="deleteItems()" 
351          title="Delete&hellip;" 
352          tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete reporters" %>" 
353        />
354        <tbl:button 
355          image="columns.gif" 
356          onclick="configureColumns()" 
357          title="Columns&hellip;" 
358          tooltip="Show, hide and re-order columns" 
359        />
360        <tbl:button
361          image="add.png"
362          onclick="newReporterList()"
363          title="New reporter list&hellip;"
364          tooltip="Create a new reporter list from matching reporters"
365          visible="<%=sc.hasPermission(Permission.CREATE, Item.REPORTERLIST)%>"
366        />
367        <tbl:button 
368          image="import.gif" 
369          onclick="runPlugin('ImportItems')" 
370          title="Import&hellip;" 
371          tooltip="Import data" 
372          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
373        />
374        <tbl:button 
375          image="export.gif" 
376          onclick="runPlugin('ExportItems')" 
377          title="Export&hellip;" 
378          tooltip="Export data" 
379          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
380        />
381        <tbl:button 
382          image="runplugin.gif" 
383          onclick="runPlugin('RunListPlugin')" 
384          title="Run plugin&hellip;" 
385          tooltip="Run a plugin" 
386          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
387        />
388        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
389          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
390      </tbl:toolbar>
391      <tbl:navigator
392        page="<%=cc.getPage()%>" 
393        rowsperpage="<%=cc.getRowsPerPage()%>" 
394        totalrows="<%=reporters == null ? 0 : reporters.getTotalCount()%>" 
395        visible="<%=mode.hasNavigator()%>"
396      />
397      <tbl:data>
398        <tbl:columns>
399        <tbl:presetselector 
400          clazz="columnheader"
401          colspan="3"
402          onchange="presetOnChange()"
403        />
404        </tbl:columns>
405        <tr>
406          <tbl:header 
407            clazz="index"
408            >&nbsp;</tbl:header>
409          <tbl:header 
410            clazz="check" 
411            visible="<%=mode.hasCheck()%>"
412            ><base:icon 
413              image="check_uncheck.gif" 
414              tooltip="Check/uncheck all" 
415              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
416            /></tbl:header>
417          <tbl:header 
418            clazz="check" 
419            visible="<%=mode.hasRadio()%>"
420            >&nbsp;</tbl:header>
421          <tbl:header 
422            clazz="icons" 
423            visible="<%=mode.hasIcons()%>"
424            >&nbsp;</tbl:header>
425          <tbl:propertyfilter />
426        </tr>
427          <tbl:rows>
428          <%
429          int index = cc.getPage()*cc.getRowsPerPage();
430          int selectedItemId = cc.getId();
431          if (reporters != null)
432          {
433            while (reporters.hasNext())
434            {
435              ReporterData item = reporters.next();
436              int itemId = item.getId();
437              String name = HTML.encodeTags(item.getName());
438              String tooltip = mode.isSelectionMode() ?
439                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
440              index++;
441              numListed++;
442              %>
443              <tbl:row>
444                <tbl:header 
445                  clazz="index"
446                  ><%=index%></tbl:header>
447                <tbl:header 
448                  clazz="check" 
449                  visible="<%=mode.hasCheck()%>"
450                  ><input 
451                    type="checkbox" 
452                    name="<%=itemId%>" 
453                    value="<%=itemId%>" 
454                    title="<%=name%>" 
455                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
456                  ></tbl:header>
457                <tbl:header 
458                  clazz="check" 
459                  visible="<%=mode.hasRadio()%>"
460                  ><input 
461                    type="radio" 
462                    name="item_id" 
463                    value="<%=itemId%>" 
464                    title="<%=name%>" 
465                    <%=selectedItemId == itemId ? "checked" : ""%>
466                  ></tbl:header>
467                <tbl:header 
468                  clazz="icons" 
469                  visible="<%=mode.hasIcons()%>"
470                  >&nbsp;</tbl:header>
471                <tbl:cell column="name"><div class="link" 
472                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
473                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
474                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
475                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
476                <tbl:cell column="symbol"><%=HTML.encodeTags(item.getSymbol())%></tbl:cell>
477                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
478                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
479                <tbl:cell column="lastUpdate" value="<%=item.getLastUpdate()%>" />
480                <tbl:cell column="lastSource"><%=HTML.encodeTags(item.getLastSource())%></tbl:cell>
481                <tbl:cell column="reporterType"
482                  ><base:propertyvalue 
483                    dbcontrol="<%=dc%>" 
484                    item="<%=item%>" 
485                    property="reporterType"
486                    enableEditLink="<%=mode.hasEditLink()%>" 
487                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
488                  /></tbl:cell>
489                <%
490                if (reporterProperties != null)
491                {
492                  for (ExtendedProperty ep : reporterProperties)
493                  {
494                    name = ep.getName();
495                    %>
496                    <tbl:cell column="<%=name%>"><tbl:cellvalue value="<%=item.getExtended(name)%>" /></tbl:cell>
497                    <%
498                  }
499                }
500                %>
501              </tbl:row>
502              <%
503            }
504          }
505          %>
506          </tbl:rows>
507      </tbl:data>
508      <%
509      if (numListed == 0)
510      {
511        %>
512        <tbl:panel><%=reporters == null || reporters.getTotalCount() == 0 ? "No reporters were found" : "No reporters on this page. Please select another page!" %></tbl:panel>
513        <%
514      }
515      else
516      {
517        %>
518        <tbl:navigator
519          page="<%=cc.getPage()%>" 
520          rowsperpage="<%=cc.getRowsPerPage()%>" 
521          totalrows="<%=reporters == null ? 0 : reporters.getTotalCount()%>" 
522          visible="<%=mode.hasNavigator()%>"
523          locked="true"
524        />
525        <%
526      }
527      %>
528    </tbl:table>
529    <base:buttongroup align="center" clazz="fixedatbottom">
530      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
531      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
532      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
533    </base:buttongroup>
534    <br><br><br>
535  </base:body>
536  </base:page>
537  <%
538}
539finally
540{
541  if (reporters != null) reporters.close();
542  if (dc != null) dc.close();
543}
544%>
Note: See TracBrowser for help on using the repository browser.