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