1 | <%-- $Id: edit_batch.jsp 6217 2012-12-14 13:05:00Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2006 Jari Häkkinen, 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 3 |
---|
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 BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | ------------------------------------------------------------------ |
---|
21 | |
---|
22 | |
---|
23 | @author Nicklas |
---|
24 | @version 2.0 |
---|
25 | --%> |
---|
26 | <%@ page pageEncoding="UTF-8" session="false" |
---|
27 | import="net.sf.basedb.core.SessionControl" |
---|
28 | import="net.sf.basedb.core.DbControl" |
---|
29 | import="net.sf.basedb.core.Item" |
---|
30 | import="net.sf.basedb.core.ItemContext" |
---|
31 | import="net.sf.basedb.core.SystemItems" |
---|
32 | import="net.sf.basedb.core.Permission" |
---|
33 | import="net.sf.basedb.core.Include" |
---|
34 | import="net.sf.basedb.core.ArrayBatch" |
---|
35 | import="net.sf.basedb.core.ArrayDesign" |
---|
36 | import="net.sf.basedb.core.Protocol" |
---|
37 | import="net.sf.basedb.core.ItemSubtype" |
---|
38 | import="net.sf.basedb.core.Project" |
---|
39 | import="net.sf.basedb.core.Hardware" |
---|
40 | import="net.sf.basedb.core.ItemQuery" |
---|
41 | import="net.sf.basedb.core.ItemResultList" |
---|
42 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
43 | import="net.sf.basedb.core.BaseException" |
---|
44 | import="net.sf.basedb.core.query.Orders" |
---|
45 | import="net.sf.basedb.core.query.Hql" |
---|
46 | import="net.sf.basedb.clients.web.Base" |
---|
47 | import="net.sf.basedb.clients.web.util.HTML" |
---|
48 | import="net.sf.basedb.util.Values" |
---|
49 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
50 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
51 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
52 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
53 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
54 | import="java.util.List" |
---|
55 | import="java.util.Set" |
---|
56 | import="java.util.HashSet" |
---|
57 | import="java.util.Date" |
---|
58 | %> |
---|
59 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
60 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
61 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
62 | <% |
---|
63 | final Item itemType = Item.ARRAYBATCH; |
---|
64 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
65 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
66 | final int itemId = cc.getId(); |
---|
67 | final String ID = sc.getId(); |
---|
68 | final float scale = Base.getScale(sc); |
---|
69 | final DbControl dc = sc.newDbControl(); |
---|
70 | try |
---|
71 | { |
---|
72 | String title = null; |
---|
73 | ArrayBatch batch = null; |
---|
74 | |
---|
75 | boolean readCurrentArrayDesign = true; |
---|
76 | ArrayDesign currentArrayDesign = null; |
---|
77 | List<ArrayDesign> defaultArrayDesigns = null; |
---|
78 | boolean readCurrentProtocol = true; |
---|
79 | Protocol currentProtocol = null; |
---|
80 | List<Protocol> defaultProtocols = null; |
---|
81 | boolean readCurrentPrintRobot = true; |
---|
82 | Hardware currentPrintRobot = null; |
---|
83 | List<Hardware> defaultPrintRobots = null; |
---|
84 | |
---|
85 | // Load recently used items |
---|
86 | List<ArrayDesign> recentArrayDesigns = (List<ArrayDesign>)cc.getRecent(dc, Item.ARRAYDESIGN); |
---|
87 | List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL); |
---|
88 | List<Hardware> recentPrintRobots = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE); |
---|
89 | |
---|
90 | int activeProjectId = sc.getActiveProjectId(); |
---|
91 | if (activeProjectId > 0) |
---|
92 | { |
---|
93 | Project activeProject = Project.getById(dc, activeProjectId); |
---|
94 | try |
---|
95 | { |
---|
96 | defaultArrayDesigns = (List<ArrayDesign>)activeProject.findDefaultItems(dc, Item.ARRAYDESIGN, true); |
---|
97 | } |
---|
98 | catch (PermissionDeniedException pdex) |
---|
99 | {} |
---|
100 | try |
---|
101 | { |
---|
102 | defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, |
---|
103 | ItemSubtype.getById(dc, SystemItems.getId(Protocol.PRINTING)), false); |
---|
104 | } |
---|
105 | catch (PermissionDeniedException pdex) |
---|
106 | {} |
---|
107 | try |
---|
108 | { |
---|
109 | defaultPrintRobots = (List<Hardware>)activeProject.findDefaultItems(dc, |
---|
110 | ItemSubtype.getById(dc, SystemItems.getId(Hardware.PRINT_ROBOT)), false); |
---|
111 | } |
---|
112 | catch (PermissionDeniedException pdex) |
---|
113 | {} |
---|
114 | } |
---|
115 | if (itemId == 0) |
---|
116 | { |
---|
117 | title = "Create array batch"; |
---|
118 | cc.removeObject("item"); |
---|
119 | int arrayDesignId = Values.getInt(request.getParameter("arraydesign_id")); |
---|
120 | if (arrayDesignId != 0) |
---|
121 | { |
---|
122 | currentArrayDesign = ArrayDesign.getById(dc, arrayDesignId); |
---|
123 | } |
---|
124 | else if (cc.getPropertyFilter("arrayDesign.name") != null) |
---|
125 | { |
---|
126 | currentArrayDesign = Base.getFirstMatching(dc, ArrayDesign.getQuery(), "name", cc.getPropertyFilter("arrayDesign.name")); |
---|
127 | } |
---|
128 | if (cc.getPropertyFilter("printRobot.name") != null) |
---|
129 | { |
---|
130 | currentPrintRobot = Base.getFirstMatching(dc, Hardware.getQuery(), "name", cc.getPropertyFilter("printRobot.name")); |
---|
131 | } |
---|
132 | if (cc.getPropertyFilter("protocol.name") != null) |
---|
133 | { |
---|
134 | currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("protocol.name")); |
---|
135 | } |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | batch = ArrayBatch.getById(dc, itemId); |
---|
140 | cc.setObject("item", batch); |
---|
141 | title = "Edit array batch -- " + HTML.encodeTags(batch.getName()); |
---|
142 | try |
---|
143 | { |
---|
144 | currentArrayDesign = batch.getArrayDesign(); |
---|
145 | } |
---|
146 | catch (PermissionDeniedException ex) |
---|
147 | { |
---|
148 | readCurrentArrayDesign = false; |
---|
149 | } |
---|
150 | try |
---|
151 | { |
---|
152 | currentPrintRobot = batch.getPrintRobot(); |
---|
153 | } |
---|
154 | catch (PermissionDeniedException ex) |
---|
155 | { |
---|
156 | readCurrentPrintRobot = false; |
---|
157 | } |
---|
158 | try |
---|
159 | { |
---|
160 | currentProtocol = batch.getProtocol(); |
---|
161 | } |
---|
162 | catch (PermissionDeniedException ex) |
---|
163 | { |
---|
164 | readCurrentProtocol = false; |
---|
165 | } |
---|
166 | } |
---|
167 | if (batch != null && !batch.hasPermission(Permission.WRITE)) |
---|
168 | { |
---|
169 | throw new PermissionDeniedException(Permission.WRITE, itemType.toString()); |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), batch); |
---|
174 | ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext); |
---|
175 | %> |
---|
176 | <base:page type="popup" title="<%=title%>"> |
---|
177 | <base:head scripts="tabcontrol.js,annotations.js" styles="tabcontrol.css"> |
---|
178 | <ext:scripts context="<%=jspContext%>" /> |
---|
179 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
180 | <script> |
---|
181 | // Validate the "ArrayBatch" tab |
---|
182 | function validateArrayBatch() |
---|
183 | { |
---|
184 | var frm = document.forms['batch']; |
---|
185 | if (Main.trimString(frm.name.value) == '') |
---|
186 | { |
---|
187 | Forms.showNotification(frm.name, 'You must enter a name'); |
---|
188 | return false; |
---|
189 | } |
---|
190 | if (frm.arraydesign_id && !frm.arraydesign_id.value) |
---|
191 | { |
---|
192 | Forms.showNotification('arraydesign_id.select', 'You must select an array design'); |
---|
193 | return false; |
---|
194 | } |
---|
195 | return true; |
---|
196 | } |
---|
197 | |
---|
198 | // Submit the form |
---|
199 | function saveSettings() |
---|
200 | { |
---|
201 | var frm = document.forms['batch']; |
---|
202 | if (TabControl.validateActiveTab('settings')) |
---|
203 | { |
---|
204 | if (annotationsLoaded) |
---|
205 | { |
---|
206 | Annotations.addModifiedAnnotationsToForm(frames.annotations, frm); |
---|
207 | } |
---|
208 | if (inheritedAnnotationsLoaded) |
---|
209 | { |
---|
210 | Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm); |
---|
211 | } |
---|
212 | frm.submit(); |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | var annotationsLoaded = false; |
---|
217 | var inheritedAnnotationsLoaded = false; |
---|
218 | var parentsChanged = false; |
---|
219 | var protocolChanged = false; |
---|
220 | function switchTab(tabControlId, tabId) |
---|
221 | { |
---|
222 | if (TabControl.setActiveTab(tabControlId, tabId)) |
---|
223 | { |
---|
224 | if (tabId == 'annotations' && (protocolChanged || !annotationsLoaded)) |
---|
225 | { |
---|
226 | Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=batch == null ? 0 : batch.getId()%>, getProtocolId()); |
---|
227 | annotationsLoaded = true; |
---|
228 | protocolChanged = false; |
---|
229 | } |
---|
230 | else if (tabId == 'inheritedAnnotations' && |
---|
231 | (parentsChanged || !inheritedAnnotationsLoaded)) |
---|
232 | { |
---|
233 | Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents()); |
---|
234 | inheritedAnnotationsLoaded = true; |
---|
235 | parentsChanged = false; |
---|
236 | } |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | function getProtocolId() |
---|
241 | { |
---|
242 | var frm = document.forms['batch']; |
---|
243 | var protocolId = 0; |
---|
244 | if (frm.protocol_id.length > 0 && !frm.protocol_id.disabled) |
---|
245 | { |
---|
246 | protocolId = Math.abs(parseInt(frm.protocol_id[frm.protocol_id.selectedIndex].value)); |
---|
247 | } |
---|
248 | return protocolId; |
---|
249 | } |
---|
250 | |
---|
251 | function getParents() |
---|
252 | { |
---|
253 | var frm = document.forms['batch']; |
---|
254 | var parents = new Array(); |
---|
255 | if (frm.arraydesign_id) |
---|
256 | { |
---|
257 | var arrayDesignId = Math.abs(parseInt(frm.arraydesign_id[frm.arraydesign_id.selectedIndex].value)); |
---|
258 | if (arrayDesignId > 0) parents[parents.length] = 'ARRAYDESIGN:'+arrayDesignId; |
---|
259 | } |
---|
260 | return parents; |
---|
261 | } |
---|
262 | |
---|
263 | function arrayDesignOnChange() |
---|
264 | { |
---|
265 | parentsChanged = true; |
---|
266 | } |
---|
267 | function selectArrayDesignOnClick() |
---|
268 | { |
---|
269 | var frm = document.forms['batch']; |
---|
270 | var url = '../../lims/arraydesigns/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArrayDesignCallback'; |
---|
271 | if (frm.arraydesign_id.length > 0) |
---|
272 | { |
---|
273 | var id = Math.abs(parseInt(frm.arraydesign_id[0].value)); |
---|
274 | url += '&item_id='+id; |
---|
275 | } |
---|
276 | Main.openPopup(url, 'SelectArrayDesign', 1050, 700); |
---|
277 | } |
---|
278 | function setArrayDesignCallback(id, name) |
---|
279 | { |
---|
280 | var frm = document.forms['batch']; |
---|
281 | var list = frm.arraydesign_id; |
---|
282 | if (list.length < 1 || list[0].value == '0') // > |
---|
283 | { |
---|
284 | Forms.addListOption(list, 0, new Option()); |
---|
285 | } |
---|
286 | list[0].value = id; |
---|
287 | list[0].text = name; |
---|
288 | list.selectedIndex = 0; |
---|
289 | parentsChanged = true; |
---|
290 | } |
---|
291 | |
---|
292 | function selectProtocolOnClick() |
---|
293 | { |
---|
294 | var frm = document.forms['batch']; |
---|
295 | var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolCallback'; |
---|
296 | if (frm.protocol_id.length > 1) |
---|
297 | { |
---|
298 | var id = Math.abs(parseInt(frm.protocol_id[1].value)); |
---|
299 | url += '&item_id='+id; |
---|
300 | } |
---|
301 | url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=<%=SystemItems.getId(Protocol.PRINTING)%>'; |
---|
302 | Main.openPopup(url, 'SelectProtocol', 1050, 700); |
---|
303 | } |
---|
304 | function setProtocolCallback(id, name) |
---|
305 | { |
---|
306 | var frm = document.forms['batch']; |
---|
307 | var list = frm.protocol_id; |
---|
308 | if (list.length < 2 || list[1].value == '0') // > |
---|
309 | { |
---|
310 | Forms.addListOption(list, 1, new Option()); |
---|
311 | } |
---|
312 | list[1].value = id; |
---|
313 | list[1].text = name; |
---|
314 | list.selectedIndex = 1; |
---|
315 | protocolChanged = true; |
---|
316 | } |
---|
317 | function protocolOnChange() |
---|
318 | { |
---|
319 | protocolChanged = true; |
---|
320 | } |
---|
321 | |
---|
322 | function selectPrintRobotOnClick() |
---|
323 | { |
---|
324 | var frm = document.forms['batch']; |
---|
325 | var url = '../../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setPrintRobotCallback'; |
---|
326 | if (frm.printrobot_id.length > 1) |
---|
327 | { |
---|
328 | var id = Math.abs(parseInt(frm.printrobot_id[1].value)); |
---|
329 | url += '&item_id='+id; |
---|
330 | } |
---|
331 | url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=<%=SystemItems.getId(Hardware.PRINT_ROBOT)%>'; |
---|
332 | Main.openPopup(url, 'SelectPrintRobot', 1050, 700); |
---|
333 | } |
---|
334 | function setPrintRobotCallback(id, name) |
---|
335 | { |
---|
336 | var frm = document.forms['batch']; |
---|
337 | var list = frm.printrobot_id; |
---|
338 | if (list.length < 2 || list[1].value == '0') // > |
---|
339 | { |
---|
340 | Forms.addListOption(list, 1, new Option()); |
---|
341 | } |
---|
342 | list[1].value = id; |
---|
343 | list[1].text = name; |
---|
344 | list.selectedIndex = 1; |
---|
345 | } |
---|
346 | |
---|
347 | |
---|
348 | function init() |
---|
349 | { |
---|
350 | var frm = document.forms['batch']; |
---|
351 | <% |
---|
352 | if (batch == null) |
---|
353 | { |
---|
354 | %> |
---|
355 | frm.name.focus(); |
---|
356 | frm.name.select(); |
---|
357 | <% |
---|
358 | } |
---|
359 | %> |
---|
360 | } |
---|
361 | </script> |
---|
362 | </base:head> |
---|
363 | <base:body onload="init()"> |
---|
364 | <h1><%=title%> <base:help tabcontrol="settings" /></h1> |
---|
365 | <form action="index.jsp?ID=<%=ID%>" method="post" name="batch"> |
---|
366 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
367 | |
---|
368 | <t:tabcontrol id="settings" |
---|
369 | subclass="content dialogtabcontrol" |
---|
370 | position="bottom" remember="<%=batch != null%>" switch="switchTab" |
---|
371 | extensions="<%=invoker%>"> |
---|
372 | <t:tab id="info" title="Array batch" validate="validateArrayBatch()" helpid="arraybatch.edit"> |
---|
373 | <table class="fullform input100"> |
---|
374 | <tr> |
---|
375 | <th>Name</th> |
---|
376 | <td><input class="text required" type="text" name="name" |
---|
377 | value="<%=HTML.encodeTags(batch == null ? Values.getString(cc.getPropertyValue("name"), "New array batch") : batch.getName())%>" |
---|
378 | maxlength="<%=ArrayBatch.MAX_NAME_LENGTH%>"></td> |
---|
379 | <td></td> |
---|
380 | </tr> |
---|
381 | <tr> |
---|
382 | <th>Array design</th> |
---|
383 | <td> |
---|
384 | <% |
---|
385 | if (batch != null) |
---|
386 | { |
---|
387 | %> |
---|
388 | <%=Base.getEncodedName(currentArrayDesign, !readCurrentArrayDesign)%> |
---|
389 | <% |
---|
390 | } |
---|
391 | else |
---|
392 | { |
---|
393 | %> |
---|
394 | <base:select |
---|
395 | id="arraydesign_id" |
---|
396 | clazz="selectionlist required" |
---|
397 | required="true" |
---|
398 | current="<%=currentArrayDesign%>" |
---|
399 | denied="<%=!readCurrentArrayDesign%>" |
---|
400 | recent="<%=recentArrayDesigns%>" |
---|
401 | defaultitems="<%=defaultArrayDesigns%>" |
---|
402 | newitem="true" |
---|
403 | onselect="selectArrayDesignOnClick()" |
---|
404 | onchange="arrayDesignOnChange()" |
---|
405 | /> |
---|
406 | <% |
---|
407 | } |
---|
408 | %> |
---|
409 | </td> |
---|
410 | <td></td> |
---|
411 | </tr> |
---|
412 | <tr> |
---|
413 | <th>Print robot</th> |
---|
414 | <td> |
---|
415 | <base:select |
---|
416 | id="printrobot_id" |
---|
417 | clazz="selectionlist" |
---|
418 | required="false" |
---|
419 | current="<%=currentPrintRobot%>" |
---|
420 | denied="<%=!readCurrentPrintRobot%>" |
---|
421 | recent="<%=recentPrintRobots%>" |
---|
422 | defaultitems="<%=defaultPrintRobots%>" |
---|
423 | newitem="<%=batch == null%>" |
---|
424 | onselect="selectPrintRobotOnClick()" |
---|
425 | /> |
---|
426 | </td> |
---|
427 | <td></td> |
---|
428 | </tr> |
---|
429 | <tr> |
---|
430 | <th>Protocol</th> |
---|
431 | <td> |
---|
432 | <base:select |
---|
433 | id="protocol_id" |
---|
434 | clazz="selectionlist" |
---|
435 | required="false" |
---|
436 | current="<%=currentProtocol%>" |
---|
437 | denied="<%=!readCurrentProtocol%>" |
---|
438 | recent="<%=recentProtocols%>" |
---|
439 | defaultitems="<%=defaultProtocols%>" |
---|
440 | newitem="<%=batch == null%>" |
---|
441 | onselect="selectProtocolOnClick()" |
---|
442 | onchange="protocolOnChange()" |
---|
443 | /> |
---|
444 | </td> |
---|
445 | <td></td> |
---|
446 | </tr> |
---|
447 | <tr class="dynamic"> |
---|
448 | <th>Description</th> |
---|
449 | <td> |
---|
450 | <textarea class="text" rows="6" name="description" id="description" |
---|
451 | ><%=HTML.encodeTags(batch == null ? cc.getPropertyValue("description") : batch.getDescription())%></textarea> |
---|
452 | </td> |
---|
453 | <td style="width: 20px;"> |
---|
454 | <base:zoom textarea="description" title="Description" /> |
---|
455 | </td> |
---|
456 | </tr> |
---|
457 | </table> |
---|
458 | </t:tab> |
---|
459 | |
---|
460 | <t:tab id="annotations" title="Annotations & parameters" helpid="annotations.edit"><iframe |
---|
461 | name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" |
---|
462 | class="absolutefull" style="width: 100%; height: 100%;"></iframe></t:tab> |
---|
463 | |
---|
464 | <t:tab id="inheritedAnnotations" title="Inherited annotations" |
---|
465 | helpid="annotations.edit.inherited"><iframe |
---|
466 | name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" |
---|
467 | class="absolutefull" style="width: 100%; height: 100%;"></iframe></t:tab> |
---|
468 | </t:tabcontrol> |
---|
469 | </form> |
---|
470 | |
---|
471 | <div class="legend"> |
---|
472 | <base:icon image="required.png" />= required information |
---|
473 | </div> |
---|
474 | |
---|
475 | <base:buttongroup subclass="dialogbuttons"> |
---|
476 | <base:button onclick="saveSettings()" title="Save" /> |
---|
477 | <base:button onclick="window.close()" title="Cancel" /> |
---|
478 | </base:buttongroup> |
---|
479 | </base:body> |
---|
480 | </base:page> |
---|
481 | <% |
---|
482 | } |
---|
483 | finally |
---|
484 | { |
---|
485 | if (dc != null) dc.close(); |
---|
486 | } |
---|
487 | %> |
---|