1 | <%-- $Id: edit_reporterlist.jsp 4306 2008-05-21 13:39:59Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson |
---|
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 session="false" |
---|
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.ItemContext" |
---|
32 | import="net.sf.basedb.core.Permission" |
---|
33 | import="net.sf.basedb.core.ReporterList" |
---|
34 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
35 | import="net.sf.basedb.clients.web.Base" |
---|
36 | import="net.sf.basedb.clients.web.util.HTML" |
---|
37 | import="net.sf.basedb.util.Values" |
---|
38 | import="java.util.List" |
---|
39 | %> |
---|
40 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
41 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
42 | <% |
---|
43 | final Item itemType = Item.REPORTERLIST; |
---|
44 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
45 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
46 | final int itemId = cc.getId(); |
---|
47 | final String ID = sc.getId(); |
---|
48 | final float scale = Base.getScale(sc); |
---|
49 | final DbControl dc = sc.newDbControl(); |
---|
50 | try |
---|
51 | { |
---|
52 | String title = null; |
---|
53 | String name = null; |
---|
54 | ReporterList reporterList = null; |
---|
55 | boolean addReporters = false; |
---|
56 | boolean mergeReporterLists = false; |
---|
57 | int numSelectedLists = cc.getSelected().size(); |
---|
58 | String formId = request.getParameter("formId"); |
---|
59 | String fromContext = Values.getString(request.getParameter("fromContext"), "REPORTER"); |
---|
60 | String subContext = request.getParameter("subContext"); |
---|
61 | |
---|
62 | if (itemId == 0) |
---|
63 | { |
---|
64 | title = "Create reporter list"; |
---|
65 | cc.removeObject("item"); |
---|
66 | addReporters = Values.getBoolean(request.getParameter("addReporters")); |
---|
67 | mergeReporterLists = !addReporters && numSelectedLists > 0; |
---|
68 | name = request.getParameter("name"); |
---|
69 | if (name == null) name = Values.getString(cc.getPropertyValue("name"), "New reporter list"); |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | reporterList = ReporterList.getById(dc, itemId); |
---|
74 | name = reporterList.getName(); |
---|
75 | cc.setObject("item", reporterList); |
---|
76 | title = "Edit reporter list -- " + HTML.encodeTags(reporterList.getName()); |
---|
77 | } |
---|
78 | if (reporterList != null) reporterList.checkPermission(Permission.WRITE); |
---|
79 | |
---|
80 | final String clazz = "class=\"text\""; |
---|
81 | final String requiredClazz = "class=\"text required\""; |
---|
82 | %> |
---|
83 | |
---|
84 | <base:page type="popup" title="<%=title%>"> |
---|
85 | <base:head scripts="tabcontrol.js" styles="tabcontrol.css"> |
---|
86 | <script language="JavaScript"> |
---|
87 | // Validate the "Reporter list" tab |
---|
88 | function validateReporterList() |
---|
89 | { |
---|
90 | var frm = document.forms['reporterList']; |
---|
91 | if (Main.trimString(frm.name.value) == '') |
---|
92 | { |
---|
93 | alert("You must enter a name"); |
---|
94 | frm.name.focus(); |
---|
95 | return false; |
---|
96 | } |
---|
97 | if (frm.minCount) |
---|
98 | { |
---|
99 | var checked = Forms.getCheckedRadio(frm.create); |
---|
100 | if (checked.value == 'count') |
---|
101 | { |
---|
102 | if (!Numbers.isInteger(frm.minCount.value)) |
---|
103 | { |
---|
104 | alert('You must specify the number of reporter lists'); |
---|
105 | frm.count.focus(); |
---|
106 | return false; |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | var minCount = parseInt(frm.minCount.value); |
---|
111 | if (minCount < 1 || minCount > <%=numSelectedLists%>) |
---|
112 | { |
---|
113 | alert('You must specify between 1 and <%=numSelectedLists%>'); |
---|
114 | frm.count.focus(); |
---|
115 | return false; |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|
120 | return true; |
---|
121 | } |
---|
122 | |
---|
123 | // Submit the form |
---|
124 | function saveSettings() |
---|
125 | { |
---|
126 | var frm = document.forms['reporterList']; |
---|
127 | if (TabControl.validateActiveTab('settings')) |
---|
128 | { |
---|
129 | if (frm.which) Forms.createHidden(frm, 'items', getSelectedItems().join(',')); |
---|
130 | frm.submit(); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | function init() |
---|
135 | { |
---|
136 | var frm = document.forms['reporterList']; |
---|
137 | <% |
---|
138 | if (reporterList == null) |
---|
139 | { |
---|
140 | %> |
---|
141 | frm.name.focus(); |
---|
142 | frm.name.select(); |
---|
143 | <% |
---|
144 | } |
---|
145 | %> |
---|
146 | if (frm.which && getSelectedItems().length == 0) |
---|
147 | { |
---|
148 | frm.which[0].disabled = true; |
---|
149 | var aSelected = document.getElementById('which.selected'); |
---|
150 | aSelected.href = 'javascript:void(0)'; |
---|
151 | aSelected.disabled = true; |
---|
152 | Main.addClass(aSelected, 'disabled'); |
---|
153 | } |
---|
154 | } |
---|
155 | // Get the ID:s of all selected reorters |
---|
156 | var selectedItems = new Array(); |
---|
157 | function getSelectedItems() |
---|
158 | { |
---|
159 | <% |
---|
160 | if (formId != null) |
---|
161 | { |
---|
162 | %> |
---|
163 | if (!selectedItems) |
---|
164 | { |
---|
165 | selectedItems = window.opener.Table.getSelected('<%=formId%>'); |
---|
166 | } |
---|
167 | <% |
---|
168 | } |
---|
169 | %> |
---|
170 | return selectedItems; |
---|
171 | } |
---|
172 | function checkRadio(radio, name) |
---|
173 | { |
---|
174 | Forms.checkRadio(radio, name); |
---|
175 | } |
---|
176 | </script> |
---|
177 | </base:head> |
---|
178 | <base:body onload="init()"> |
---|
179 | <p> |
---|
180 | <form action="index.jsp?ID=<%=ID%>" method="post" name="reporterList" onsubmit="return false;"> |
---|
181 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
182 | <input type="hidden" name="fromContext" value="<%=fromContext%>"> |
---|
183 | <% |
---|
184 | if (subContext != null) |
---|
185 | { |
---|
186 | %> |
---|
187 | <input type="hidden" name="subContext" value="<%=subContext%>"> |
---|
188 | <% |
---|
189 | } |
---|
190 | %> |
---|
191 | <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3> |
---|
192 | <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" |
---|
193 | position="bottom" remember="<%=reporterList != null%>"> |
---|
194 | <t:tab id="info" title="Reporter list" |
---|
195 | validate="validateReporterList()" helpid="reporterlist.edit"> |
---|
196 | <table class="form" cellspacing=0> |
---|
197 | <tr> |
---|
198 | <td class="prompt">Name</td> |
---|
199 | <td><input <%=requiredClazz%> type="text" name="name" |
---|
200 | value="<%=HTML.encodeTags(name)%>" |
---|
201 | size="40" maxlength="<%=ReporterList.MAX_NAME_LENGTH%>"></td> |
---|
202 | </tr> |
---|
203 | <tr> |
---|
204 | <td class="prompt">External ID</td> |
---|
205 | <td><input <%=clazz%> type="text" name="external_id" |
---|
206 | value="<%=HTML.encodeTags(reporterList == null ? Values.getString(cc.getPropertyValue("externalId")) : reporterList.getExternalId())%>" |
---|
207 | size="40" maxlength="<%=ReporterList.MAX_EXTERNAL_ID_LENGTH%>"></td> |
---|
208 | </tr> |
---|
209 | <% |
---|
210 | if (addReporters) |
---|
211 | { |
---|
212 | %> |
---|
213 | <tr valign="top"> |
---|
214 | <td class="prompt">Which reporters?</td> |
---|
215 | <td> |
---|
216 | <input type="radio" name="which" value="selected"><a |
---|
217 | id="which.selected" |
---|
218 | href="javascript:checkRadio(document.forms['reporterList'].which, 'selected');" |
---|
219 | >Selected items</a><br> |
---|
220 | <input type="radio" name="which" value="page"><a |
---|
221 | href="javascript:checkRadio(document.forms['reporterList'].which, 'page');" |
---|
222 | >Current page</a><br> |
---|
223 | <input type="radio" name="which" value="all" checked><a |
---|
224 | href="javascript:checkRadio(document.forms['reporterList'].which, 'all');" |
---|
225 | >All pages</a><br> |
---|
226 | </td> |
---|
227 | </tr> |
---|
228 | <% |
---|
229 | } |
---|
230 | else if (mergeReporterLists) |
---|
231 | { |
---|
232 | %> |
---|
233 | <tr valign="top"> |
---|
234 | <td class="prompt">Add reporters?</td> |
---|
235 | <td> |
---|
236 | <input type="radio" name="create" value=""><a |
---|
237 | href="javascript:checkRadio(document.forms['reporterList'].create, '');" |
---|
238 | title="The new reporter list will be empty" |
---|
239 | >No</a><br> |
---|
240 | <input type="radio" name="create" value="union" checked><a |
---|
241 | href="javascript:checkRadio(document.forms['reporterList'].create, 'union');" |
---|
242 | title="The new reporter list contains all reporters from the selected lists" |
---|
243 | >Union of selected lists</a> <base:icon image="set_operations/union_small.png" /><br> |
---|
244 | <input type="radio" name="create" value="intersection"><a |
---|
245 | href="javascript:checkRadio(document.forms['reporterList'].create, 'intersection');" |
---|
246 | title="The new reporter lists contains only reporters that are present in ALL selected lists" |
---|
247 | >Intersection of selected lists</a> <base:icon image="set_operations/intersection_small.png" /><br> |
---|
248 | <input type="radio" name="create" value="count"><a |
---|
249 | href="javascript:checkRadio(document.forms['reporterList'].create, 'count');" |
---|
250 | title="The new reporter lists contains only reporters that are present in some of selected lists" |
---|
251 | >Present in at least</a> |
---|
252 | <input type="text" class="text" name="minCount" size="2" maxlength="2" |
---|
253 | value="1" |
---|
254 | onkeypress="return Numbers.integerOnly(event)" |
---|
255 | onfocus="checkRadio(document.forms['reporterList'].create, 'count');"> |
---|
256 | of the selected lists (1-<%=numSelectedLists%>). |
---|
257 | <br> |
---|
258 | |
---|
259 | </td> |
---|
260 | </tr> |
---|
261 | <% |
---|
262 | } |
---|
263 | %> |
---|
264 | <tr valign=top> |
---|
265 | <td class="prompt">Description</td> |
---|
266 | <td nowrap> |
---|
267 | <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual" |
---|
268 | ><%=HTML.encodeTags(reporterList == null ? cc.getPropertyValue("description") : reporterList.getDescription())%></textarea> |
---|
269 | <a href="javascript:Main.zoom('Description', 'reporterList', 'description')" |
---|
270 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
271 | </td> |
---|
272 | </tr> |
---|
273 | </table> |
---|
274 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
275 | </t:tab> |
---|
276 | </t:tabcontrol> |
---|
277 | |
---|
278 | <table align="center"> |
---|
279 | <tr> |
---|
280 | <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td> |
---|
281 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
282 | </tr> |
---|
283 | </table> |
---|
284 | </form> |
---|
285 | </base:body> |
---|
286 | </base:page> |
---|
287 | <% |
---|
288 | } |
---|
289 | finally |
---|
290 | { |
---|
291 | if (dc != null) dc.close(); |
---|
292 | } |
---|
293 | %> |
---|