www/lims/platetypes/eventtypes/index.jsp

Code
Comments
Other
Rev Date Author Line
2305 22 May 06 jari 1 <%-- $Id$
2305 22 May 06 jari 2   ------------------------------------------------------------------
5425 23 Sep 10 nicklas 3   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
2305 22 May 06 jari 4
2304 22 May 06 jari 5   This file is part of BASE - BioArray Software Environment.
2304 22 May 06 jari 6   Available at http://base.thep.lu.se/
2305 22 May 06 jari 7
2305 22 May 06 jari 8   BASE is free software; you can redistribute it and/or
2305 22 May 06 jari 9   modify it under the terms of the GNU General Public License
4476 05 Sep 08 jari 10   as published by the Free Software Foundation; either version 3
2305 22 May 06 jari 11   of the License, or (at your option) any later version.
2305 22 May 06 jari 12
2305 22 May 06 jari 13   BASE is distributed in the hope that it will be useful,
2305 22 May 06 jari 14   but WITHOUT ANY WARRANTY; without even the implied warranty of
2305 22 May 06 jari 15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2305 22 May 06 jari 16   GNU General Public License for more details.
2305 22 May 06 jari 17
2305 22 May 06 jari 18   You should have received a copy of the GNU General Public License
4511 11 Sep 08 jari 19   along with BASE. If not, see <http://www.gnu.org/licenses/>.
2305 22 May 06 jari 20   ------------------------------------------------------------------
2305 22 May 06 jari 21
2305 22 May 06 jari 22   @author Nicklas
2305 22 May 06 jari 23   @version 2.0
2305 22 May 06 jari 24 --%>
5426 24 Sep 10 nicklas 25 <%@ page pageEncoding="UTF-8" session="false"
2305 22 May 06 jari 26   import="net.sf.basedb.core.SessionControl"
2305 22 May 06 jari 27   import="net.sf.basedb.core.DbControl"
2305 22 May 06 jari 28   import="net.sf.basedb.core.Item"
2305 22 May 06 jari 29   import="net.sf.basedb.core.ItemContext"
2305 22 May 06 jari 30   import="net.sf.basedb.core.PlateType"
2305 22 May 06 jari 31   import="net.sf.basedb.core.PlateEventType"
5630 13 May 11 nicklas 32   import="net.sf.basedb.core.ItemSubtype"
2305 22 May 06 jari 33   import="net.sf.basedb.core.ItemQuery"
2305 22 May 06 jari 34   import="net.sf.basedb.core.Permission"
2305 22 May 06 jari 35   import="net.sf.basedb.core.PermissionDeniedException"
2305 22 May 06 jari 36   import="net.sf.basedb.util.RemovableUtil"
2305 22 May 06 jari 37   import="net.sf.basedb.clients.web.Base"
2305 22 May 06 jari 38   import="net.sf.basedb.clients.web.WebException"
2305 22 May 06 jari 39   import="net.sf.basedb.clients.web.util.HTML"
5498 17 Nov 10 nicklas 40   import="net.sf.basedb.core.plugin.GuiContext"
5498 17 Nov 10 nicklas 41   import="net.sf.basedb.util.extensions.ExtensionsInvoker"
5498 17 Nov 10 nicklas 42   import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
5498 17 Nov 10 nicklas 43   import="net.sf.basedb.clients.web.extensions.JspContext"
5498 17 Nov 10 nicklas 44   import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
7604 25 Feb 19 nicklas 45   import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction"
5498 17 Nov 10 nicklas 46   import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
6039 29 Mar 12 nicklas 47   import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer"
7604 25 Feb 19 nicklas 48   import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
6039 29 Mar 12 nicklas 49   import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
2753 20 Oct 06 nicklas 50   import="net.sf.basedb.util.Values"
2305 22 May 06 jari 51   import="java.util.List"
2305 22 May 06 jari 52   import="java.util.Collections"
2305 22 May 06 jari 53 %>
2305 22 May 06 jari 54 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
2305 22 May 06 jari 55 <%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
2305 22 May 06 jari 56 <%!
5630 13 May 11 nicklas 57   private static final ItemContext defaultContext = Base.createDefaultContext("ordinal", "name,ordinal,itemSubtype,description");
2305 22 May 06 jari 58   private static final Item itemType = Item.PLATEEVENTTYPE;
2305 22 May 06 jari 59 %>
2305 22 May 06 jari 60 <%
2305 22 May 06 jari 61 final int plateTypeId = Values.getInt(request.getParameter("platetype_id"));
2305 22 May 06 jari 62
2305 22 May 06 jari 63 final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
2305 22 May 06 jari 64 final String ID = sc.getId();
2305 22 May 06 jari 65 final String cmd = request.getParameter("cmd");
2305 22 May 06 jari 66 final String root = request.getContextPath()+"/";
2305 22 May 06 jari 67 final String mode = request.getParameter("mode");
2305 22 May 06 jari 68 final String callback = request.getParameter("callback");
2305 22 May 06 jari 69 final String itemId = request.getParameter("item_id");
2305 22 May 06 jari 70 final String listPage = "list_eventtypes.jsp?ID="+ID
2305 22 May 06 jari 71   +"&platetype_id="+plateTypeId
2305 22 May 06 jari 72   +(mode == null ? "" : "&mode="+mode)
2305 22 May 06 jari 73   +(callback == null ? "" : "&callback="+callback)
2305 22 May 06 jari 74   +(itemId == null ? "" : "&item_id="+itemId);
2305 22 May 06 jari 75 final String viewPage = "view_eventtype.jsp?ID="+ID+"&platetype_id="+plateTypeId;
2305 22 May 06 jari 76 final String editPage = "edit_eventtype.jsp?ID="+ID+"&platetype_id="+plateTypeId;
2305 22 May 06 jari 77
2305 22 May 06 jari 78 String forward = null;
2305 22 May 06 jari 79 String redirect = null;
2305 22 May 06 jari 80 String message = null;
2305 22 May 06 jari 81 DbControl dc = null;
2305 22 May 06 jari 82
2305 22 May 06 jari 83 try
2305 22 May 06 jari 84 {
2305 22 May 06 jari 85   if (cmd == null || "List".equals(cmd))
2305 22 May 06 jari 86   {
2305 22 May 06 jari 87     // Display the list page without updatinging the current context
2811 26 Oct 06 nicklas 88     Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
2305 22 May 06 jari 89     redirect = listPage;
2305 22 May 06 jari 90   }
2305 22 May 06 jari 91   else if ("UpdateContext".equals(cmd))
2305 22 May 06 jari 92   {
2305 22 May 06 jari 93     // Display the list page after updating the current context from the request parameters
2305 22 May 06 jari 94     Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
2305 22 May 06 jari 95     redirect = listPage;
2305 22 May 06 jari 96   }
2305 22 May 06 jari 97   else if ("LoadContext".equals(cmd))
2305 22 May 06 jari 98   {
2305 22 May 06 jari 99     // Display the list page after loading a saved context
2305 22 May 06 jari 100     int contextId = Values.getInt(request.getParameter("context"));
2305 22 May 06 jari 101     Base.loadContext(sc, contextId, defaultContext);
2305 22 May 06 jari 102     redirect = listPage;
2305 22 May 06 jari 103   }
2305 22 May 06 jari 104   else if ("ViewItem".equals(cmd))
2305 22 May 06 jari 105   {
2305 22 May 06 jari 106     // Display the view page for a single item 
2305 22 May 06 jari 107     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
2305 22 May 06 jari 108     forward = viewPage;
2305 22 May 06 jari 109   }
2305 22 May 06 jari 110   else if ("EditItem".equals(cmd))
2305 22 May 06 jari 111   {
2305 22 May 06 jari 112     // Display the edit page for a single item (should be opened in a popup)
2305 22 May 06 jari 113     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
2305 22 May 06 jari 114     redirect = editPage;
2305 22 May 06 jari 115   }
2305 22 May 06 jari 116   else if ("NewItem".equals(cmd))
2305 22 May 06 jari 117   {
2305 22 May 06 jari 118     // Display the edit page for a new item (should be opened in a popup)
2305 22 May 06 jari 119     if (!sc.hasPermission(Permission.CREATE, itemType))
2305 22 May 06 jari 120     {
2305 22 May 06 jari 121       throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
2305 22 May 06 jari 122     }
2305 22 May 06 jari 123     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
2305 22 May 06 jari 124     cc.setId(0);
2305 22 May 06 jari 125     redirect = editPage;
2305 22 May 06 jari 126   }
2305 22 May 06 jari 127   else if ("UpdateItem".equals(cmd))
2305 22 May 06 jari 128   {
2305 22 May 06 jari 129     // Update the properties on an item (will close the popup)
2305 22 May 06 jari 130     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
2598 28 Aug 06 nicklas 131     final int maxRecent = Base.getMaxRecent(sc);
7954 12 May 21 nicklas 132     dc = sc.newDbControl(":Edit "+itemType);
7605 26 Feb 19 nicklas 133     PlateEventType eventType = cc.getObject("item");
2305 22 May 06 jari 134     if (eventType == null)
2305 22 May 06 jari 135     {
2305 22 May 06 jari 136       PlateType plateType = PlateType.getById(dc, plateTypeId);
2305 22 May 06 jari 137       eventType = plateType.newEventType();
2305 22 May 06 jari 138       message = "Event type created";
2305 22 May 06 jari 139       dc.saveItem(eventType);
2305 22 May 06 jari 140     }
2305 22 May 06 jari 141     else
2305 22 May 06 jari 142     {
5060 19 Aug 09 nicklas 143       dc.reattachItem(eventType, false);
2305 22 May 06 jari 144       message = "Event type updated";
2305 22 May 06 jari 145     }
5498 17 Nov 10 nicklas 146     JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.PLATEEVENTTYPE), eventType);
7604 25 Feb 19 nicklas 147     ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext);
5498 17 Nov 10 nicklas 148     try
2305 22 May 06 jari 149     {
5498 17 Nov 10 nicklas 150       eventType.setName(Values.getStringOrNull(request.getParameter("name")));
5498 17 Nov 10 nicklas 151       eventType.setDescription(Values.getStringOrNull(request.getParameter("description")));
5498 17 Nov 10 nicklas 152       eventType.setOrdinal(Values.getInt(request.getParameter("ordinal")));
5498 17 Nov 10 nicklas 153       int protocolTypeId = Values.getInt(request.getParameter("protocoltype_id"), -1);
5498 17 Nov 10 nicklas 154       if (protocolTypeId >= 0) // < 0 = denied or unchanged
5498 17 Nov 10 nicklas 155       {
5630 13 May 11 nicklas 156         ItemSubtype pt = protocolTypeId == 0 ? null : ItemSubtype.getById(dc, protocolTypeId);
5498 17 Nov 10 nicklas 157         eventType.setProtocolType(pt);
7703 11 Apr 19 nicklas 158         cc.setRecent(Item.ITEMSUBTYPE, pt, maxRecent);
5498 17 Nov 10 nicklas 159       }
5498 17 Nov 10 nicklas 160       
5498 17 Nov 10 nicklas 161       // OnSave extensions
5498 17 Nov 10 nicklas 162       invoker.render(OnSaveRenderer.ON_SAVE);
5498 17 Nov 10 nicklas 163       dc.commit();
5498 17 Nov 10 nicklas 164       invoker.render(OnSaveRenderer.ON_COMMIT);
2305 22 May 06 jari 165     }
5498 17 Nov 10 nicklas 166     catch (Exception ex)
5498 17 Nov 10 nicklas 167     {
5498 17 Nov 10 nicklas 168       invoker.render(OnSaveRenderer.onRollback(ex));
5498 17 Nov 10 nicklas 169       throw ex;
5498 17 Nov 10 nicklas 170     }
5498 17 Nov 10 nicklas 171     finally
5498 17 Nov 10 nicklas 172     {
5498 17 Nov 10 nicklas 173       cc.removeObject("item");
5498 17 Nov 10 nicklas 174     }
2305 22 May 06 jari 175   }
2305 22 May 06 jari 176   else if ("DeleteItem".equals(cmd))
2305 22 May 06 jari 177   {
2305 22 May 06 jari 178     // Delete a single item and then return to the view page
7954 12 May 21 nicklas 179     dc = sc.newDbControl(":Delete "+itemType);
2305 22 May 06 jari 180     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
2305 22 May 06 jari 181     RemovableUtil.delete(dc, itemType, Collections.singleton(cc.getId()));
2305 22 May 06 jari 182     dc.commit();
6306 13 Aug 13 nicklas 183     redirect = listPage;
2305 22 May 06 jari 184   }
2305 22 May 06 jari 185   else if ("DeleteItems".equals(cmd))
2305 22 May 06 jari 186   {
2305 22 May 06 jari 187     // Delete all selected items on the list page
7954 12 May 21 nicklas 188     dc = sc.newDbControl(":Delete "+itemType);
2305 22 May 06 jari 189     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
2305 22 May 06 jari 190     int numTotal = cc.getSelected().size();
2305 22 May 06 jari 191     int numDeleted = RemovableUtil.delete(dc, itemType, cc.getSelected());
2305 22 May 06 jari 192     dc.commit();
2305 22 May 06 jari 193     if (numTotal != numDeleted)
2305 22 May 06 jari 194     {
2305 22 May 06 jari 195       message = (numDeleted == 0 ? "No" : "Only "+numDeleted+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
2305 22 May 06 jari 196     }
6192 31 Oct 12 nicklas 197     redirect = listPage;
2305 22 May 06 jari 198   }
2305 22 May 06 jari 199   else if ("ExportItems".equals(cmd))
2305 22 May 06 jari 200   {
2305 22 May 06 jari 201     // Run an export plugin in a list context
2305 22 May 06 jari 202     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
7954 12 May 21 nicklas 203     dc = sc.newDbControl(":Export "+itemType);
2305 22 May 06 jari 204     final PlateType plateType = PlateType.getById(dc, plateTypeId);
5590 16 Mar 11 nicklas 205     final ItemQuery<PlateEventType> query = PlateEventType.getQuery(plateType);
7914 23 Feb 21 nicklas 206     JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
7914 23 Feb 21 nicklas 207     cc.configureQuery(dc, query, jspContext, true);
6039 29 Mar 12 nicklas 208     cc.setQuery(query);
7604 25 Feb 19 nicklas 209     ExtensionsInvoker<ListColumnAction<PlateEventType,?>> listInvoker = ListColumnUtil.useExtensions(jspContext);
7604 25 Feb 19 nicklas 210     listInvoker.render(new ListColumnExportRenderer<PlateEventType>(cc));
2305 22 May 06 jari 211     dc.close();
6039 29 Mar 12 nicklas 212     redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+event+types";
2305 22 May 06 jari 213   }
2305 22 May 06 jari 214   else if ("ExportItem".equals(cmd))
2305 22 May 06 jari 215   {
2305 22 May 06 jari 216     // Run an export plugin in single-item context
2305 22 May 06 jari 217     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
6039 29 Mar 12 nicklas 218     redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+event+type";
2305 22 May 06 jari 219   }
2305 22 May 06 jari 220   else if ("ImportItems".equals(cmd))
2305 22 May 06 jari 221   {
2305 22 May 06 jari 222     // Run an import plugin in a list context
2305 22 May 06 jari 223     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
7954 12 May 21 nicklas 224     dc = sc.newDbControl(":Import "+itemType);
2305 22 May 06 jari 225     final PlateType plateType = PlateType.getById(dc, plateTypeId);
5590 16 Mar 11 nicklas 226     final ItemQuery<PlateEventType> query = PlateEventType.getQuery(plateType);
7914 23 Feb 21 nicklas 227     JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
7914 23 Feb 21 nicklas 228     cc.configureQuery(dc, query, jspContext, true);
2305 22 May 06 jari 229     dc.close();
2305 22 May 06 jari 230     cc.setQuery(query);
6039 29 Mar 12 nicklas 231     redirect = "../../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+event+types";
2305 22 May 06 jari 232   }
2305 22 May 06 jari 233   else if ("ImportItem".equals(cmd))
2305 22 May 06 jari 234   {
2305 22 May 06 jari 235     // Run an import plugin in single-item context
2305 22 May 06 jari 236     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
6039 29 Mar 12 nicklas 237     redirect = "../../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+event+type";
2305 22 May 06 jari 238   }
2305 22 May 06 jari 239   else if ("RunListPlugin".equals(cmd))
2305 22 May 06 jari 240   {
2305 22 May 06 jari 241     // Run another plugin in a list context
2305 22 May 06 jari 242     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
7954 12 May 21 nicklas 243     dc = sc.newDbControl(":Run plugin "+itemType);
2305 22 May 06 jari 244     final PlateType plateType = PlateType.getById(dc, plateTypeId);
5590 16 Mar 11 nicklas 245     final ItemQuery<PlateEventType> query = PlateEventType.getQuery(plateType);
7914 23 Feb 21 nicklas 246     JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
7914 23 Feb 21 nicklas 247     cc.configureQuery(dc, query, jspContext, true);
2305 22 May 06 jari 248     dc.close();
2305 22 May 06 jari 249     cc.setQuery(query);
6039 29 Mar 12 nicklas 250     redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
2305 22 May 06 jari 251   }
2305 22 May 06 jari 252   else if ("RunPlugin".equals(cmd))
2305 22 May 06 jari 253   {
2305 22 May 06 jari 254     // Run another plugin in single-item context
2305 22 May 06 jari 255     ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
6039 29 Mar 12 nicklas 256     redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
2305 22 May 06 jari 257   }
2305 22 May 06 jari 258   else
2305 22 May 06 jari 259   {
2305 22 May 06 jari 260     throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
2305 22 May 06 jari 261   }
2305 22 May 06 jari 262
2305 22 May 06 jari 263 }
2305 22 May 06 jari 264 finally
2305 22 May 06 jari 265 {
2305 22 May 06 jari 266   if (dc != null) dc.close();
2305 22 May 06 jari 267 }
2305 22 May 06 jari 268 if (forward != null)
2305 22 May 06 jari 269 {
6192 31 Oct 12 nicklas 270   sc.setSessionSetting("alert-message", message);
2305 22 May 06 jari 271   pageContext.forward(forward);
2305 22 May 06 jari 272 }
2305 22 May 06 jari 273 else if (redirect != null)
2305 22 May 06 jari 274 {
6192 31 Oct 12 nicklas 275   sc.setSessionSetting("alert-message", message);
2305 22 May 06 jari 276   response.sendRedirect(redirect);
2305 22 May 06 jari 277 }
2305 22 May 06 jari 278 else if (message == null)
2305 22 May 06 jari 279 {
2305 22 May 06 jari 280   response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
2305 22 May 06 jari 281 }
2305 22 May 06 jari 282 else
2305 22 May 06 jari 283 {
2305 22 May 06 jari 284   response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
2305 22 May 06 jari 285 }
2305 22 May 06 jari 286
3675 16 Aug 07 jari 287 %>