source: branches/3.15-stable/www/my_base/messages/list_messages.jsp @ 7753

Last change on this file since 7753 was 7753, checked in by Nicklas Nordborg, 4 years ago

Fixes #2198: Add "Has been read" column to the message list view

  • 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 7753 2019-11-13 11:01:17Z 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 pageEncoding="UTF-8" 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.ButtonAction" 
57  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
58  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
59  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
60  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
61  import="java.util.List"
62  import="java.util.Map"
63  import="java.util.Date"
64%>
65<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
66<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
67<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
68<%!
69  private static final Item itemType = Item.MESSAGE;
70  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
71%>
72<%
73final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
74final String ID = sc.getId();
75final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
76final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
77
78final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
79final String callback = request.getParameter("callback");
80final String title = mode.generateTitle("message", "messages");
81final DbControl dc = sc.newDbControl();
82ItemResultIterator<Message> messages = null;
83try
84{
85  final User user = User.getById(dc, sc.getLoggedInUserId());
86
87  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
88  try
89  {
90    final ItemQuery<Message> query = Base.getConfiguredQuery(dc, cc, true, Message.getQuery(user), mode);
91    messages = query.iterate(dc);
92  }
93  catch (Throwable t)
94  {
95    cc.setMessage(t.getMessage());
96  }
97  int numListed = 0;
98  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
99  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
100  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
101  ExtensionsInvoker<ListColumnAction<Message,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
102  %>
103  <base:page title="<%=title==null ? "Messages" : title%>" type="<%=mode.getPageType()%>" id="list-page">
104  <base:head scripts="table.js,~messages.js" styles="table.css,toolbar.css">
105    <ext:scripts context="<%=jspContext%>" />
106    <ext:stylesheets context="<%=jspContext%>" />
107  </base:head>
108 
109  <base:body>
110    <h1><%=title==null ? "Messages" : title%></h1>
111    <div class="content">
112    <tbl:table 
113      id="messages" 
114      columns="<%=cc.getSetting("columns")%>"
115      sortby="<%=cc.getSortProperty()%>" 
116      direction="<%=cc.getSortDirection()%>"
117      action="index.jsp"
118      sc="<%=sc%>"
119      item="<%=itemType%>"
120      filterrows="<%=cc.getFilterRows()%>"
121      subclass="fulltable"
122      >
123      <tbl:hidden 
124        name="mode" 
125        value="<%=mode.getName()%>" 
126      />
127      <tbl:hidden 
128        name="callback" 
129        value="<%=callback%>" 
130        skip="<%=callback == null%>" 
131      />
132      <tbl:columndef 
133        id="name"
134        property="name"
135        datatype="string"
136        title="Subject"
137        sortable="true" 
138        filterable="true"
139        exportable="true"
140        show="always" 
141      />
142      <tbl:columndef 
143        id="id"
144        clazz="uniquecol"
145        property="id"
146        datatype="int"
147        title="ID"
148        sortable="true"
149        filterable="true"
150        exportable="true"
151      />
152      <tbl:columndef 
153        id="from"
154        property="from"
155        datatype="string"
156        title="From"
157        sortable="true" 
158        filterable="true"
159        exportable="true"
160      />
161      <tbl:columndef 
162        id="timeSent"
163        property="timeSent"
164        datatype="timestamp"
165        title="Time sent"
166        sortable="true" 
167        filterable="true"
168        exportable="true"
169        formatter="<%=dateTimeFormatter%>"
170      />
171      <tbl:columndef 
172        id="read"
173        property="read"
174        datatype="boolean"
175        title="Has been read"
176        sortable="true" 
177        filterable="true"
178        exportable="true"
179      />
180      <tbl:columndef 
181        id="job"
182        property="job.name"
183        datatype="string"
184        title="Job"
185        sortable="true" 
186        filterable="true"
187        exportable="true"
188      />
189      <tbl:columndef 
190        id="description"
191        property="description"
192        datatype="string"
193        title="Message" 
194        sortable="true" 
195        filterable="true" 
196        exportable="true"
197      />
198      <tbl:columndef
199        id="permission"
200        title="Permission"
201      />
202      <tbl:columndef 
203        id="xt-columns" 
204        extensions="<%=columnsInvoker%>" 
205        jspcontext="<%=jspContext%>" 
206      />
207      <div class="panelgroup bg-filled-50 bottomborder">
208        <tbl:toolbar
209          subclass="bottomborder"
210          visible="<%=mode.hasToolbar()%>"
211          >
212          <tbl:button 
213            id="btnMarkAsRead"
214            image="message.png" 
215            title="Mark as read" 
216            tooltip="Mark the selected messages as read" 
217          />
218          <tbl:button 
219            id="btnDeleteItems"
220            image="delete.png"
221            title="Delete" 
222            tooltip="Delete the selected items" 
223          />
224          <tbl:button 
225            id="btnRestoreItems"
226            image="restore.png"
227            title="Restore" 
228            tooltip="Restore the selected (deleted) items"
229          />
230          <tbl:button 
231            id="btnColumns"
232            image="columns.png" 
233            title="Columns&hellip;" 
234            tooltip="Show, hide and re-order columns" 
235          />
236          <tbl:button 
237            id="btnImport"
238            data-plugin-type="IMPORT"
239            image="import.png" 
240            title="Import&hellip;" 
241            tooltip="Import data" 
242            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
243          />
244          <tbl:button 
245            id="btnExport"
246            data-plugin-type="EXPORT"
247            image="export.png" 
248            title="Export&hellip;" 
249            tooltip="Export data" 
250            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
251          />
252          <tbl:button 
253            id="btnRunPlugin"
254            data-plugin-type="OTHER"
255            image="runplugin.png" 
256            title="Run plugin&hellip;" 
257            tooltip="Run a plugin" 
258            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
259          />
260          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
261            wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
262        </tbl:toolbar>
263        <tbl:panel>
264          <tbl:presetselector />
265          <tbl:navigator
266            page="<%=cc.getPage()%>" 
267            rowsperpage="<%=cc.getRowsPerPage()%>" 
268            totalrows="<%=messages == null ? 0 : messages.getTotalCount()%>" 
269            visible="<%=mode.hasNavigator()%>"
270          />
271        </tbl:panel>
272      </div>
273      <tbl:data>
274        <tbl:headers>
275          <tbl:headerrow>
276            <tbl:header colspan="3" />
277            <tbl:columnheaders />
278          </tbl:headerrow>
279          <%
280          int numFilters = cc.getNumPropertyFilters();
281          int numRows = cc.getFilterRows();
282          for (int filterNo = 0; filterNo < numRows; filterNo++)
283          {
284            boolean lastRow = filterNo == numRows-1;
285            %>
286            <tbl:headerrow>
287              <tbl:header subclass="index" />
288              <tbl:header 
289                subclass="check" 
290                visible="<%=mode.hasCheck()%>"
291                ><base:icon 
292                  subclass="link table-check"
293                  image="check_uncheck.png" 
294                  tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
295                  visible="<%=lastRow%>"
296                /></tbl:header>
297              <tbl:header 
298                subclass="check" 
299                visible="<%=mode.hasRadio()%>"
300                />
301              <tbl:header 
302                subclass="icons" 
303                visible="<%=mode.hasIcons()%>"
304                >
305                <base:icon
306                  subclass="link table-filter-row-action"
307                  image="add.png"
308                  tooltip="Add extra filter row"
309                  visible="<%=lastRow%>"
310                /><base:icon
311                  subclass="link table-filter-row-action"
312                  image="remove.png"
313                  tooltip="Remove this filter row"
314                  visible="<%=numRows > 1 || numFilters > 0 %>"
315                  data-remove-row="<%=filterNo%>"
316                />
317              </tbl:header>
318              <tbl:propertyfilter row="<%=filterNo%>" />
319            </tbl:headerrow>
320            <%
321          }
322          %>
323        </tbl:headers>
324        <tbl:rows>
325          <%
326          if (cc.getMessage() != null)
327          {
328            %>
329            <tbl:panel subclass="bg-filled-50">
330              <div class="messagecontainer error"><%=cc.getMessage()%></div>
331            </tbl:panel>
332            <%
333            cc.setMessage(null);
334          }
335          int index = cc.getPage()*cc.getRowsPerPage();
336          int selectedItemId = cc.getId();
337          boolean  editLink = false;
338          if (messages != null)
339          {
340            String tooltip = mode.isSelectionMode() ?
341              "Select this item" : "View this item";
342            while (messages.hasNext())
343            {
344              Message item = messages.next();
345              int itemId = item.getId();
346              String name = HTML.encodeTags(item.getName());
347             
348              boolean deletePermission = item.hasPermission(Permission.DELETE);
349              index++;
350              numListed++;
351              String style = null;
352              if (!item.isRead()) style = "font-weight: bold;";
353              %>
354              <tbl:row style="<%=style%>">
355                <tbl:header 
356                  clazz="index"
357                  ><%=index%></tbl:header>
358                <tbl:header 
359                  clazz="check" 
360                  visible="<%=mode.hasCheck()%>"
361                  ><input 
362                    type="checkbox" 
363                    name="<%=itemId%>" 
364                    value="<%=itemId%>" 
365                    title="<%=name%>" 
366                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
367                  ></tbl:header>
368                <tbl:header 
369                  clazz="check" 
370                  visible="<%=mode.hasRadio()%>"
371                  ><input 
372                    type="radio" 
373                    name="item_id" 
374                    value="<%=itemId%>" 
375                    title="<%=name%>" 
376                    <%=selectedItemId == itemId ? "checked" : ""%>
377                  ></tbl:header>
378                <tbl:header 
379                  clazz="icons" 
380                  visible="<%=mode.hasIcons()%>"
381                  ><base:icon 
382                    image="message.png" 
383                    tooltip="This is a new message" 
384                    visible="<%=!item.isRead()%>"
385                  /><base:icon 
386                    image="deleted.png"
387                    id="<%="delete."+itemId %>"
388                    subclass="<%=deletePermission ? "table-delete-item" : "disabled" %>"
389                    data-item-id="<%=itemId%>"
390                    tooltip="This item has been scheduled for deletion" 
391                    visible="<%=item.isRemoved()%>"
392                  />&nbsp;</tbl:header>
393                <tbl:cell column="name"><div 
394                  class="link table-item"
395                  data-item-id="<%=itemId%>"
396                  data-no-edit="1"
397                  tabindex="0"
398                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
399                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
400                <tbl:cell column="from"><%=HTML.encodeTags(item.getFrom())%></tbl:cell>
401                <tbl:cell column="timeSent" value="<%=item.getTimeSent()%>" />
402                <tbl:cell column="read" value="<%=item.isRead()%>" />
403                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
404                <tbl:cell column="job"><base:propertyvalue item="<%=item%>" property="job" enableEditLink="<%=editLink%>" enablePropertyLink="<%=mode.hasPropertyLink()%>"/></tbl:cell>
405                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
406                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
407                  <tbl:cell column="xt-columns" />
408                </tbl:xt-cells>
409              </tbl:row>
410              <%
411              }
412            }
413          if (numListed == 0)
414          {
415            %>
416            <tbl:panel subclass="bg-filled-50">
417              <div class="messagecontainer note">
418              <%=messages == null || messages.getTotalCount() == 0 ? "No messages were found" : "No messages on this page. Please select another page!" %>
419              </div>
420            </tbl:panel>
421            <%
422          }
423          %>
424        </tbl:rows>
425      </tbl:data>
426    </tbl:table>
427    </div>
428   
429    <base:buttongroup subclass="dialogbuttons">
430      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
431      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
432      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
433    </base:buttongroup>
434   
435  </base:body>
436  </base:page>
437  <%
438}
439finally
440{
441  if (messages != null) messages.close();
442  if (dc != null) dc.close();
443}
444%>
Note: See TracBrowser for help on using the repository browser.