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

Last change on this file since 3679 was 3679, checked in by Jari Häkkinen, 16 years ago

Changing the pesky "a (ä) character to a.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.5 KB
Line 
1<%-- $Id: list_reporters.jsp 3679 2007-08-17 07:18:29Z jari $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Johan Enell, Jari Hakkinen, 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 2
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 this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330,
23  Boston, MA  02111-1307, USA.
24  ------------------------------------------------------------------
25
26  @author Nicklas
27  @version 2.0
28--%>
29<%@ page session="false"
30  import="net.sf.basedb.core.SessionControl"
31  import="net.sf.basedb.core.DbControl"
32  import="net.sf.basedb.core.SystemItems"
33  import="net.sf.basedb.core.Item"
34  import="net.sf.basedb.core.ItemContext"
35  import="net.sf.basedb.core.Reporter"
36  import="net.sf.basedb.core.ReporterType"
37  import="net.sf.basedb.core.PluginDefinition"
38  import="net.sf.basedb.core.data.ReporterData"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.DataQuery"
42  import="net.sf.basedb.core.DataResultIterator"
43  import="net.sf.basedb.core.ExtendedProperty"
44  import="net.sf.basedb.core.ExtendedProperties"
45  import="net.sf.basedb.core.Permission"
46  import="net.sf.basedb.core.query.Orders"
47  import="net.sf.basedb.core.query.Hql"
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.clients.web.Base"
52  import="net.sf.basedb.clients.web.ModeInfo"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.Values"
55  import="net.sf.basedb.util.formatter.Formatter"
56  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
57  import="java.util.Date"
58  import="java.util.Map"
59  import="java.util.List"
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.REPORTER;
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 boolean writePermission = sc.hasPermission(Permission.WRITE, itemType);
72final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType);
73
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("reporter", "reporters");
79final DbControl dc = sc.newDbControl();
80DataResultIterator<ReporterData> reporters = null;
81ItemResultList<ReporterType> reporterTypes = null;
82try
83{
84  final DataQuery<ReporterData> query = Reporter.getQuery();
85  cc.configureQuery(query, true);
86
87  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
88  final ItemQuery<ReporterType> typeQuery = ReporterType.getQuery();
89  typeQuery.order(Orders.asc(Hql.property("name")));
90  typeQuery.setCacheResult(true);
91  List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData");
92  try
93  {
94    reporters = query.iterate(dc);
95  }
96  catch (Throwable t)
97  {
98    cc.setMessage(t.getMessage());
99  }
100  int numListed = 0;
101  Formatter<Date> timeFormatter = FormatterFactory.getDateTimeFormatter(sc);
102  %>
103  <base:page title="<%=title==null ? "Reporters" : title%>" type="<%=mode.getPageType()%>">
104  <base:head scripts="table.js" styles="table.css">
105    <script language="JavaScript">
106    var submitPage = 'index.jsp';
107    var formId = 'reporters';
108    function newItem()
109    {
110      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
111    }
112    function editItem(itemId)
113    {
114      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
115    }
116    function viewItem(itemId)
117    {
118      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
119    }
120    function itemOnClick(evt, itemId)
121    {
122      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
123    }
124    function deleteItems()
125    {
126      var frm = document.forms[formId];
127      var numChecked = Forms.numChecked(frm);
128      if (numChecked == 0)
129      {
130        alert('Please select at least one item in the list');
131        return;
132      }
133      else
134      {
135        var rep = numChecked == 1 ? 'reporter' : 'reporters';
136        if (!confirm('You are about to delete '+numChecked+' '+rep+'. This can\'t be undone. Continue?'))
137        {
138          return;
139        }
140      }
141      frm.action = submitPage;
142      frm.cmd.value = 'DeleteItems';
143      frm.submit();
144    }
145    function configureColumns()
146    {
147      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
148    }
149    function runPlugin(cmd)
150    {
151      Table.submitToPopup(formId, cmd, 740, 540);
152    }
153    function returnSelected()
154    {
155      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
156      window.close();
157    }
158    function presetOnChange()
159    {
160      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
161    }
162    function newReporterList()
163    {
164      Table.submitToPopup(formId, 'CreateReporterList', 540, 400);
165    }
166    </script>
167  </base:head>
168 
169  <base:body>
170    <%
171    if (cc.getMessage() != null)
172    {
173      %>
174      <div class="error"><%=cc.getMessage()%></div>
175      <%
176      cc.setMessage(null);
177    }
178    %>
179    <tbl:table 
180      id="reporters" 
181      clazz="itemlist" 
182      columns="<%=cc.getSetting("columns")%>"
183      sortby="<%=cc.getSortProperty()%>" 
184      direction="<%=cc.getSortDirection()%>"
185      title="<%=title%>"
186      action="index.jsp"
187      sc="<%=sc%>"
188      item="<%=itemType%>"
189      >
190      <tbl:hidden 
191        name="mode" 
192        value="<%=mode.getName()%>" 
193      />
194      <tbl:hidden 
195        name="callback" 
196        value="<%=callback%>" 
197        skip="<%=callback == null%>" 
198      />
199      <tbl:columndef 
200        id="externalId"
201        property="externalId"
202        datatype="string"
203        title="External ID"
204        sortable="true" 
205        filterable="true"
206        exportable="true"
207      />
208      <tbl:columndef 
209        id="name"
210        property="name"
211        datatype="string"
212        title="Name"
213        sortable="true" 
214        filterable="true"
215        exportable="true"
216        show="always" 
217      />
218      <tbl:columndef 
219        id="symbol"
220        property="symbol"
221        datatype="string"
222        title="Gene symbol"
223        sortable="true" 
224        filterable="true"
225        exportable="true"
226      />
227      <tbl:columndef 
228        id="description"
229        property="description"
230        datatype="string"
231        title="Description" 
232        sortable="true" 
233        filterable="true" 
234        exportable="true"
235      />
236      <tbl:columndef 
237        id="lastUpdate"
238        property="lastUpdate"
239        datatype="date"
240        title="Last update" 
241        sortable="true" 
242        filterable="true" 
243        exportable="true"
244        formatter="<%=timeFormatter%>"
245      />
246      <%
247      Enumeration<String, String> types = new Enumeration<String, String>();
248      reporterTypes = typeQuery.list(dc);
249      for (ReporterType rt : reporterTypes)
250      {
251        types.add(Integer.toString(rt.getId()), HTML.encodeTags(rt.getName()));
252      }
253      %>
254      <tbl:columndef 
255        id="reporterType"
256        property="reporterType"
257        sortproperty="reporterType.name"
258        exportproperty="reporterType.name"
259        datatype="int"
260        enumeration="<%=types%>"
261        title="Type"
262        sortable="true" 
263        filterable="true"
264        exportable="true"
265      />
266      <%
267      if (reporterProperties != null)
268      {
269        for (ExtendedProperty ep : reporterProperties)
270        {
271          String name = ep.getName();
272          %>
273          <tbl:columndef
274            id="<%=name%>"
275            property="<%=name%>"
276            datatype="<%=ep.getType().getStringValue()%>"
277            title="<%=HTML.encodeTags(ep.getTitle())%>"
278            sortable="true"
279            filterable="true"
280            exportable="true"
281            formatter="<%=FormatterFactory.getExtendedPropertyFormatter(sc, ep)%>"
282          />
283          <%
284        }
285      }
286      %>
287      <tbl:toolbar
288        visible="<%=mode.hasToolbar()%>"
289        >
290        <tbl:button 
291          disabled="<%=createPermission ? false : true%>" 
292          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
293          onclick="newItem()" 
294          title="New&hellip;" 
295          tooltip="<%=createPermission ? "Create a new reporter" : "You do not have permission to create reporter"%>" 
296        />
297        <tbl:button 
298          disabled="<%=deletePermission ? false : true%>" 
299          image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
300          onclick="deleteItems()" 
301          title="Delete&hellip;" 
302          tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete reporters" %>" 
303        />
304        <tbl:button 
305          image="columns.gif" 
306          onclick="configureColumns()" 
307          title="Columns&hellip;" 
308          tooltip="Show, hide and re-order columns" 
309        />
310        <tbl:button
311          image="add.png"
312          onclick="newReporterList()"
313          title="New reporter list&hellip;"
314          tooltip="Create a new reporter list from matching reporters"
315          visible="<%=sc.hasPermission(Permission.CREATE, Item.REPORTERLIST)%>"
316        />
317        <tbl:button 
318          image="import.gif" 
319          onclick="runPlugin('ImportItems')" 
320          title="Import&hellip;" 
321          tooltip="Import data" 
322          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
323        />
324        <tbl:button 
325          image="export.gif" 
326          onclick="runPlugin('ExportItems')" 
327          title="Export&hellip;" 
328          tooltip="Export data" 
329          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
330        />
331        <tbl:button 
332          image="runplugin.gif" 
333          onclick="runPlugin('RunListPlugin')" 
334          title="Run plugin&hellip;" 
335          tooltip="Run a plugin" 
336          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
337        />
338      </tbl:toolbar>
339      <tbl:navigator
340        page="<%=cc.getPage()%>" 
341        rowsperpage="<%=cc.getRowsPerPage()%>" 
342        totalrows="<%=reporters == null ? 0 : reporters.getTotalCount()%>" 
343        visible="<%=mode.hasNavigator()%>"
344      />
345      <tbl:data>
346        <tbl:columns>
347        <tbl:presetselector 
348          clazz="columnheader"
349          colspan="3"
350          onchange="presetOnChange()"
351        />
352        </tbl:columns>
353        <tr>
354          <tbl:header 
355            clazz="index"
356            >&nbsp;</tbl:header>
357          <tbl:header 
358            clazz="check" 
359            visible="<%=mode.hasCheck()%>"
360            ><base:icon 
361              image="check_uncheck.gif" 
362              tooltip="Check/uncheck all" 
363              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
364            /></tbl:header>
365          <tbl:header 
366            clazz="check" 
367            visible="<%=mode.hasRadio()%>"
368            >&nbsp;</tbl:header>
369          <tbl:header 
370            clazz="icons" 
371            visible="<%=mode.hasIcons()%>"
372            >&nbsp;</tbl:header>
373          <tbl:propertyfilter />
374        </tr>
375          <tbl:rows>
376          <%
377          int index = cc.getPage()*cc.getRowsPerPage();
378          int selectedItemId = cc.getId();
379          if (reporters != null)
380          {
381            while (reporters.hasNext())
382            {
383              ReporterData item = reporters.next();
384              int itemId = item.getId();
385              String name = HTML.encodeTags(item.getName());
386              String tooltip = mode.isSelectionMode() ?
387                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
388              index++;
389              numListed++;
390              %>
391              <tbl:row>
392                <tbl:header 
393                  clazz="index"
394                  ><%=index%></tbl:header>
395                <tbl:header 
396                  clazz="check" 
397                  visible="<%=mode.hasCheck()%>"
398                  ><input 
399                    type="checkbox" 
400                    name="<%=itemId%>" 
401                    value="<%=itemId%>" 
402                    title="<%=name%>" 
403                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
404                  ></tbl:header>
405                <tbl:header 
406                  clazz="check" 
407                  visible="<%=mode.hasRadio()%>"
408                  ><input 
409                    type="radio" 
410                    name="item_id" 
411                    value="<%=itemId%>" 
412                    title="<%=name%>" 
413                    <%=selectedItemId == itemId ? "checked" : ""%>
414                  ></tbl:header>
415                <tbl:header 
416                  clazz="icons" 
417                  visible="<%=mode.hasIcons()%>"
418                  >&nbsp;</tbl:header>
419                <tbl:cell column="name"><div class="link" 
420                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
421                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
422                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
423                <tbl:cell column="symbol"><%=HTML.encodeTags(item.getSymbol())%></tbl:cell>
424                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
425                <tbl:cell column="lastUpdate" value="<%=item.getLastUpdate()%>" />
426                <tbl:cell column="reporterType"
427                  ><base:propertyvalue 
428                    dbcontrol="<%=dc%>" 
429                    item="<%=item%>" 
430                    property="reporterType"
431                    enableEditLink="<%=mode.hasEditLink()%>" 
432                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
433                  /></tbl:cell>
434                <%
435                if (reporterProperties != null)
436                {
437                  for (ExtendedProperty ep : reporterProperties)
438                  {
439                    name = ep.getName();
440                    %>
441                    <tbl:cell column="<%=name%>"><tbl:cellvalue value="<%=item.getExtended(name)%>" /></tbl:cell>
442                    <%
443                  }
444                }
445                %>
446              </tbl:row>
447              <%
448            }
449          }
450          %>
451          </tbl:rows>
452      </tbl:data>
453      <%
454      if (numListed == 0)
455      {
456        %>
457        <tbl:panel><%=reporters == null || reporters.getTotalCount() == 0 ? "No reporters were found" : "No reporters on this page. Please select another page!" %></tbl:panel>
458        <%
459      }
460      else
461      {
462        %>
463        <tbl:navigator
464          page="<%=cc.getPage()%>" 
465          rowsperpage="<%=cc.getRowsPerPage()%>" 
466          totalrows="<%=reporters == null ? 0 : reporters.getTotalCount()%>" 
467          visible="<%=mode.hasNavigator()%>"
468          locked="true"
469        />
470        <%
471      }
472      %>
473    </tbl:table>
474    <base:buttongroup align="center" clazz="fixedatbottom">
475      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
476      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
477      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
478    </base:buttongroup>
479    <br><br><br>
480  </base:body>
481  </base:page>
482  <%
483}
484finally
485{
486  if (reporters != null) reporters.close();
487  if (dc != null) dc.close();
488}
489%>
Note: See TracBrowser for help on using the repository browser.