source: trunk/www/my_base/messages/list_messages.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: 13.7 KB
Line 
1<%-- $Id: list_messages.jsp 5425 2010-09-23 13:30:07Z 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.Message"
31  import="net.sf.basedb.core.User"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.ItemResultIterator"
35  import="net.sf.basedb.core.ItemResultList"
36  import="net.sf.basedb.core.ItemContext"
37  import="net.sf.basedb.core.Permission"
38  import="net.sf.basedb.core.PluginDefinition"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.query.Hql"
41  import="net.sf.basedb.core.query.Restrictions"
42  import="net.sf.basedb.core.query.Expressions"
43  import="net.sf.basedb.core.plugin.GuiContext"
44  import="net.sf.basedb.core.plugin.Plugin"
45  import="net.sf.basedb.util.Enumeration"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.ModeInfo"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="net.sf.basedb.util.Values"
51  import="net.sf.basedb.util.formatter.Formatter"
52  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
53  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
54  import="net.sf.basedb.clients.web.extensions.JspContext"
55  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
56  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
57  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
58  import="java.util.List"
59  import="java.util.Map"
60  import="java.util.Date"
61%>
62<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
63<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
64<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
65<%!
66  private static final Item itemType = Item.MESSAGE;
67  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
68%>
69<%
70final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
71final String ID = sc.getId();
72final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
73final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
74
75final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
76final String callback = request.getParameter("callback");
77final String title = mode.generateTitle("message", "messages");
78final DbControl dc = sc.newDbControl();
79ItemResultIterator<Message> messages = null;
80try
81{
82  final User user = User.getById(dc, sc.getLoggedInUserId());
83  final ItemQuery<Message> query = Base.getConfiguredQuery(cc, true, Message.getQuery(user), mode);
84
85  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
86  try
87  {
88    messages = query.iterate(dc);
89  }
90  catch (Throwable t)
91  {
92    cc.setMessage(t.getMessage());
93  }
94  int numListed = 0;
95  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
96  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
97  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
98  %>
99  <base:page title="<%=title==null ? "Messages" : title%>" type="<%=mode.getPageType()%>">
100  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
101    <ext:scripts context="<%=jspContext%>" />
102    <ext:stylesheets context="<%=jspContext%>" />
103    <script language="JavaScript">
104    var submitPage = 'index.jsp';
105    var formId = 'messages';
106    function viewItem(itemId)
107    {
108      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
109    }
110    function itemOnClick(evt, itemId)
111    {
112      viewItem(itemId);
113    }
114    function markAsRead()
115    {
116      var frm = document.forms[formId];
117      if (Forms.numChecked(frm) == 0)
118      {
119        alert('Please select at least one item in the list');
120        return;
121      }
122      frm.action = submitPage;
123      frm.cmd.value = 'MarkAsRead';
124      frm.submit();
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 deleteItemPermanently(itemId)
151    {
152      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', itemId);
153    }
154    function configureColumns()
155    {
156      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
157    }
158    function runPlugin(cmd)
159    {
160      Table.submitToPopup(formId, cmd, 740, 540);
161    }
162    function returnSelected()
163    {
164      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
165      window.close();
166    }
167    function presetOnChange()
168    {
169      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
170    }
171    </script>
172  </base:head>
173 
174  <base:body>
175    <%
176    if (cc.getMessage() != null)
177    {
178      %>
179      <div class="error"><%=cc.getMessage()%></div>
180      <%
181      cc.setMessage(null);
182    }
183    %>
184    <tbl:table 
185      id="messages" 
186      clazz="itemlist" 
187      columns="<%=cc.getSetting("columns")%>"
188      sortby="<%=cc.getSortProperty()%>" 
189      direction="<%=cc.getSortDirection()%>"
190      title="<%=title%>"
191      action="index.jsp"
192      sc="<%=sc%>"
193      item="<%=itemType%>"
194      >
195      <tbl:hidden 
196        name="mode" 
197        value="<%=mode.getName()%>" 
198      />
199      <tbl:hidden 
200        name="callback" 
201        value="<%=callback%>" 
202        skip="<%=callback == null%>" 
203      />
204      <tbl:columndef 
205        id="name"
206        property="name"
207        datatype="string"
208        title="Subject"
209        sortable="true" 
210        filterable="true"
211        exportable="true"
212        show="always" 
213      />
214      <tbl:columndef 
215        id="id"
216        clazz="uniquecol"
217        property="id"
218        datatype="int"
219        title="ID"
220        sortable="true"
221        filterable="true"
222        exportable="true"
223      />
224      <tbl:columndef 
225        id="from"
226        property="from"
227        datatype="string"
228        title="From"
229        sortable="true" 
230        filterable="true"
231        exportable="true"
232      />
233      <tbl:columndef 
234        id="timeSent"
235        property="timeSent"
236        datatype="timestamp"
237        title="Time sent"
238        sortable="true" 
239        filterable="true"
240        exportable="true"
241        formatter="<%=dateTimeFormatter%>"
242      />
243      <tbl:columndef 
244        id="job"
245        property="job.name"
246        datatype="string"
247        title="Job"
248        sortable="true" 
249        filterable="true"
250        exportable="true"
251      />
252      <tbl:columndef 
253        id="description"
254        property="description"
255        datatype="string"
256        title="Message" 
257        sortable="true" 
258        filterable="true" 
259        exportable="true"
260      />
261      <tbl:columndef
262        id="permission"
263        title="Permission"
264      />
265      <tbl:toolbar
266        visible="<%=mode.hasToolbar()%>"
267        >
268        <tbl:button 
269          image="message.gif" 
270          onclick="markAsRead()" 
271          title="Mark as read" 
272          tooltip="Mark the selected messages as read" 
273        />
274        <tbl:button 
275          image="delete.gif"
276          onclick="deleteItems()" 
277          title="Delete" 
278          tooltip="Delete the selected items" 
279        />
280        <tbl:button 
281          image="restore.gif"
282          onclick="restoreItems()" 
283          title="Restore" 
284          tooltip="Restore the selected (deleted) items"
285        />
286        <tbl:button 
287          image="columns.gif" 
288          onclick="configureColumns()" 
289          title="Columns&hellip;" 
290          tooltip="Show, hide and re-order columns" 
291        />
292        <tbl:button 
293          image="import.gif" 
294          onclick="runPlugin('ImportItems')" 
295          title="Import&hellip;" 
296          tooltip="Import data" 
297          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
298        />
299        <tbl:button 
300          image="export.gif" 
301          onclick="runPlugin('ExportItems')" 
302          title="Export&hellip;" 
303          tooltip="Export data" 
304          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
305        />
306        <tbl:button 
307          image="runplugin.gif" 
308          onclick="runPlugin('RunListPlugin')" 
309          title="Run plugin&hellip;" 
310          tooltip="Run a plugin" 
311          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
312        />
313        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
314          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
315      </tbl:toolbar>
316      <tbl:navigator
317        page="<%=cc.getPage()%>" 
318        rowsperpage="<%=cc.getRowsPerPage()%>" 
319        totalrows="<%=messages == null ? 0 : messages.getTotalCount()%>" 
320        visible="<%=mode.hasNavigator()%>"
321      />
322      <tbl:data>
323        <tbl:columns>
324        <tbl:presetselector 
325          clazz="columnheader"
326          colspan="3"
327          onchange="presetOnChange()"
328        />
329        </tbl:columns>
330
331        <tr>
332          <tbl:header 
333            clazz="index"
334            >&nbsp;</tbl:header>
335          <tbl:header 
336            clazz="check" 
337            visible="<%=mode.hasCheck()%>"
338            ><base:icon 
339              image="check_uncheck.gif" 
340              tooltip="Check/uncheck all" 
341              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
342            /></tbl:header>
343          <tbl:header 
344            clazz="check" 
345            visible="<%=mode.hasRadio()%>"
346            >&nbsp;</tbl:header>
347          <tbl:header 
348            clazz="icons" 
349            visible="<%=mode.hasIcons()%>"
350            >&nbsp;</tbl:header>
351          <tbl:propertyfilter />
352        </tr>
353         
354          <tbl:rows>
355          <%
356          int index = cc.getPage()*cc.getRowsPerPage();
357          int selectedItemId = cc.getId();
358          boolean  editLink = false;
359          if (messages != null)
360          {
361            String tooltip = mode.isSelectionMode() ?
362              "Select this item" : "View this item";
363            while (messages.hasNext())
364            {
365              Message item = messages.next();
366              int itemId = item.getId();
367              String name = HTML.encodeTags(item.getName());
368              String deletePermanently = "deleteItemPermanently("+itemId+")";
369              boolean deletePermission = item.hasPermission(Permission.DELETE);
370              index++;
371              numListed++;
372              String style = null;
373              if (!item.isRead()) style = "font-weight: bold;";
374              %>
375              <tbl:row style="<%=style%>">
376                <tbl:header 
377                  clazz="index"
378                  ><%=index%></tbl:header>
379                <tbl:header 
380                  clazz="check" 
381                  visible="<%=mode.hasCheck()%>"
382                  ><input 
383                    type="checkbox" 
384                    name="<%=itemId%>" 
385                    value="<%=itemId%>" 
386                    title="<%=name%>" 
387                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
388                  ></tbl:header>
389                <tbl:header 
390                  clazz="check" 
391                  visible="<%=mode.hasRadio()%>"
392                  ><input 
393                    type="radio" 
394                    name="item_id" 
395                    value="<%=itemId%>" 
396                    title="<%=name%>" 
397                    <%=selectedItemId == itemId ? "checked" : ""%>
398                  ></tbl:header>
399                <tbl:header 
400                  clazz="icons" 
401                  visible="<%=mode.hasIcons()%>"
402                  ><base:icon 
403                    image="message.gif" 
404                    tooltip="This is a new message" 
405                    visible="<%=!item.isRead()%>"
406                  /><base:icon 
407                    image="<%=deletePermission ? "deleted.gif" : "deleted_disabled.gif"%>"
408                    onclick="<%=deletePermission ? deletePermanently : null%>"
409                    tooltip="This item has been scheduled for deletion" 
410                    visible="<%=item.isRemoved()%>"
411                  />&nbsp;</tbl:header>
412                <tbl:cell column="name"><div class="link" onclick="itemOnClick(event, <%=itemId%>)" 
413                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
414                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
415                <tbl:cell column="from"><%=HTML.encodeTags(item.getFrom())%></tbl:cell>
416                <tbl:cell column="timeSent" value="<%=item.getTimeSent()%>" />
417                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
418                <tbl:cell column="job"><base:propertyvalue item="<%=item%>" property="job" enableEditLink="<%=editLink%>" enablePropertyLink="<%=mode.hasPropertyLink()%>"/></tbl:cell>
419                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
420            </tbl:row>
421              <%
422              }
423            }
424          %>
425          </tbl:rows>
426      </tbl:data>
427      <%
428      if (numListed == 0)
429      {
430        %>
431        <tbl:panel><%=messages == null || messages.getTotalCount() == 0 ? "No messages were found" : "No messages on this page. Please select another page!" %></tbl:panel>
432        <%
433      }
434      else
435      {
436        %>
437        <tbl:navigator
438          page="<%=cc.getPage()%>" 
439          rowsperpage="<%=cc.getRowsPerPage()%>" 
440          totalrows="<%=messages == null ? 0 : messages.getTotalCount()%>" 
441          visible="<%=mode.hasNavigator()%>"
442          locked="true"
443        />
444        <%
445      }
446      %>
447    </tbl:table>
448    <base:buttongroup align="center" clazz="fixedatbottom">
449      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
450      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
451      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
452    </base:buttongroup>
453    <br><br><br>
454  </base:body>
455  </base:page>
456  <%
457}
458finally
459{
460  if (messages != null) messages.close();
461  if (dc != null) dc.close();
462}
463%>
Note: See TracBrowser for help on using the repository browser.