502 |
02 May 05 |
nicklas |
1 |
<%-- $Id$ |
502 |
02 May 05 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
5425 |
23 Sep 10 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
502 |
02 May 05 |
nicklas |
6 |
|
2304 |
22 May 06 |
jari |
7 |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
8 |
Available at http://base.thep.lu.se/ |
502 |
02 May 05 |
nicklas |
9 |
|
502 |
02 May 05 |
nicklas |
10 |
BASE is free software; you can redistribute it and/or |
502 |
02 May 05 |
nicklas |
11 |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
12 |
as published by the Free Software Foundation; either version 3 |
502 |
02 May 05 |
nicklas |
13 |
of the License, or (at your option) any later version. |
502 |
02 May 05 |
nicklas |
14 |
|
502 |
02 May 05 |
nicklas |
15 |
BASE is distributed in the hope that it will be useful, |
502 |
02 May 05 |
nicklas |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
502 |
02 May 05 |
nicklas |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
502 |
02 May 05 |
nicklas |
18 |
GNU General Public License for more details. |
502 |
02 May 05 |
nicklas |
19 |
|
502 |
02 May 05 |
nicklas |
20 |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
21 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
502 |
02 May 05 |
nicklas |
22 |
------------------------------------------------------------------ |
502 |
02 May 05 |
nicklas |
23 |
|
502 |
02 May 05 |
nicklas |
24 |
@author Nicklas |
502 |
02 May 05 |
nicklas |
25 |
@version 2.0 |
502 |
02 May 05 |
nicklas |
26 |
--%> |
5426 |
24 Sep 10 |
nicklas |
27 |
<%@ page pageEncoding="UTF-8" session="false" |
502 |
02 May 05 |
nicklas |
28 |
import="net.sf.basedb.core.SessionControl" |
502 |
02 May 05 |
nicklas |
29 |
import="net.sf.basedb.core.DbControl" |
502 |
02 May 05 |
nicklas |
30 |
import="net.sf.basedb.core.Item" |
1959 |
09 Feb 06 |
nicklas |
31 |
import="net.sf.basedb.core.Include" |
502 |
02 May 05 |
nicklas |
32 |
import="net.sf.basedb.core.Group" |
1959 |
09 Feb 06 |
nicklas |
33 |
import="net.sf.basedb.core.User" |
508 |
03 May 05 |
nicklas |
34 |
import="net.sf.basedb.core.Quota" |
1418 |
07 Oct 05 |
nicklas |
35 |
import="net.sf.basedb.core.ItemQuery" |
502 |
02 May 05 |
nicklas |
36 |
import="net.sf.basedb.core.Permission" |
1959 |
09 Feb 06 |
nicklas |
37 |
import="net.sf.basedb.core.ItemContext" |
1959 |
09 Feb 06 |
nicklas |
38 |
import="net.sf.basedb.core.MultiPermissions" |
515 |
03 May 05 |
nicklas |
39 |
import="net.sf.basedb.core.PermissionDeniedException" |
1959 |
09 Feb 06 |
nicklas |
40 |
import="net.sf.basedb.core.ItemAlreadyExistsException" |
4906 |
24 Apr 09 |
martin |
41 |
import="net.sf.basedb.core.query.Expressions" |
4906 |
24 Apr 09 |
martin |
42 |
import="net.sf.basedb.core.query.Hql" |
4906 |
24 Apr 09 |
martin |
43 |
import="net.sf.basedb.core.query.Orders" |
4906 |
24 Apr 09 |
martin |
44 |
import="net.sf.basedb.core.query.Restrictions" |
1959 |
09 Feb 06 |
nicklas |
45 |
import="net.sf.basedb.util.RemovableUtil" |
502 |
02 May 05 |
nicklas |
46 |
import="net.sf.basedb.clients.web.Base" |
1959 |
09 Feb 06 |
nicklas |
47 |
import="net.sf.basedb.clients.web.WebException" |
2753 |
20 Oct 06 |
nicklas |
48 |
import="net.sf.basedb.util.Values" |
4906 |
24 Apr 09 |
martin |
49 |
import="net.sf.basedb.util.formatter.NameableFormatter" |
502 |
02 May 05 |
nicklas |
50 |
import="net.sf.basedb.clients.web.util.HTML" |
4906 |
24 Apr 09 |
martin |
51 |
import="net.sf.basedb.clients.web.plugins.ItemQueryLoader" |
5506 |
19 Nov 10 |
nicklas |
52 |
import="net.sf.basedb.core.plugin.GuiContext" |
5506 |
19 Nov 10 |
nicklas |
53 |
import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
5506 |
19 Nov 10 |
nicklas |
54 |
import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
5506 |
19 Nov 10 |
nicklas |
55 |
import="net.sf.basedb.clients.web.extensions.JspContext" |
5506 |
19 Nov 10 |
nicklas |
56 |
import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
7604 |
25 Feb 19 |
nicklas |
57 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
5506 |
19 Nov 10 |
nicklas |
58 |
import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
6045 |
03 Apr 12 |
nicklas |
59 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer" |
7604 |
25 Feb 19 |
nicklas |
60 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnAction" |
6045 |
03 Apr 12 |
nicklas |
61 |
import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil" |
1959 |
09 Feb 06 |
nicklas |
62 |
import="java.util.Enumeration" |
1959 |
09 Feb 06 |
nicklas |
63 |
import="java.util.Set" |
1959 |
09 Feb 06 |
nicklas |
64 |
import="java.util.HashSet" |
1959 |
09 Feb 06 |
nicklas |
65 |
import="java.util.List" |
1959 |
09 Feb 06 |
nicklas |
66 |
import="java.util.ArrayList" |
1959 |
09 Feb 06 |
nicklas |
67 |
import="java.util.Collections" |
502 |
02 May 05 |
nicklas |
68 |
%> |
502 |
02 May 05 |
nicklas |
69 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
502 |
02 May 05 |
nicklas |
70 |
<%! |
3467 |
08 Jun 07 |
nicklas |
71 |
private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,isDefault,description"); |
1959 |
09 Feb 06 |
nicklas |
72 |
private static final Item itemType = Item.GROUP; |
4906 |
24 Apr 09 |
martin |
73 |
|
4906 |
24 Apr 09 |
martin |
74 |
private static void registerExportUtils(ItemContext cc) |
4906 |
24 Apr 09 |
martin |
75 |
{ |
4906 |
24 Apr 09 |
martin |
76 |
// Register formatters |
4906 |
24 Apr 09 |
martin |
77 |
cc.setObject("export.formatter.&children(name)", new NameableFormatter()); |
4906 |
24 Apr 09 |
martin |
78 |
cc.setObject("export.formatter.&users(name)", new NameableFormatter()); |
4906 |
24 Apr 09 |
martin |
79 |
|
4906 |
24 Apr 09 |
martin |
80 |
|
4906 |
24 Apr 09 |
martin |
81 |
// Register dataloaders |
4906 |
24 Apr 09 |
martin |
82 |
String groupParameter = "group"; |
4906 |
24 Apr 09 |
martin |
83 |
// Groups |
4906 |
24 Apr 09 |
martin |
84 |
ItemQuery<Group> groupQuery = Group.getQuery(); |
4906 |
24 Apr 09 |
martin |
85 |
groupQuery.include(cc.getInclude()); |
4906 |
24 Apr 09 |
martin |
86 |
groupQuery.join(Hql.innerJoin("parents", "p")); |
4906 |
24 Apr 09 |
martin |
87 |
groupQuery.restrict(Restrictions.eq(Hql.alias("p"), Expressions.parameter(groupParameter))); |
4906 |
24 Apr 09 |
martin |
88 |
groupQuery.order(Orders.asc(Hql.property("name"))); |
7604 |
25 Feb 19 |
nicklas |
89 |
cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader<Group>(groupQuery, groupParameter)); |
4906 |
24 Apr 09 |
martin |
90 |
|
4906 |
24 Apr 09 |
martin |
91 |
// Users |
4906 |
24 Apr 09 |
martin |
92 |
ItemQuery<User> userQuery = User.getQuery(); |
4906 |
24 Apr 09 |
martin |
93 |
userQuery.include(cc.getInclude()); |
4906 |
24 Apr 09 |
martin |
94 |
userQuery.join(Hql.innerJoin("groups", "grp")); |
4906 |
24 Apr 09 |
martin |
95 |
userQuery.restrict(Restrictions.eq(Hql.alias("grp"), Expressions.parameter(groupParameter))); |
4906 |
24 Apr 09 |
martin |
96 |
userQuery.order(Orders.asc(Hql.property("name"))); |
7604 |
25 Feb 19 |
nicklas |
97 |
cc.setObject("export.dataloader.&users(name)", new ItemQueryLoader<Group>(userQuery, groupParameter)); |
4906 |
24 Apr 09 |
martin |
98 |
} |
502 |
02 May 05 |
nicklas |
99 |
%> |
502 |
02 May 05 |
nicklas |
100 |
<% |
1959 |
09 Feb 06 |
nicklas |
101 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
502 |
02 May 05 |
nicklas |
102 |
final String ID = sc.getId(); |
1959 |
09 Feb 06 |
nicklas |
103 |
final String cmd = request.getParameter("cmd"); |
1959 |
09 Feb 06 |
nicklas |
104 |
final String root = request.getContextPath()+"/"; |
1959 |
09 Feb 06 |
nicklas |
105 |
final String mode = request.getParameter("mode"); |
1959 |
09 Feb 06 |
nicklas |
106 |
final String callback = request.getParameter("callback"); |
1959 |
09 Feb 06 |
nicklas |
107 |
final String itemId = request.getParameter("item_id"); |
1959 |
09 Feb 06 |
nicklas |
108 |
final String listPage = "list_groups.jsp?ID="+ID |
1959 |
09 Feb 06 |
nicklas |
109 |
+(mode == null ? "" : "&mode="+mode) |
1959 |
09 Feb 06 |
nicklas |
110 |
+(callback == null ? "" : "&callback="+callback) |
1959 |
09 Feb 06 |
nicklas |
111 |
+(itemId == null ? "" : "&item_id="+itemId); |
1959 |
09 Feb 06 |
nicklas |
112 |
final String viewPage = "view_group.jsp?ID="+ID; |
1959 |
09 Feb 06 |
nicklas |
113 |
final String editPage = "edit_group.jsp?ID="+ID; |
502 |
02 May 05 |
nicklas |
114 |
|
1959 |
09 Feb 06 |
nicklas |
115 |
String forward = null; |
1959 |
09 Feb 06 |
nicklas |
116 |
String redirect = null; |
1959 |
09 Feb 06 |
nicklas |
117 |
String message = null; |
1959 |
09 Feb 06 |
nicklas |
118 |
DbControl dc = null; |
1959 |
09 Feb 06 |
nicklas |
119 |
|
502 |
02 May 05 |
nicklas |
120 |
try |
502 |
02 May 05 |
nicklas |
121 |
{ |
1959 |
09 Feb 06 |
nicklas |
122 |
if (cmd == null || "List".equals(cmd)) |
517 |
03 May 05 |
nicklas |
123 |
{ |
1959 |
09 Feb 06 |
nicklas |
124 |
// Display the list page without updatinging the current context |
2811 |
26 Oct 06 |
nicklas |
125 |
Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true); |
1959 |
09 Feb 06 |
nicklas |
126 |
redirect = listPage; |
517 |
03 May 05 |
nicklas |
127 |
} |
1959 |
09 Feb 06 |
nicklas |
128 |
else if ("UpdateContext".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
129 |
{ |
1959 |
09 Feb 06 |
nicklas |
130 |
// Display the list page after updating the current context from the request parameters |
1959 |
09 Feb 06 |
nicklas |
131 |
Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
132 |
redirect = listPage; |
1959 |
09 Feb 06 |
nicklas |
133 |
} |
1959 |
09 Feb 06 |
nicklas |
134 |
else if ("LoadContext".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
135 |
{ |
1959 |
09 Feb 06 |
nicklas |
136 |
// Display the list page after loading a saved context |
1959 |
09 Feb 06 |
nicklas |
137 |
int contextId = Values.getInt(request.getParameter("context")); |
1959 |
09 Feb 06 |
nicklas |
138 |
Base.loadContext(sc, contextId, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
139 |
redirect = listPage; |
1959 |
09 Feb 06 |
nicklas |
140 |
} |
1959 |
09 Feb 06 |
nicklas |
141 |
|
1959 |
09 Feb 06 |
nicklas |
142 |
else if ("ViewItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
143 |
{ |
1959 |
09 Feb 06 |
nicklas |
144 |
// Display the view page for a single item |
1959 |
09 Feb 06 |
nicklas |
145 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
146 |
forward = viewPage; |
1959 |
09 Feb 06 |
nicklas |
147 |
} |
1959 |
09 Feb 06 |
nicklas |
148 |
else if ("EditItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
149 |
{ |
1959 |
09 Feb 06 |
nicklas |
150 |
// Display the edit page for a single item (should be opened in a popup) |
1959 |
09 Feb 06 |
nicklas |
151 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
152 |
redirect = editPage; |
1959 |
09 Feb 06 |
nicklas |
153 |
} |
1959 |
09 Feb 06 |
nicklas |
154 |
else if ("NewItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
155 |
{ |
1959 |
09 Feb 06 |
nicklas |
156 |
// Display the edit page for a new item (should be opened in a popup) |
1959 |
09 Feb 06 |
nicklas |
157 |
if (!sc.hasPermission(Permission.CREATE, itemType)) |
502 |
02 May 05 |
nicklas |
158 |
{ |
1959 |
09 Feb 06 |
nicklas |
159 |
throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); |
502 |
02 May 05 |
nicklas |
160 |
} |
1959 |
09 Feb 06 |
nicklas |
161 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
162 |
cc.setId(0); |
2434 |
27 Jun 06 |
nicklas |
163 |
forward = editPage; |
1959 |
09 Feb 06 |
nicklas |
164 |
} |
1959 |
09 Feb 06 |
nicklas |
165 |
else if ("UpdateItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
166 |
{ |
1959 |
09 Feb 06 |
nicklas |
167 |
// Update the properties on an item (will close the popup) |
1959 |
09 Feb 06 |
nicklas |
168 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext); |
7954 |
12 May 21 |
nicklas |
169 |
dc = sc.newDbControl(":Edit "+itemType); |
7605 |
26 Feb 19 |
nicklas |
170 |
Group group = cc.getObject("item"); |
1959 |
09 Feb 06 |
nicklas |
171 |
if (group == null) |
502 |
02 May 05 |
nicklas |
172 |
{ |
1959 |
09 Feb 06 |
nicklas |
173 |
group = Group.getNew(dc); |
1959 |
09 Feb 06 |
nicklas |
174 |
message = "Group created"; |
1959 |
09 Feb 06 |
nicklas |
175 |
dc.saveItem(group); |
502 |
02 May 05 |
nicklas |
176 |
} |
1959 |
09 Feb 06 |
nicklas |
177 |
else |
502 |
02 May 05 |
nicklas |
178 |
{ |
5060 |
19 Aug 09 |
nicklas |
179 |
dc.reattachItem(group, false); |
1959 |
09 Feb 06 |
nicklas |
180 |
message = "Group updated"; |
502 |
02 May 05 |
nicklas |
181 |
} |
5506 |
19 Nov 10 |
nicklas |
182 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(Item.GROUP), group); |
7604 |
25 Feb 19 |
nicklas |
183 |
ExtensionsInvoker<OnSaveAction> invoker = EditUtil.useOnSaveExtensions(jspContext); |
5506 |
19 Nov 10 |
nicklas |
184 |
try |
502 |
02 May 05 |
nicklas |
185 |
{ |
5506 |
19 Nov 10 |
nicklas |
186 |
group.setName(Values.getStringOrNull(request.getParameter("name"))); |
5506 |
19 Nov 10 |
nicklas |
187 |
group.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
5506 |
19 Nov 10 |
nicklas |
188 |
group.setDefault(Values.getBoolean(request.getParameter("is_default"), false)); |
5506 |
19 Nov 10 |
nicklas |
189 |
group.setHiddenMembers(Values.getBoolean(request.getParameter("hidden_members"), false)); |
5506 |
19 Nov 10 |
nicklas |
190 |
int quotaId = Values.getInt(request.getParameter("quota_id"), -1); |
5506 |
19 Nov 10 |
nicklas |
191 |
if (quotaId >= 0) // < 0 = denied or unchanged |
5506 |
19 Nov 10 |
nicklas |
192 |
{ |
5506 |
19 Nov 10 |
nicklas |
193 |
group.setQuota(quotaId == 0 ? null : Quota.getById(dc, quotaId)); |
5506 |
19 Nov 10 |
nicklas |
194 |
} |
5506 |
19 Nov 10 |
nicklas |
195 |
|
6291 |
11 Jun 13 |
nicklas |
196 |
String[] removeUsers = Values.getString(request.getParameter("-USER")).split(","); |
5506 |
19 Nov 10 |
nicklas |
197 |
for (int i = 0; i < removeUsers.length; ++i) |
5506 |
19 Nov 10 |
nicklas |
198 |
{ |
5506 |
19 Nov 10 |
nicklas |
199 |
int userId = Values.getInt(removeUsers[i], -1); |
5506 |
19 Nov 10 |
nicklas |
200 |
if (userId != -1) group.removeUser(User.getById(dc, userId)); |
5506 |
19 Nov 10 |
nicklas |
201 |
} |
5506 |
19 Nov 10 |
nicklas |
202 |
|
6291 |
11 Jun 13 |
nicklas |
203 |
String[] addUsers = Values.getString(request.getParameter("+USER")).split(","); |
5506 |
19 Nov 10 |
nicklas |
204 |
for (int i = 0; i < addUsers.length; ++i) |
5506 |
19 Nov 10 |
nicklas |
205 |
{ |
5506 |
19 Nov 10 |
nicklas |
206 |
int userId = Values.getInt(addUsers[i], -1); |
5506 |
19 Nov 10 |
nicklas |
207 |
if (userId != -1) group.addUser(User.getById(dc, userId)); |
5506 |
19 Nov 10 |
nicklas |
208 |
} |
5506 |
19 Nov 10 |
nicklas |
209 |
|
6291 |
11 Jun 13 |
nicklas |
210 |
String[] removeGroups = Values.getString(request.getParameter("-GROUP")).split(","); |
5506 |
19 Nov 10 |
nicklas |
211 |
for (int i = 0; i < removeGroups.length; ++i) |
5506 |
19 Nov 10 |
nicklas |
212 |
{ |
5506 |
19 Nov 10 |
nicklas |
213 |
int groupId = Values.getInt(removeGroups[i], -1); |
5506 |
19 Nov 10 |
nicklas |
214 |
if (groupId != -1) group.removeGroup(Group.getById(dc, groupId)); |
5506 |
19 Nov 10 |
nicklas |
215 |
} |
5506 |
19 Nov 10 |
nicklas |
216 |
|
6291 |
11 Jun 13 |
nicklas |
217 |
String[] addGroups = Values.getString(request.getParameter("+GROUP")).split(","); |
5506 |
19 Nov 10 |
nicklas |
218 |
for (int i = 0; i < addGroups.length; ++i) |
5506 |
19 Nov 10 |
nicklas |
219 |
{ |
5506 |
19 Nov 10 |
nicklas |
220 |
int groupId = Values.getInt(addGroups[i], -1); |
5506 |
19 Nov 10 |
nicklas |
221 |
if (groupId != -1) group.addGroup(Group.getById(dc, groupId)); |
5506 |
19 Nov 10 |
nicklas |
222 |
} |
5506 |
19 Nov 10 |
nicklas |
223 |
|
5506 |
19 Nov 10 |
nicklas |
224 |
// OnSave extensions |
5506 |
19 Nov 10 |
nicklas |
225 |
invoker.render(OnSaveRenderer.ON_SAVE); |
5506 |
19 Nov 10 |
nicklas |
226 |
dc.commit(); |
5506 |
19 Nov 10 |
nicklas |
227 |
invoker.render(OnSaveRenderer.ON_COMMIT); |
502 |
02 May 05 |
nicklas |
228 |
} |
5506 |
19 Nov 10 |
nicklas |
229 |
catch (Exception ex) |
502 |
02 May 05 |
nicklas |
230 |
{ |
5506 |
19 Nov 10 |
nicklas |
231 |
invoker.render(OnSaveRenderer.onRollback(ex)); |
5506 |
19 Nov 10 |
nicklas |
232 |
throw ex; |
502 |
02 May 05 |
nicklas |
233 |
} |
5506 |
19 Nov 10 |
nicklas |
234 |
finally |
502 |
02 May 05 |
nicklas |
235 |
{ |
5506 |
19 Nov 10 |
nicklas |
236 |
cc.removeObject("item"); |
502 |
02 May 05 |
nicklas |
237 |
} |
1959 |
09 Feb 06 |
nicklas |
238 |
} |
1959 |
09 Feb 06 |
nicklas |
239 |
else if ("DeleteItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
240 |
{ |
1959 |
09 Feb 06 |
nicklas |
241 |
// Delete a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
242 |
dc = sc.newDbControl(":Delete "+itemType); |
1959 |
09 Feb 06 |
nicklas |
243 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
244 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true); |
1959 |
09 Feb 06 |
nicklas |
245 |
dc.commit(); |
1959 |
09 Feb 06 |
nicklas |
246 |
redirect = viewPage; |
1959 |
09 Feb 06 |
nicklas |
247 |
} |
1959 |
09 Feb 06 |
nicklas |
248 |
else if ("DeleteItems".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
249 |
{ |
1959 |
09 Feb 06 |
nicklas |
250 |
// Delete all selected items on the list page |
7954 |
12 May 21 |
nicklas |
251 |
dc = sc.newDbControl(":Delete "+itemType); |
1959 |
09 Feb 06 |
nicklas |
252 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
253 |
int numTotal = cc.getSelected().size(); |
1959 |
09 Feb 06 |
nicklas |
254 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true); |
1959 |
09 Feb 06 |
nicklas |
255 |
dc.commit(); |
1959 |
09 Feb 06 |
nicklas |
256 |
if (numTotal != numRemoved) |
1959 |
09 Feb 06 |
nicklas |
257 |
{ |
1959 |
09 Feb 06 |
nicklas |
258 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission"; |
1959 |
09 Feb 06 |
nicklas |
259 |
} |
6192 |
31 Oct 12 |
nicklas |
260 |
redirect = listPage; |
1959 |
09 Feb 06 |
nicklas |
261 |
} |
1959 |
09 Feb 06 |
nicklas |
262 |
else if ("RestoreItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
263 |
{ |
1959 |
09 Feb 06 |
nicklas |
264 |
// Restore a single item and then return to the view page |
7954 |
12 May 21 |
nicklas |
265 |
dc = sc.newDbControl(":Restore "+itemType); |
1959 |
09 Feb 06 |
nicklas |
266 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
267 |
RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false); |
1959 |
09 Feb 06 |
nicklas |
268 |
dc.commit(); |
1959 |
09 Feb 06 |
nicklas |
269 |
redirect = viewPage; |
1959 |
09 Feb 06 |
nicklas |
270 |
} |
1959 |
09 Feb 06 |
nicklas |
271 |
else if ("RestoreItems".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
272 |
{ |
1959 |
09 Feb 06 |
nicklas |
273 |
// Restore all selected items on the list page |
7954 |
12 May 21 |
nicklas |
274 |
dc = sc.newDbControl(":Restore "+itemType); |
1959 |
09 Feb 06 |
nicklas |
275 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
276 |
int numTotal = cc.getSelected().size(); |
1959 |
09 Feb 06 |
nicklas |
277 |
int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); |
1959 |
09 Feb 06 |
nicklas |
278 |
dc.commit(); |
1959 |
09 Feb 06 |
nicklas |
279 |
if (numTotal != numRemoved) |
1959 |
09 Feb 06 |
nicklas |
280 |
{ |
2528 |
15 Aug 06 |
martin |
281 |
message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; |
1959 |
09 Feb 06 |
nicklas |
282 |
} |
6192 |
31 Oct 12 |
nicklas |
283 |
redirect = listPage; |
1959 |
09 Feb 06 |
nicklas |
284 |
} |
1959 |
09 Feb 06 |
nicklas |
285 |
else if ("ExportItems".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
286 |
{ |
1959 |
09 Feb 06 |
nicklas |
287 |
// Run an export plugin in a list context |
1959 |
09 Feb 06 |
nicklas |
288 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
289 |
final ItemQuery<Group> query = Group.getQuery(); |
7954 |
12 May 21 |
nicklas |
290 |
dc = sc.newDbControl(":Export "+itemType); |
7914 |
23 Feb 21 |
nicklas |
291 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
292 |
cc.configureQuery(dc, query, jspContext, true); |
1959 |
09 Feb 06 |
nicklas |
293 |
cc.setQuery(query); |
4906 |
24 Apr 09 |
martin |
294 |
registerExportUtils(cc); |
7604 |
25 Feb 19 |
nicklas |
295 |
ExtensionsInvoker<ListColumnAction<Group,?>> listInvoker = ListColumnUtil.useExtensions(jspContext); |
7604 |
25 Feb 19 |
nicklas |
296 |
listInvoker.render(new ListColumnExportRenderer<Group>(cc)); |
6045 |
03 Apr 12 |
nicklas |
297 |
dc.close(); |
1959 |
09 Feb 06 |
nicklas |
298 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+groups"; |
1959 |
09 Feb 06 |
nicklas |
299 |
} |
1959 |
09 Feb 06 |
nicklas |
300 |
else if ("ExportItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
301 |
{ |
1959 |
09 Feb 06 |
nicklas |
302 |
// Run an export plugin in single-item context |
1959 |
09 Feb 06 |
nicklas |
303 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
4906 |
24 Apr 09 |
martin |
304 |
registerExportUtils(cc); |
1959 |
09 Feb 06 |
nicklas |
305 |
redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+group"; |
1959 |
09 Feb 06 |
nicklas |
306 |
} |
1959 |
09 Feb 06 |
nicklas |
307 |
else if ("ImportItems".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
308 |
{ |
1959 |
09 Feb 06 |
nicklas |
309 |
// Run an import plugin in a list context |
1959 |
09 Feb 06 |
nicklas |
310 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
311 |
final ItemQuery<Group> query = Group.getQuery(); |
7954 |
12 May 21 |
nicklas |
312 |
dc = sc.newDbControl(":Import "+itemType); |
7914 |
23 Feb 21 |
nicklas |
313 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
314 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
315 |
dc.close(); |
1959 |
09 Feb 06 |
nicklas |
316 |
cc.setQuery(query); |
1959 |
09 Feb 06 |
nicklas |
317 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+groups"; |
1959 |
09 Feb 06 |
nicklas |
318 |
} |
1959 |
09 Feb 06 |
nicklas |
319 |
else if ("ImportItem".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
320 |
{ |
1959 |
09 Feb 06 |
nicklas |
321 |
// Run an import plugin in single-item context |
1959 |
09 Feb 06 |
nicklas |
322 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
323 |
redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+group"; |
1959 |
09 Feb 06 |
nicklas |
324 |
} |
1959 |
09 Feb 06 |
nicklas |
325 |
else if ("RunListPlugin".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
326 |
{ |
1959 |
09 Feb 06 |
nicklas |
327 |
// Run another plugin in a list context |
1959 |
09 Feb 06 |
nicklas |
328 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
329 |
final ItemQuery<Group> query = Group.getQuery(); |
7954 |
12 May 21 |
nicklas |
330 |
dc = sc.newDbControl(":Run plugin "+itemType); |
7914 |
23 Feb 21 |
nicklas |
331 |
JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null); |
7914 |
23 Feb 21 |
nicklas |
332 |
cc.configureQuery(dc, query, jspContext, true); |
5590 |
16 Mar 11 |
nicklas |
333 |
dc.close(); |
1959 |
09 Feb 06 |
nicklas |
334 |
cc.setQuery(query); |
1959 |
09 Feb 06 |
nicklas |
335 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin"; |
1959 |
09 Feb 06 |
nicklas |
336 |
} |
1959 |
09 Feb 06 |
nicklas |
337 |
else if ("RunPlugin".equals(cmd)) |
1959 |
09 Feb 06 |
nicklas |
338 |
{ |
1959 |
09 Feb 06 |
nicklas |
339 |
// Run another plugin in single-item context |
1959 |
09 Feb 06 |
nicklas |
340 |
ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); |
1959 |
09 Feb 06 |
nicklas |
341 |
redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; |
1959 |
09 Feb 06 |
nicklas |
342 |
} |
1959 |
09 Feb 06 |
nicklas |
343 |
else |
1959 |
09 Feb 06 |
nicklas |
344 |
{ |
1959 |
09 Feb 06 |
nicklas |
345 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
1959 |
09 Feb 06 |
nicklas |
346 |
} |
502 |
02 May 05 |
nicklas |
347 |
} |
502 |
02 May 05 |
nicklas |
348 |
finally |
502 |
02 May 05 |
nicklas |
349 |
{ |
502 |
02 May 05 |
nicklas |
350 |
if (dc != null) dc.close(); |
502 |
02 May 05 |
nicklas |
351 |
} |
1959 |
09 Feb 06 |
nicklas |
352 |
|
1959 |
09 Feb 06 |
nicklas |
353 |
if (forward != null) |
1959 |
09 Feb 06 |
nicklas |
354 |
{ |
6192 |
31 Oct 12 |
nicklas |
355 |
sc.setSessionSetting("alert-message", message); |
1959 |
09 Feb 06 |
nicklas |
356 |
pageContext.forward(forward); |
1959 |
09 Feb 06 |
nicklas |
357 |
} |
1959 |
09 Feb 06 |
nicklas |
358 |
else if (redirect != null) |
1959 |
09 Feb 06 |
nicklas |
359 |
{ |
6192 |
31 Oct 12 |
nicklas |
360 |
sc.setSessionSetting("alert-message", message); |
1959 |
09 Feb 06 |
nicklas |
361 |
response.sendRedirect(redirect); |
1959 |
09 Feb 06 |
nicklas |
362 |
} |
1959 |
09 Feb 06 |
nicklas |
363 |
else if (message == null) |
1959 |
09 Feb 06 |
nicklas |
364 |
{ |
1959 |
09 Feb 06 |
nicklas |
365 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0"); |
1959 |
09 Feb 06 |
nicklas |
366 |
} |
1959 |
09 Feb 06 |
nicklas |
367 |
else |
1959 |
09 Feb 06 |
nicklas |
368 |
{ |
1959 |
09 Feb 06 |
nicklas |
369 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
1959 |
09 Feb 06 |
nicklas |
370 |
} |
1959 |
09 Feb 06 |
nicklas |
371 |
%> |
1959 |
09 Feb 06 |
nicklas |
372 |
|