source: branches/3.15-stable/www/my_base/messages/index.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: 10.3 KB
Line 
1<%-- $Id: index.jsp 7753 2019-11-13 11:01:17Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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.Include"
31  import="net.sf.basedb.core.Message"
32  import="net.sf.basedb.core.User"
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.ItemContext"
37  import="net.sf.basedb.core.MultiPermissions"
38  import="net.sf.basedb.core.PermissionDeniedException"
39  import="net.sf.basedb.core.ItemAlreadyExistsException"
40  import="net.sf.basedb.util.RemovableUtil"
41  import="net.sf.basedb.util.ShareableUtil"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.util.Values"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.core.plugin.GuiContext"
47  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
48  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
49  import="net.sf.basedb.clients.web.extensions.JspContext"
50  import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer"
51  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
52  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
53  import="java.util.Enumeration"
54  import="java.util.Set"
55  import="java.util.HashSet"
56  import="java.util.List"
57  import="java.util.ArrayList"
58  import="java.util.Collections"
59%>
60<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
61<%!
62  private static final ItemContext defaultContext = Base.createDefaultContext("timeSent", "name,from,timeSent,read,description");
63  private static final Item itemType = Item.MESSAGE;
64%>
65<%
66final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
67final String ID = sc.getId();
68final String cmd = request.getParameter("cmd");
69final String root = request.getContextPath()+"/";
70final String mode = request.getParameter("mode");
71final String callback = request.getParameter("callback");
72final String itemId = request.getParameter("item_id");
73final String listPage = "list_messages.jsp?ID="+ID
74  +(mode == null ? "" : "&mode="+mode)
75  +(callback == null ? "" : "&callback="+callback)
76  +(itemId == null ? "" : "&item_id="+itemId);
77final String viewPage = "view_message.jsp?ID="+ID;
78//final String editPage = "edit_job.jsp?ID="+ID;
79
80String forward = null;
81String redirect = null;
82String message = null;
83DbControl dc = null;
84
85try
86{
87  if (cmd == null || "List".equals(cmd))
88  {
89    // Display the list page without updatinging the current context
90    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
91    redirect = listPage;
92  }
93  else if ("UpdateContext".equals(cmd))
94  {
95    // Display the list page after updating the current context from the request parameters
96    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
97    redirect = listPage;
98  }
99  else if ("LoadContext".equals(cmd))
100  {
101    // Display the list page after loading a saved context
102    int contextId = Values.getInt(request.getParameter("context"));
103    Base.loadContext(sc, contextId, defaultContext);
104    redirect = listPage;
105  }
106
107  else if ("ViewItem".equals(cmd))
108  {
109    // Display the view page for a single item (opens in a popup)
110    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
111    forward = viewPage;
112  }
113  /*
114  else if ("EditItem".equals(cmd))
115  {
116    // Display the edit page for a single item (should be opened in a popup)
117    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
118    redirect = editPage;
119  }
120  */
121  else if ("MarkAsRead".equals(cmd))
122  {
123    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
124    int numRead = 0;
125    int numTotal = 0;
126    dc = sc.newDbControl();
127    for (int messageId : cc.getSelected())
128    {
129      Message m = Message.getById(dc, messageId);
130      if (!m.isRead())
131      {
132        numTotal++;
133        try
134        {
135          m.setRead(true);
136          numRead++;
137        }
138        catch (PermissionDeniedException ex)
139        {}
140      }
141    }
142    dc.commit();
143    if (numTotal != numRead)
144    {
145      message = (numRead == 0 ? "No" : "Only "+numRead+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
146    }
147    redirect = listPage;
148  }
149  else if ("DeleteItem".equals(cmd))
150  {
151    // Delete a single item and then return to the view page
152    dc = sc.newDbControl();
153    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
154    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
155    dc.commit();
156    redirect = viewPage;
157  }
158  else if ("DeleteItems".equals(cmd))
159  {
160    // Delete all selected items on the list page
161    dc = sc.newDbControl();
162    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
163    int numTotal = cc.getSelected().size();
164    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
165    dc.commit();
166    if (numTotal != numRemoved)
167    {
168      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
169    }
170    redirect = listPage;
171  }
172  else if ("RestoreItem".equals(cmd))
173  {
174    // Restore a single item and then return to the view page
175    dc = sc.newDbControl();
176    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
177    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
178    dc.commit();
179    redirect = viewPage;
180  }
181  else if ("RestoreItems".equals(cmd))
182  {
183    // Restore all selected items on the list page
184    dc = sc.newDbControl();
185    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
186    int numTotal = cc.getSelected().size();
187    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
188    dc.commit();
189    if (numTotal != numRemoved)
190    {
191      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
192    }
193    redirect = listPage;
194  }
195  else if ("ExportItems".equals(cmd))
196  {
197    // Run an export plugin in a list context
198    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
199    dc = sc.newDbControl();
200    final User user = User.getById(dc, sc.getLoggedInUserId());
201    final ItemQuery<Message> query = Message.getQuery(user);
202    cc.configureQuery(dc, query, true);
203    cc.setQuery(query);
204    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
205    ExtensionsInvoker<ListColumnAction<Message,?>> listInvoker = ListColumnUtil.useExtensions(jspContext);
206    listInvoker.render(new ListColumnExportRenderer<Message>(cc));
207    dc.close();
208    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+messages";
209  }
210  else if ("ExportItem".equals(cmd))
211  {
212    // Run an export plugin in single-item context
213    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
214    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+message";
215  }
216  else if ("ImportItems".equals(cmd))
217  {
218    // Run an import plugin in a list context
219    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
220    dc = sc.newDbControl();
221    final User user = User.getById(dc, sc.getLoggedInUserId());
222    final ItemQuery<Message> query = Message.getQuery(user);
223    cc.configureQuery(dc, query, true);
224    dc.close();
225    cc.setQuery(query);
226    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+messages";
227  }
228  else if ("ImportItem".equals(cmd))
229  {
230    // Run an import plugin in single-item context
231    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
232    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+messge";
233  }
234  else if ("RunListPlugin".equals(cmd))
235  {
236    // Run another plugin in a list context
237    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
238    dc = sc.newDbControl();
239    final User user = User.getById(dc, sc.getLoggedInUserId());
240    final ItemQuery<Message> query = Message.getQuery(user);
241    cc.configureQuery(dc, query, true);
242    dc.close();
243    cc.setQuery(query);
244    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
245  }
246  else if ("RunPlugin".equals(cmd))
247  {
248    // Run another plugin in single-item context
249    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
250    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
251  }
252  else
253  {
254    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
255  }
256}
257finally
258{
259  if (dc != null) dc.close();
260}
261
262if (forward != null)
263{
264  sc.setSessionSetting("alert-message", message);
265  pageContext.forward(forward);
266}
267else if (redirect != null)
268{
269  sc.setSessionSetting("alert-message", message);
270  response.sendRedirect(redirect);
271}
272else if (message == null)
273{
274  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
275}
276else
277{
278  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
279}
280%>
281
Note: See TracBrowser for help on using the repository browser.