source: trunk/www/admin/protocoltypes/index.jsp @ 4906

Last change on this file since 4906 was 4906, checked in by Martin Svensson, 13 years ago

References #1128 More item-pages updated

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.7 KB
Line 
1<%-- $Id: index.jsp 4906 2009-04-24 13:53:14Z martin $
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 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.ProtocolType"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Protocol"
35  import="net.sf.basedb.core.ItemContext"
36  import="net.sf.basedb.core.MultiPermissions"
37  import="net.sf.basedb.core.PermissionDeniedException"
38  import="net.sf.basedb.core.ItemAlreadyExistsException"
39  import="net.sf.basedb.core.query.Expressions"
40  import="net.sf.basedb.core.query.Hql"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.util.RemovableUtil"
44  import="net.sf.basedb.util.formatter.NameableFormatter"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.WebException"
47  import="net.sf.basedb.util.Values"
48  import="net.sf.basedb.clients.web.plugins.ItemQueryLoader"
49  import="net.sf.basedb.clients.web.util.HTML"
50  import="java.util.Enumeration"
51  import="java.util.Set"
52  import="java.util.HashSet"
53  import="java.util.List"
54  import="java.util.ArrayList"
55  import="java.util.Collections"
56%>
57<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
58<%!
59  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,protocols,description");
60  private static final Item itemType = Item.PROTOCOLTYPE;
61 
62  private static void registerExportUtils(ItemContext cc)
63  {
64    // Register formatter
65    cc.setObject("export.formatter.&protocols(name)", new NameableFormatter());   
66   
67    // Register dataloader
68    String typeParameter = "protocolType";
69    ItemQuery<Protocol> protocolQuery = Protocol.getQuery();
70    protocolQuery.include(cc.getInclude());
71    protocolQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
72    protocolQuery.restrict(Restrictions.eq(Hql.property("protocolType"), Expressions.parameter(typeParameter)));
73    protocolQuery.order(Orders.asc(Hql.property("name"))); 
74    cc.setObject("export.dataloader.&protocols(name)", new ItemQueryLoader(protocolQuery, typeParameter));
75  }
76%>
77<%
78final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
79final String ID = sc.getId();
80final String cmd = request.getParameter("cmd");
81final String root = request.getContextPath()+"/";
82final String mode = request.getParameter("mode");
83final String callback = request.getParameter("callback");
84final String itemId = request.getParameter("item_id");
85final String listPage = "list_protocoltype.jsp?ID="+ID
86  +(mode == null ? "" : "&mode="+mode)
87  +(callback == null ? "" : "&callback="+callback)
88  +(itemId == null ? "" : "&item_id="+itemId);
89final String viewPage = "view_protocoltype.jsp?ID="+ID;
90final String editPage = "edit_protocoltype.jsp?ID="+ID;
91
92String forward = null;
93String redirect = null;
94String message = null;
95DbControl dc = null;
96
97try
98{
99  if (cmd == null || "List".equals(cmd))
100  {
101    // Display the list page without updatinging the current context
102    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
103    redirect = listPage;
104  }
105  else if ("UpdateContext".equals(cmd))
106  {
107    // Display the list page after updating the current context from the request parameters
108    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
109    redirect = listPage;
110  }
111  else if ("LoadContext".equals(cmd))
112  {
113    // Display the list page after loading a saved context
114    int contextId = Values.getInt(request.getParameter("context"));
115    Base.loadContext(sc, contextId, defaultContext);
116    redirect = listPage;
117  }
118
119  else if ("ViewItem".equals(cmd))
120  {
121    // Display the view page for a single item
122    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
123    forward = viewPage;
124  }
125  else if ("EditItem".equals(cmd))
126  {
127    // Display the edit page for a single item (should be opened in a popup)
128    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
129    redirect = editPage;
130  }
131  else if ("NewItem".equals(cmd))
132  {
133    // Display the edit page for a new item (should be opened in a popup)
134    if (!sc.hasPermission(Permission.CREATE, itemType))
135    {
136      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
137    }
138    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
139    cc.setId(0);
140    redirect = editPage;
141  }
142  else if ("UpdateItem".equals(cmd))
143  {
144    // Update the properties on an item (will close the popup)
145    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
146    dc = sc.newDbControl();
147    ProtocolType protocolType = (ProtocolType)cc.getObject("item");
148    if (protocolType == null)
149    {
150      protocolType = ProtocolType.getNew(dc);
151      message = "Protocol type created";
152      dc.saveItem(protocolType);
153    }
154    else
155    {
156      dc.reattachItem(protocolType);
157      message = "Protocol type updated";
158    }
159    protocolType.setName(Values.getStringOrNull(request.getParameter("name")));
160    protocolType.setDescription(Values.getStringOrNull(request.getParameter("description")));
161    dc.commit();
162    cc.removeObject("item");
163  }
164  else if ("DeleteItem".equals(cmd))
165  {
166    // Delete a single item and then return to the view page
167    dc = sc.newDbControl();
168    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
169    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
170    dc.commit();
171    redirect = viewPage;
172  }
173  else if ("DeleteItems".equals(cmd))
174  {
175    // Delete all selected items on the list page
176    dc = sc.newDbControl();
177    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
178    int numTotal = cc.getSelected().size();
179    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
180    dc.commit();
181    if (numTotal != numRemoved)
182    {
183      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
184    }
185    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
186  }
187  else if ("RestoreItem".equals(cmd))
188  {
189    // Restore a single item and then return to the view page
190    dc = sc.newDbControl();
191    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
192    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
193    dc.commit();
194    redirect = viewPage;
195  }
196  else if ("RestoreItems".equals(cmd))
197  {
198    // Restore all selected items on the list page
199    dc = sc.newDbControl();
200    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
201    int numTotal = cc.getSelected().size();
202    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
203    dc.commit();
204    if (numTotal != numRemoved)
205    {
206      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
207    }
208    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
209  }
210  else if ("ExportItems".equals(cmd))
211  {
212    // Run an export plugin in a list context
213    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
214    final ItemQuery<ProtocolType> query = ProtocolType.getQuery();
215    cc.configureQuery(query, true);
216    cc.setQuery(query);
217    registerExportUtils(cc);
218    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+protocol+types";
219  }
220  else if ("ExportItem".equals(cmd))
221  {
222    // Run an export plugin in single-item context
223    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
224    registerExportUtils(cc);
225    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+protocol+type";
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<ProtocolType> query = ProtocolType.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+protocol+types";
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+protocol+type";
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<ProtocolType> query = ProtocolType.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.