source: trunk/www/biomaterials/labels/index.jsp @ 2811

Last change on this file since 2811 was 2811, checked in by Nicklas Nordborg, 17 years ago

Clear hidden 'exclude' filter that was set by popups

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.5 KB
Line 
1<%-- $Id: index.jsp 2811 2006-10-26 10:05:23Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Include"
32  import="net.sf.basedb.core.Label"
33  import="net.sf.basedb.core.ItemQuery"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.ItemContext"
36  import="net.sf.basedb.core.ItemQuery"
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="java.util.Enumeration"
47  import="java.util.Set"
48  import="java.util.HashSet"
49  import="java.util.List"
50  import="java.util.ArrayList"
51  import="java.util.Collections"
52%>
53<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
54<%!
55  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,description");
56  private static final Item itemType = Item.LABEL;
57%>
58<%
59final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
60final String ID = sc.getId();
61final String cmd = request.getParameter("cmd");
62final String root = request.getContextPath()+"/";
63final String mode = request.getParameter("mode");
64final String callback = request.getParameter("callback");
65final String itemId = request.getParameter("item_id");
66final String listPage = "list_labels.jsp?ID="+ID
67  +(mode == null ? "" : "&mode="+mode)
68  +(callback == null ? "" : "&callback="+callback)
69  +(itemId == null ? "" : "&item_id="+itemId);
70final String viewPage = "view_label.jsp?ID="+ID;
71final String editPage = "edit_label.jsp?ID="+ID;
72
73String forward = null;
74String redirect = null;
75String message = null;
76DbControl dc = null;
77
78try
79{
80  if (cmd == null || "List".equals(cmd))
81  {
82    // Display the list page without updatinging the current context
83    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
84    redirect = listPage;
85  }
86  else if ("UpdateContext".equals(cmd))
87  {
88    // Display the list page after updating the current context from the request parameters
89    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
90    redirect = listPage;
91  }
92  else if ("LoadContext".equals(cmd))
93  {
94    // Display the list page after loading a saved context
95    int contextId = Values.getInt(request.getParameter("context"));
96    Base.loadContext(sc, contextId, defaultContext);
97    redirect = listPage;
98  }
99
100  else if ("ViewItem".equals(cmd))
101  {
102    // Display the view page for a single item
103    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
104    forward = viewPage;
105  }
106  else if ("EditItem".equals(cmd))
107  {
108    // Display the edit page for a single item (should be opened in a popup)
109    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
110    redirect = editPage;
111  }
112  else if ("NewItem".equals(cmd))
113  {
114    // Display the edit page for a new item (should be opened in a popup)
115    if (!sc.hasPermission(Permission.CREATE, itemType))
116    {
117      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
118    }
119    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
120    cc.setId(0);
121    redirect = editPage;
122  }
123  else if ("UpdateItem".equals(cmd))
124  {
125    // Update the properties on an item (will close the popup)
126    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
127    dc = sc.newDbControl();
128    Label label = (Label)cc.getObject("item");
129    if (label == null)
130    {
131      label = Label.getNew(dc);
132      message = "Label created";
133      dc.saveItem(label);
134    }
135    else
136    {
137      dc.reattachItem(label);
138      message = "Label updated";
139    }
140    label.setName(Values.getStringOrNull(request.getParameter("name")));
141    label.setDescription(Values.getStringOrNull(request.getParameter("description")));
142
143    dc.commit();
144    cc.removeObject("item");
145  }
146  else if ("DeleteItem".equals(cmd))
147  {
148    // Delete a single item and then return to the view page
149    dc = sc.newDbControl();
150    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
151    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
152    dc.commit();
153    redirect = viewPage;
154  }
155  else if ("DeleteItems".equals(cmd))
156  {
157    // Delete all selected items on the list page
158    dc = sc.newDbControl();
159    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
160    int numTotal = cc.getSelected().size();
161    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
162    dc.commit();
163    if (numTotal != numRemoved)
164    {
165      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
166    }
167    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
168  }
169  else if ("RestoreItem".equals(cmd))
170  {
171    // Restore a single item and then return to the view page
172    dc = sc.newDbControl();
173    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
174    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
175    dc.commit();
176    redirect = viewPage;
177  }
178  else if ("RestoreItems".equals(cmd))
179  {
180    // Restore all selected items on the list page
181    dc = sc.newDbControl();
182    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
183    int numTotal = cc.getSelected().size();
184    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
185    dc.commit();
186    if (numTotal != numRemoved)
187    {
188      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
189    }
190    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
191  }
192  else if ("ShareItem".equals(cmd))
193  {
194    // Display a popup window for sharing a single item
195    dc = sc.newDbControl();
196    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
197    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, Collections.singleton(cc.getId()));
198    dc.close();
199    cc.setObject("MultiPermissions", permissions);
200    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
201  }
202  else if ("ShareItems".equals(cmd))
203  {
204    // Display a popup window for sharing all selected items on the list page
205    dc = sc.newDbControl();
206    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
207    MultiPermissions permissions = ShareableUtil.getMultiPermissions(dc, itemType, cc.getSelected());
208    dc.close();
209    cc.setObject("MultiPermissions", permissions);
210    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
211  }
212  else if ("ExportItems".equals(cmd))
213  {
214    // Run an export plugin in a list context
215    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
216    final ItemQuery<Label> query = Label.getQuery();
217    cc.configureQuery(query, true);
218    cc.setQuery(query);
219    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+labels";
220  }
221  else if ("ExportItem".equals(cmd))
222  {
223    // Run an export plugin in single-item context
224    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
225    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+label";
226  }
227  else if ("ImportItems".equals(cmd))
228  {
229    // Run an import plugin in a list context
230    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
231    final ItemQuery<Label> query = Label.getQuery();
232    cc.configureQuery(query, true);
233    cc.setQuery(query);
234    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+labels";
235  }
236  else if ("ImportItem".equals(cmd))
237  {
238    // Run an import plugin in single-item context
239    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
240    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+label";
241  }
242  else if ("RunListPlugin".equals(cmd))
243  {
244    // Run another plugin in a list context
245    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
246    final ItemQuery<Label> query = Label.getQuery();
247    cc.configureQuery(query, true);
248    cc.setQuery(query);
249    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
250  }
251  else if ("RunPlugin".equals(cmd))
252  {
253    // Run another plugin in single-item context
254    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
255    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
256  }
257  else
258  {
259    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
260  }
261}
262finally
263{
264  if (dc != null) dc.close();
265}
266
267if (forward != null)
268{
269  pageContext.forward(forward);
270}
271else if (redirect != null)
272{
273  response.sendRedirect(redirect);
274}
275else if (message == null)
276{
277  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
278}
279else
280{
281  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
282}
283%>
284
Note: See TracBrowser for help on using the repository browser.