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