1 | <%-- $Id:edit_variant.jsp 3820 2007-10-12 10:03:18Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
---|
5 | |
---|
6 | This file is part of BASE - BioArray Software Environment. |
---|
7 | Available at http://base.thep.lu.se/ |
---|
8 | |
---|
9 | BASE is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 3 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | BASE is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | ------------------------------------------------------------------ |
---|
22 | |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page pageEncoding="UTF-8" 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.Include" |
---|
33 | import="net.sf.basedb.core.Permission" |
---|
34 | import="net.sf.basedb.core.Platform" |
---|
35 | import="net.sf.basedb.core.PlatformVariant" |
---|
36 | import="net.sf.basedb.core.PlatformFileType" |
---|
37 | import="net.sf.basedb.core.DataFileType" |
---|
38 | import="net.sf.basedb.core.RawDataType" |
---|
39 | import="net.sf.basedb.core.RawDataTypes" |
---|
40 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
41 | import="net.sf.basedb.core.ItemQuery" |
---|
42 | import="net.sf.basedb.core.ItemResultList" |
---|
43 | import="net.sf.basedb.core.query.Orders" |
---|
44 | import="net.sf.basedb.core.query.Hql" |
---|
45 | import="net.sf.basedb.clients.web.Base" |
---|
46 | import="net.sf.basedb.clients.web.util.HTML" |
---|
47 | import="net.sf.basedb.util.Values" |
---|
48 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
49 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
50 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
51 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
52 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
53 | %> |
---|
54 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
55 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
56 | <% |
---|
57 | final int platformId = Values.getInt(request.getParameter("platform_id")); |
---|
58 | final Item itemType = Item.PLATFORMVARIANT; |
---|
59 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
60 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
61 | final String tabId = Values.getString(request.getParameter("tab"), null); |
---|
62 | final int itemId = cc.getId(); |
---|
63 | final String ID = sc.getId(); |
---|
64 | final float scale = Base.getScale(sc); |
---|
65 | final DbControl dc = sc.newDbControl(); |
---|
66 | try |
---|
67 | { |
---|
68 | String title = null; |
---|
69 | Platform platform = null; |
---|
70 | PlatformVariant variant = null; |
---|
71 | boolean isFileOnly = false; |
---|
72 | ItemQuery<PlatformFileType> fileTypeQuery = null; |
---|
73 | |
---|
74 | if (itemId == 0) |
---|
75 | { |
---|
76 | title = "Create platform variant"; |
---|
77 | platform = Platform.getById(dc, platformId); |
---|
78 | isFileOnly = Values.getBoolean(cc.getPropertyValue("fileOnly"), platform.isFileOnly()); |
---|
79 | cc.removeObject("item"); |
---|
80 | platform.checkPermission(Permission.WRITE); |
---|
81 | } |
---|
82 | else |
---|
83 | { |
---|
84 | variant = PlatformVariant.getById(dc, itemId); |
---|
85 | platform = variant.getPlatform(); |
---|
86 | isFileOnly = variant.isFileOnly(); |
---|
87 | cc.setObject("item", variant); |
---|
88 | title = "Edit platform variant -- " + HTML.encodeTags(variant.getName()); |
---|
89 | variant.checkPermission(Permission.WRITE); |
---|
90 | fileTypeQuery = platform.getFileTypes(variant, true); |
---|
91 | fileTypeQuery.include(Include.ALL); |
---|
92 | fileTypeQuery.order(Orders.asc(Hql.property("dataFileType.name"))); |
---|
93 | } |
---|
94 | |
---|
95 | final String clazz = "class=\"text\""; |
---|
96 | final String requiredClazz = "class=\"text required\""; |
---|
97 | final String unchangeableClazz = "class=\"text required unchangeable\""; |
---|
98 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), variant); |
---|
99 | ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext); |
---|
100 | %> |
---|
101 | <base:page type="popup" title="<%=title%>"> |
---|
102 | <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css"> |
---|
103 | <ext:scripts context="<%=jspContext%>" /> |
---|
104 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
105 | <script language="JavaScript"> |
---|
106 | // Validate the "Variant" tab |
---|
107 | function validateVariant() |
---|
108 | { |
---|
109 | var frm = document.forms['variant']; |
---|
110 | if (Main.trimString(frm.name.value) == '') |
---|
111 | { |
---|
112 | alert("You must enter a name"); |
---|
113 | frm.name.focus(); |
---|
114 | return false; |
---|
115 | } |
---|
116 | if (frm.externalId) |
---|
117 | { |
---|
118 | var fileOnly = Forms.getCheckedRadio(frm.fileOnly).value == '1'; |
---|
119 | if (Main.trimString(frm.externalId.value) == '') |
---|
120 | { |
---|
121 | alert("You must enter an external ID"); |
---|
122 | frm.externalId.focus(); |
---|
123 | return false; |
---|
124 | } |
---|
125 | else if (fileOnly) |
---|
126 | { |
---|
127 | if (!Numbers.isInteger(frm.channels.value)) |
---|
128 | { |
---|
129 | alert("You must enter the number of channels"); |
---|
130 | frm.channels.focus(); |
---|
131 | return false; |
---|
132 | } |
---|
133 | if (parseInt(frm.channels.value) <= 0) |
---|
134 | { |
---|
135 | alert("The number of channels must be > 0"); |
---|
136 | frm.channels.focus(); |
---|
137 | return false; |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|
141 | return true; |
---|
142 | } |
---|
143 | |
---|
144 | // Submit the form |
---|
145 | function saveSettings() |
---|
146 | { |
---|
147 | var frm = document.forms['variant']; |
---|
148 | if (TabControl.validateActiveTab('settings')) |
---|
149 | { |
---|
150 | frm.modifiedFileTypes.value = Link.exportModified(frm, 'F', true).join(','); |
---|
151 | frm.removedFileTypes.value = Link.getActionIds(-1, 'F').join(','); |
---|
152 | frm.submit(); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | function init() |
---|
157 | { |
---|
158 | <% |
---|
159 | if (variant == null) |
---|
160 | { |
---|
161 | %> |
---|
162 | var frm = document.forms['variant']; |
---|
163 | frm.name.focus(); |
---|
164 | frm.name.select(); |
---|
165 | fileOnlyOnClick(); |
---|
166 | <% |
---|
167 | } |
---|
168 | %> |
---|
169 | initFileTypes(); |
---|
170 | } |
---|
171 | function fileOnlyOnClick() |
---|
172 | { |
---|
173 | var frm = document.forms['variant']; |
---|
174 | var fileOnly = Forms.getCheckedRadio(frm.fileOnly).value == '1'; |
---|
175 | frm.rawdatatype.disabled = fileOnly; |
---|
176 | frm.channels.disabled = !fileOnly; |
---|
177 | Main.addOrRemoveClass(frm.rawdatatype, 'required', !frm.rawdatatype.disabled); |
---|
178 | Main.addOrRemoveClass(frm.channels, 'required', !frm.channels.disabled); |
---|
179 | } |
---|
180 | function initFileTypes() |
---|
181 | { |
---|
182 | var fileTypes = document.forms['variant'].fileTypes; |
---|
183 | <% |
---|
184 | if (fileTypeQuery != null) |
---|
185 | { |
---|
186 | ItemResultList<PlatformFileType> fileTypes = fileTypeQuery.list(dc); |
---|
187 | for (PlatformFileType ft : fileTypes) |
---|
188 | { |
---|
189 | DataFileType dft = ft.getDataFileType(); |
---|
190 | boolean required = ft.isRequired(); |
---|
191 | boolean multiple = ft.getAllowMultiple(); |
---|
192 | int value = 0; |
---|
193 | if (required) value += 1; |
---|
194 | if (multiple) value += 2; |
---|
195 | %> |
---|
196 | Link.addNewItem(fileTypes, new Item('F', <%=dft.getId()%>, '<%=HTML.javaScriptEncode(dft.getName())%> <%=required ? "[×]" : "[-]"%>', <%=value%>)); |
---|
197 | <% |
---|
198 | } |
---|
199 | } |
---|
200 | %> |
---|
201 | } |
---|
202 | function addFileTypesOnClick() |
---|
203 | { |
---|
204 | var frm = document.forms['variant']; |
---|
205 | Main.openPopup('../../datafiletypes/index.jsp?ID=<%=ID%>&mode=selectmultiple&callback=addFileTypeCallback', 'AddFileTypes', 1000, 700); |
---|
206 | } |
---|
207 | function addFileTypeCallback(fileTypeId, name) |
---|
208 | { |
---|
209 | var item = Link.getItem('F', fileTypeId); |
---|
210 | var frm = document.forms['variant']; |
---|
211 | var required = frm.required.checked; |
---|
212 | var multiple = frm.multiple.checked; |
---|
213 | var newValue = 0; |
---|
214 | if (required) newValue += 1; |
---|
215 | if (multiple) newValue += 2; |
---|
216 | if (!item) item = new Item('F', fileTypeId, name+(required ? '[×]' : '[-]'), newValue, ''); |
---|
217 | Link.addItem(frm.fileTypes, item); |
---|
218 | } |
---|
219 | function removeOnClick() |
---|
220 | { |
---|
221 | Link.removeSelected(document.forms['variant'].fileTypes); |
---|
222 | } |
---|
223 | function fileTypesOnChange() |
---|
224 | { |
---|
225 | var frm = document.forms['variant']; |
---|
226 | var item = frm.fileTypes[frm.fileTypes.selectedIndex].item; |
---|
227 | if (item && item.id) |
---|
228 | { |
---|
229 | frm.required.checked = (item.value & 1) > 0; |
---|
230 | frm.multiple.checked = (item.value & 2) > 0; |
---|
231 | } |
---|
232 | else |
---|
233 | { |
---|
234 | frm.required.checked = false; |
---|
235 | frm.multiple.checked = false; |
---|
236 | } |
---|
237 | } |
---|
238 | function requiredOnClick() |
---|
239 | { |
---|
240 | var frm = document.forms['variant']; |
---|
241 | var required = frm.required.checked; |
---|
242 | var multiple = frm.multiple.checked; |
---|
243 | var newValue = 0; |
---|
244 | if (required) newValue += 1; |
---|
245 | if (multiple) newValue += 2; |
---|
246 | for (var i = 0; i < frm.fileTypes.length; i++) // > |
---|
247 | { |
---|
248 | var option = frm.fileTypes[i]; |
---|
249 | if (option.selected && option.item.id) |
---|
250 | { |
---|
251 | option.item.value = newValue; |
---|
252 | var text = option.text.replace(/\[.*\]/, '['+(required ? '×' : '-') +']'); |
---|
253 | option.text = text; |
---|
254 | } |
---|
255 | } |
---|
256 | } |
---|
257 | function multipleOnClick() |
---|
258 | { |
---|
259 | requiredOnClick(); |
---|
260 | } |
---|
261 | </script> |
---|
262 | </base:head> |
---|
263 | <base:body onload="init()"> |
---|
264 | <p> |
---|
265 | <form action="index.jsp?ID=<%=ID%>" method="post" name="variant" onsubmit="return false;"> |
---|
266 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
267 | <input type="hidden" name="platform_id" value="<%=platformId%>"> |
---|
268 | |
---|
269 | <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3> |
---|
270 | <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" |
---|
271 | position="bottom" active="<%=tabId%>" remember="<%=tabId == null && variant != null%>" |
---|
272 | extensions="<%=invoker%>"> |
---|
273 | <t:tab id="info" title="Variant" validate="validateVariant()" helpid="platformvariant.edit"> |
---|
274 | <table class="form" cellspacing="0"> |
---|
275 | <tr> |
---|
276 | <td class="prompt">Name</td> |
---|
277 | <td><input <%=requiredClazz%> type="text" name="name" |
---|
278 | value="<%=HTML.encodeTags(variant == null ? |
---|
279 | Values.getString(cc.getPropertyValue("name"), "New " + platform.getName() + " variant") : |
---|
280 | variant.getName())%>" |
---|
281 | size="40" maxlength="<%=PlatformVariant.MAX_NAME_LENGTH%>"></td> |
---|
282 | </tr> |
---|
283 | <% |
---|
284 | if (variant == null) |
---|
285 | { |
---|
286 | // For new platforms only |
---|
287 | RawDataType currentRawDataType = |
---|
288 | RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType")); |
---|
289 | if (currentRawDataType == null) |
---|
290 | { |
---|
291 | currentRawDataType = platform.getRawDataType(); |
---|
292 | } |
---|
293 | %> |
---|
294 | <tr> |
---|
295 | <td class="prompt">External ID</td> |
---|
296 | <td><input <%=unchangeableClazz%> type="text" name="externalId" |
---|
297 | value="<%=HTML.encodeTags(Values.getString(cc.getPropertyValue("externalId"), platform.getExternalId() + ".new"))%>" |
---|
298 | size="40" maxlength="<%=PlatformVariant.MAX_EXTERNAL_ID_LENGTH%>"></td> |
---|
299 | </tr> |
---|
300 | <tr> |
---|
301 | <td class="prompt">File-only</td> |
---|
302 | <td> |
---|
303 | <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="0" <%=!isFileOnly ? "checked" : ""%> |
---|
304 | onclick="fileOnlyOnClick()">no |
---|
305 | <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="1" <%=isFileOnly ? "checked" : ""%> |
---|
306 | onclick="fileOnlyOnClick()">yes |
---|
307 | </td> |
---|
308 | </tr> |
---|
309 | |
---|
310 | <tr> |
---|
311 | <td class="prompt">Raw data type</td> |
---|
312 | <td> |
---|
313 | <select name="rawdatatype" <%=unchangeableClazz%>> |
---|
314 | <option value="">- any - |
---|
315 | <% |
---|
316 | for (RawDataType rdt : RawDataTypes.getSortedRawDataTypes(new RawDataTypes.NameComparator())) |
---|
317 | { |
---|
318 | if (rdt.isStoredInDb()) |
---|
319 | { |
---|
320 | String selected = rdt.equals(currentRawDataType) ? "selected" : ""; |
---|
321 | %> |
---|
322 | <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%> |
---|
323 | <% |
---|
324 | } |
---|
325 | } |
---|
326 | %> |
---|
327 | </select> |
---|
328 | </td> |
---|
329 | </tr> |
---|
330 | <tr> |
---|
331 | <td class="prompt">Channels</td> |
---|
332 | <td><input <%=unchangeableClazz%> type="text" name="channels" |
---|
333 | value="<%=Values.getInt(cc.getPropertyValue("channels"), currentRawDataType == null ? 1 : currentRawDataType.getChannels())%>" |
---|
334 | size="12" maxlength="10" |
---|
335 | onkeypress="return Numbers.integerOnly(event)"></td> |
---|
336 | </tr> |
---|
337 | <% |
---|
338 | } |
---|
339 | %> |
---|
340 | <tr valign=top> |
---|
341 | <td class="prompt">Description</td> |
---|
342 | <td nowrap> |
---|
343 | <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual" |
---|
344 | ><%=HTML.encodeTags(variant == null ? cc.getPropertyValue("description") : variant.getDescription())%></textarea> |
---|
345 | <a href="javascript:Main.zoom('Description', 'variant', 'description')" |
---|
346 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
347 | </td> |
---|
348 | </tr> |
---|
349 | </table> |
---|
350 | <div align=right> |
---|
351 | <i><base:icon image="required.gif" /> = required information</i> |
---|
352 | <%if (variant == null) {%><br> |
---|
353 | <i><base:icon image="unchangeable.gif" /> = can't be changed later</i> |
---|
354 | <%}%> |
---|
355 | </div> |
---|
356 | </t:tab> |
---|
357 | <t:tab id="fileTypes" title="Data file types" |
---|
358 | tooltip="Associate this platform variant with date file types" |
---|
359 | helpid="platformvariant.edit.filetypes" |
---|
360 | > |
---|
361 | <table > |
---|
362 | <tr valign="top"> |
---|
363 | <td> |
---|
364 | <b>Data file types</b><br> |
---|
365 | <select name="fileTypes" size="10" multiple style="width: 20em;" |
---|
366 | onchange="fileTypesOnChange()"> |
---|
367 | </select> |
---|
368 | <input type="hidden" name="modifiedFileTypes" value=""> |
---|
369 | <input type="hidden" name="removedFileTypes" value=""> |
---|
370 | </td> |
---|
371 | <td> |
---|
372 | <br> |
---|
373 | <table width="150"> |
---|
374 | <tr><td width="150"><base:button |
---|
375 | clazz="leftaligned buttonclass" |
---|
376 | onclick="addFileTypesOnClick()" |
---|
377 | title="Add data file types…" |
---|
378 | tooltip="Add more data file types to this platform variant" |
---|
379 | /></td></tr> |
---|
380 | <tr><td width="150"><base:button |
---|
381 | clazz="leftaligned buttonclass" |
---|
382 | onclick="removeOnClick()" |
---|
383 | title="Remove" |
---|
384 | tooltip="Remove the selected data file types" |
---|
385 | /></td></tr> |
---|
386 | </table> |
---|
387 | <input type="checkbox" id="required" name="required" value="1" onchange="requiredOnClick()"> |
---|
388 | <label for="required">Required</label><br> |
---|
389 | <input type="checkbox" id="multiple" name="multiple" value="1" onchange="multipleOnClick()"> |
---|
390 | <label for="multiple">Allow multiple files</label> |
---|
391 | </td> |
---|
392 | </tr> |
---|
393 | </table> |
---|
394 | </t:tab> |
---|
395 | </t:tabcontrol> |
---|
396 | |
---|
397 | <table align="center"> |
---|
398 | <tr> |
---|
399 | <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td> |
---|
400 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
401 | </tr> |
---|
402 | </table> |
---|
403 | </form> |
---|
404 | </base:body> |
---|
405 | </base:page> |
---|
406 | <% |
---|
407 | } |
---|
408 | finally |
---|
409 | { |
---|
410 | if (dc != null) dc.close(); |
---|
411 | } |
---|
412 | %> |
---|