1 | <%-- $Id: edit_extract.jsp 5665 2011-06-23 10:32:07Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Johan Enell, 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.Type" |
---|
32 | import="net.sf.basedb.core.ItemContext" |
---|
33 | import="net.sf.basedb.core.SystemItems" |
---|
34 | import="net.sf.basedb.core.Permission" |
---|
35 | import="net.sf.basedb.core.Sample" |
---|
36 | import="net.sf.basedb.core.Extract" |
---|
37 | import="net.sf.basedb.core.ItemSubtype" |
---|
38 | import="net.sf.basedb.core.Tag" |
---|
39 | import="net.sf.basedb.core.BioMaterialEvent" |
---|
40 | import="net.sf.basedb.core.BioPlate" |
---|
41 | import="net.sf.basedb.core.BioWell" |
---|
42 | import="net.sf.basedb.core.Protocol" |
---|
43 | import="net.sf.basedb.core.Project" |
---|
44 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
45 | import="net.sf.basedb.core.BaseException" |
---|
46 | import="net.sf.basedb.core.ItemQuery" |
---|
47 | import="net.sf.basedb.core.ItemResultList" |
---|
48 | import="net.sf.basedb.core.Include" |
---|
49 | import="net.sf.basedb.core.query.Orders" |
---|
50 | import="net.sf.basedb.core.query.Hql" |
---|
51 | import="net.sf.basedb.core.query.Expressions" |
---|
52 | import="net.sf.basedb.core.query.Restrictions" |
---|
53 | import="net.sf.basedb.clients.web.Base" |
---|
54 | import="net.sf.basedb.clients.web.util.HTML" |
---|
55 | import="net.sf.basedb.util.Values" |
---|
56 | import="net.sf.basedb.util.formatter.Formatter" |
---|
57 | import="net.sf.basedb.util.formatter.WellCoordinateFormatter" |
---|
58 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
59 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
60 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
61 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
62 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
63 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
64 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
65 | import="java.util.List" |
---|
66 | import="java.util.Set" |
---|
67 | import="java.util.HashSet" |
---|
68 | import="java.util.Date" |
---|
69 | %> |
---|
70 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
71 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
72 | <% |
---|
73 | final Item itemType = Item.EXTRACT; |
---|
74 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
75 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
76 | final int itemId = cc.getId(); |
---|
77 | final String ID = sc.getId(); |
---|
78 | final float scale = Base.getScale(sc); |
---|
79 | final DbControl dc = sc.newDbControl(); |
---|
80 | try |
---|
81 | { |
---|
82 | String title = null; |
---|
83 | Extract extract = null; |
---|
84 | BioMaterialEvent creationEvent = null; |
---|
85 | Date eventDate = null; |
---|
86 | Item parentType = null; |
---|
87 | boolean lockEventProperties = false; |
---|
88 | |
---|
89 | WellCoordinateFormatter rowFormatter = new WellCoordinateFormatter(true); |
---|
90 | WellCoordinateFormatter columnFormatter = new WellCoordinateFormatter(false); |
---|
91 | |
---|
92 | boolean readCurrentSubtype = true; |
---|
93 | int currentSubtypeId = 0; |
---|
94 | boolean readCurrentProtocol = true; |
---|
95 | Protocol currentProtocol = null; |
---|
96 | Protocol defaultProtocol = null; |
---|
97 | boolean readCurrentTag = true; |
---|
98 | Tag currentTag = null; |
---|
99 | boolean readCurrentSample = true; |
---|
100 | Sample currentSample = null; |
---|
101 | Float usedFromSample = null; |
---|
102 | String name = null; |
---|
103 | ItemQuery<Extract> extractsQuery = null; |
---|
104 | boolean readCurrentBioWell = true; |
---|
105 | BioWell currentBioWell = null; |
---|
106 | boolean lockedWell = false; |
---|
107 | boolean readCurrentBioPlate = true; |
---|
108 | BioPlate currentBioPlate = null; |
---|
109 | |
---|
110 | // Load recently used items |
---|
111 | List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL); |
---|
112 | List<Sample> recentSamples = (List<Sample>)cc.getRecent(dc, Item.SAMPLE); |
---|
113 | List<BioPlate> recentBioPlates = (List<BioPlate>)cc.getRecent(dc, Item.BIOPLATE); |
---|
114 | List<Tag> recentTags = (List<Tag>)cc.getRecent(dc, Item.TAG); |
---|
115 | |
---|
116 | int activeProjectId = sc.getActiveProjectId(); |
---|
117 | if (activeProjectId > 0) |
---|
118 | { |
---|
119 | Project activeProject = Project.getById(dc, activeProjectId); |
---|
120 | try |
---|
121 | { |
---|
122 | defaultProtocol = (Protocol)activeProject.findDefaultItem(dc, |
---|
123 | ItemSubtype.getById(dc, SystemItems.getId(Protocol.EXTRACTION)), false); |
---|
124 | } |
---|
125 | catch(PermissionDeniedException pdex) |
---|
126 | { |
---|
127 | defaultProtocol = null; |
---|
128 | } |
---|
129 | } |
---|
130 | if (itemId == 0) |
---|
131 | { |
---|
132 | title = "Create extract"; |
---|
133 | cc.removeObject("item"); |
---|
134 | if (cc.getPropertyFilter("creationEvent.protocol.name") != null) |
---|
135 | { |
---|
136 | currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("creationEvent.protocol.name")); |
---|
137 | } |
---|
138 | if (cc.getPropertyFilter("tag.name") != null) |
---|
139 | { |
---|
140 | currentTag = Base.getFirstMatching(dc, Tag.getQuery(), "name", cc.getPropertyFilter("tag.name")); |
---|
141 | } |
---|
142 | currentSubtypeId = Values.getInt(request.getParameter("subtype_id")); |
---|
143 | if (currentSubtypeId == 0) |
---|
144 | { |
---|
145 | int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); |
---|
146 | currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId); |
---|
147 | } |
---|
148 | int sampleId = Values.getInt(request.getParameter("sample_id")); |
---|
149 | int extractId = Values.getInt(request.getParameter("extract_id")); |
---|
150 | if (sampleId != 0) |
---|
151 | { |
---|
152 | currentSample = Sample.getById(dc, sampleId); |
---|
153 | parentType = Item.SAMPLE; |
---|
154 | name = currentSample.getName() + ".e" + (currentSample.countExtracts() + 1); |
---|
155 | } |
---|
156 | else if (extractId != 0) |
---|
157 | { |
---|
158 | parentType = Item.EXTRACT; |
---|
159 | Extract e = Extract.getById(dc, extractId); |
---|
160 | name = e.getName() + ".e" + (e.countExtracts()+1); |
---|
161 | extractsQuery = Extract.getQuery(); |
---|
162 | extractsQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(extractId))); |
---|
163 | } |
---|
164 | else if (Values.getBoolean(request.getParameter("pooled"))) |
---|
165 | { |
---|
166 | parentType = Item.EXTRACT; |
---|
167 | name = Values.getString(cc.getPropertyValue("name"), "New pooled extract"); |
---|
168 | extractsQuery = Extract.getQuery(); |
---|
169 | extractsQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("selected"))); |
---|
170 | extractsQuery.setParameter("selected", cc.getSelected(), Type.INT); |
---|
171 | } |
---|
172 | else |
---|
173 | { |
---|
174 | name = Values.getString(cc.getPropertyValue("name"), "New extract"); |
---|
175 | } |
---|
176 | eventDate = (Date)cc.getPropertyObject("creationEvent.eventDate"); |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | extract = Extract.getById(dc, itemId); |
---|
181 | extract.checkPermission(Permission.WRITE); |
---|
182 | parentType = extract.getParentType(); |
---|
183 | cc.setObject("item", extract); |
---|
184 | title = "Edit extract -- " + HTML.encodeTags(extract.getName()); |
---|
185 | |
---|
186 | creationEvent = extract.getCreationEvent(); |
---|
187 | eventDate = creationEvent.getEventDate(); |
---|
188 | name = extract.getName(); |
---|
189 | lockEventProperties = !creationEvent.hasPermission(Permission.WRITE); |
---|
190 | |
---|
191 | try |
---|
192 | { |
---|
193 | ItemSubtype subtype = extract.getItemSubtype(); |
---|
194 | if (subtype != null) currentSubtypeId = subtype.getId(); |
---|
195 | } |
---|
196 | catch (PermissionDeniedException ex) |
---|
197 | { |
---|
198 | readCurrentSubtype = false; |
---|
199 | } |
---|
200 | |
---|
201 | try |
---|
202 | { |
---|
203 | currentProtocol = creationEvent.getProtocol(); |
---|
204 | } |
---|
205 | catch (PermissionDeniedException ex) |
---|
206 | { |
---|
207 | readCurrentProtocol = false; |
---|
208 | } |
---|
209 | |
---|
210 | try |
---|
211 | { |
---|
212 | currentTag = extract.getTag(); |
---|
213 | } |
---|
214 | catch (PermissionDeniedException ex) |
---|
215 | { |
---|
216 | readCurrentTag = false; |
---|
217 | } |
---|
218 | |
---|
219 | try |
---|
220 | { |
---|
221 | if (parentType == Item.SAMPLE) |
---|
222 | { |
---|
223 | currentSample = (Sample)extract.getParent(); |
---|
224 | if (currentSample != null) |
---|
225 | { |
---|
226 | usedFromSample = creationEvent.getUsedQuantity(currentSample); |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|
230 | catch (PermissionDeniedException ex) |
---|
231 | { |
---|
232 | readCurrentSample = false; |
---|
233 | } |
---|
234 | try |
---|
235 | { |
---|
236 | currentBioWell = extract.getBioWell(); |
---|
237 | lockedWell = extract.isLockedInWell(); |
---|
238 | if (currentBioWell != null) |
---|
239 | { |
---|
240 | currentBioPlate = currentBioWell.getPlate(); |
---|
241 | } |
---|
242 | } |
---|
243 | catch (PermissionDeniedException ex) |
---|
244 | { |
---|
245 | readCurrentBioWell = false; |
---|
246 | readCurrentBioPlate = false; |
---|
247 | } |
---|
248 | |
---|
249 | // Query to retrieve pooled extracts |
---|
250 | if (parentType == Item.EXTRACT) |
---|
251 | { |
---|
252 | extractsQuery = (ItemQuery<Extract>)creationEvent.getSources(); |
---|
253 | } |
---|
254 | } |
---|
255 | |
---|
256 | // Query to retrieve item types |
---|
257 | final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType); |
---|
258 | subtypesQuery.include(Include.ALL); |
---|
259 | |
---|
260 | final String clazz = "class=\"text\""; |
---|
261 | final String requiredClazz = "class=\"text required\""; |
---|
262 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
263 | String dateFormat = FormatterSettings.getDateFormat(sc); |
---|
264 | String jsDateFormat = HTML.javaScriptEncode(dateFormat); |
---|
265 | String htmlDateFormat = HTML.encodeTags(dateFormat); |
---|
266 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), extract); |
---|
267 | ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext); |
---|
268 | %> |
---|
269 | <base:page type="popup" title="<%=title%>"> |
---|
270 | <base:head scripts="tabcontrol.js,annotations.js,linkitems.js,subtypes.js,ajax.js,json2.js" styles="tabcontrol.css"> |
---|
271 | <ext:scripts context="<%=jspContext%>" /> |
---|
272 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
273 | <script language="JavaScript"> |
---|
274 | // Validate the "Extract" tab |
---|
275 | function validateExtract() |
---|
276 | { |
---|
277 | var frm = document.forms['extract']; |
---|
278 | if (Main.trimString(frm.name.value) == '') |
---|
279 | { |
---|
280 | alert("You must enter a name"); |
---|
281 | frm.name.focus(); |
---|
282 | return false; |
---|
283 | } |
---|
284 | if (Main.trimString(frm.bioplate_id.value) != 0 && Main.trimString(frm.biowell_id.value) == 0) |
---|
285 | { |
---|
286 | alert("You must choose a biowell from the bioplate"); |
---|
287 | return false; |
---|
288 | } |
---|
289 | return true; |
---|
290 | } |
---|
291 | |
---|
292 | // Submit the form |
---|
293 | function saveSettings() |
---|
294 | { |
---|
295 | var frm = document.forms['extract']; |
---|
296 | if (TabControl.validateActiveTab('settings')) |
---|
297 | { |
---|
298 | if (annotationsLoaded) |
---|
299 | { |
---|
300 | Annotations.addModifiedAnnotationsToForm(frames.annotations, frm); |
---|
301 | } |
---|
302 | if (inheritedAnnotationsLoaded) |
---|
303 | { |
---|
304 | Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm); |
---|
305 | } |
---|
306 | frm.modifiedExtracts.value = Link.exportModified(frm, 'E', true).join(','); |
---|
307 | frm.removedExtracts.value = Link.getActionIds(-1, 'E').join(','); |
---|
308 | frm.submit(); |
---|
309 | } |
---|
310 | } |
---|
311 | |
---|
312 | var annotationsLoaded = false; |
---|
313 | var inheritedAnnotationsLoaded = false; |
---|
314 | var parentsChanged = false; |
---|
315 | var protocolChanged = false; |
---|
316 | function switchTab(tabControlId, tabId) |
---|
317 | { |
---|
318 | if (TabControl.setActiveTab(tabControlId, tabId)) |
---|
319 | { |
---|
320 | if (tabId == 'annotations' && (protocolChanged || !annotationsLoaded)) |
---|
321 | { |
---|
322 | Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getProtocolId()); |
---|
323 | annotationsLoaded = true; |
---|
324 | protocolChanged = false; |
---|
325 | } |
---|
326 | else if (tabId == 'inheritedAnnotations' && |
---|
327 | (parentsChanged || !inheritedAnnotationsLoaded)) |
---|
328 | { |
---|
329 | Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents()); |
---|
330 | inheritedAnnotationsLoaded = true; |
---|
331 | parentsChanged = false; |
---|
332 | } |
---|
333 | } |
---|
334 | } |
---|
335 | |
---|
336 | function getProtocolId() |
---|
337 | { |
---|
338 | var frm = document.forms['extract']; |
---|
339 | var protocolId = 0; |
---|
340 | if (frm.protocol_id.length > 0 && !frm.protocol_id.disabled) |
---|
341 | { |
---|
342 | protocolId = Math.abs(parseInt(frm.protocol_id[frm.protocol_id.selectedIndex].value)); |
---|
343 | } |
---|
344 | return protocolId; |
---|
345 | } |
---|
346 | |
---|
347 | function getParents() |
---|
348 | { |
---|
349 | var frm = document.forms['extract']; |
---|
350 | var parents = new Array(); |
---|
351 | if (frm.parentType[0].checked) |
---|
352 | { |
---|
353 | var sampleId = Math.abs(parseInt(frm.sample_id[frm.sample_id.selectedIndex].value)); |
---|
354 | if (sampleId > 0) parents[parents.length] = 'SAMPLE:'+sampleId; |
---|
355 | } |
---|
356 | else |
---|
357 | { |
---|
358 | var ids = Link.getListIds(frm.extracts, 'E'); |
---|
359 | if (ids.length > 0) |
---|
360 | { |
---|
361 | parents[parents.length] = 'EXTRACT:'+ids.join(':'); |
---|
362 | } |
---|
363 | } |
---|
364 | return parents; |
---|
365 | } |
---|
366 | |
---|
367 | function selectProtocolOnClick() |
---|
368 | { |
---|
369 | var frm = document.forms['extract']; |
---|
370 | var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; |
---|
371 | url += '&callback=setProtocolCallback&resetTemporary=1'; |
---|
372 | url += ItemSubtype.createRelatedFilter('extract', 'PROTOCOL', <%=SystemItems.getId(Protocol.EXTRACTION)%>); |
---|
373 | if (frm.protocol_id.length > 1) |
---|
374 | { |
---|
375 | var id = Math.abs(parseInt(frm.protocol_id[1].value)); |
---|
376 | url += '&item_id='+id; |
---|
377 | } |
---|
378 | Main.openPopup(url, 'SelectProtocol', 1000, 700); |
---|
379 | } |
---|
380 | function setProtocolCallback(id, name) |
---|
381 | { |
---|
382 | var frm = document.forms['extract']; |
---|
383 | var list = frm.protocol_id; |
---|
384 | if (list.length < 2 || list[1].value == '0') // > |
---|
385 | { |
---|
386 | Forms.addListOption(list, 1, new Option()); |
---|
387 | } |
---|
388 | list[1].value = id; |
---|
389 | list[1].text = name; |
---|
390 | list.selectedIndex = 1; |
---|
391 | protocolChanged = true; |
---|
392 | } |
---|
393 | function protocolOnChange() |
---|
394 | { |
---|
395 | protocolChanged = true; |
---|
396 | } |
---|
397 | function selectTagOnClick() |
---|
398 | { |
---|
399 | var frm = document.forms['extract']; |
---|
400 | var url = '../tags/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; |
---|
401 | url += '&callback=setTagCallback&resetTemporary=1'; |
---|
402 | url += ItemSubtype.createRelatedFilter('extract', 'TAG'); |
---|
403 | if (frm.tag_id.length > 1) |
---|
404 | { |
---|
405 | var id = Math.abs(parseInt(frm.tag_id[1].value)); |
---|
406 | url += '&item_id='+id; |
---|
407 | } |
---|
408 | Main.openPopup(url, 'SelectTag', 1000, 700); |
---|
409 | } |
---|
410 | function setTagCallback(id, name) |
---|
411 | { |
---|
412 | var frm = document.forms['extract']; |
---|
413 | var list = frm.tag_id; |
---|
414 | if (list.length < 2 || list[1].value == '0') // > |
---|
415 | { |
---|
416 | Forms.addListOption(list, 1, new Option()); |
---|
417 | } |
---|
418 | list[1].value = id; |
---|
419 | list[1].text = name; |
---|
420 | list.selectedIndex = 1; |
---|
421 | } |
---|
422 | function selectBioPlateOnClick() |
---|
423 | { |
---|
424 | var frm = document.forms['extract']; |
---|
425 | var url = '../bioplates/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setBioPlateCallback'; |
---|
426 | if (frm.bioplate_id.length > 1) |
---|
427 | { |
---|
428 | var id = Math.abs(parseInt(frm.bioplate_id[1].value)); |
---|
429 | url += '&item_id='+id; |
---|
430 | } |
---|
431 | url += '&resetTemporary=1&tmpfilter:INT:bioPlateType.lockMode=<><%=BioWell.LockMode.LOCKED_AFTER_CREATE.getValue()%>'; |
---|
432 | url += '&tmpfilter:BOOLEAN:destroyed=false'; |
---|
433 | Main.openPopup(url, 'SelectBioplate', 1000, 700); |
---|
434 | } |
---|
435 | function setBioPlateCallback(id, name) |
---|
436 | { |
---|
437 | var frm = document.forms['extract']; |
---|
438 | var list = frm.bioplate_id; |
---|
439 | if (list.length < 2 || list[1].value == '0') // > |
---|
440 | { |
---|
441 | Forms.addListOption(list, 1, new Option()); |
---|
442 | } |
---|
443 | list[1].value = id; |
---|
444 | list[1].text = name; |
---|
445 | list.selectedIndex = 1; |
---|
446 | frm.biowell_id.remove(1); |
---|
447 | frm.biowell_id.disabled = false; |
---|
448 | } |
---|
449 | function bioPlateOnChange() |
---|
450 | { |
---|
451 | var frm = document.forms['extract']; |
---|
452 | var list = frm.bioplate_id; |
---|
453 | frm.biowell_id.selectedIndex=0; |
---|
454 | frm.biowell_id.remove(1); |
---|
455 | } |
---|
456 | |
---|
457 | function initBioWell() |
---|
458 | { |
---|
459 | var frm = document.forms['extract']; |
---|
460 | <% |
---|
461 | if (currentBioWell != null) |
---|
462 | { |
---|
463 | %> |
---|
464 | var list = frm.biowell_id; |
---|
465 | var wellId = <%=currentBioWell.getId()%>; |
---|
466 | Forms.addListOption(list, 1, new Option()); |
---|
467 | list[1].value = '<%=currentBioWell.getId()*(extract == null ? 1 : -1)%>'; |
---|
468 | list[1].text = '[<%=rowFormatter.format(currentBioWell.getRow())%>,<%=columnFormatter.format(currentBioWell.getColumn())%>]'; |
---|
469 | list.selectedIndex = 1; |
---|
470 | <% |
---|
471 | } |
---|
472 | %> |
---|
473 | } |
---|
474 | function selectBioWellOnClick() |
---|
475 | { |
---|
476 | var frm = document.forms['extract']; |
---|
477 | var bioplate_list = frm.bioplate_id; |
---|
478 | var bioplateId = Math.abs(parseInt(bioplate_list[bioplate_list.selectedIndex].value)) |
---|
479 | if (Main.trimString(frm.bioplate_id.value) == 0) |
---|
480 | { |
---|
481 | alert("You must first select the bioplate where the biowell is located"); |
---|
482 | return; |
---|
483 | } |
---|
484 | |
---|
485 | var url = '../bioplates/wells/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setBioWellCallback'; |
---|
486 | if (frm.biowell_id.length > 1) |
---|
487 | { |
---|
488 | var id = Math.abs(parseInt(frm.biowell_id[1].value)); |
---|
489 | url += '&item_id='+id; |
---|
490 | } |
---|
491 | url += '&bioplate_id='+bioplateId; |
---|
492 | url += '&resetTemporary=1&tmpfilter:STRING:$mbm.name='+escape('='); |
---|
493 | url += '&tmpfilter:STRING:originalBioMaterial.name='+escape('='); |
---|
494 | url += '&columns=row,column'; |
---|
495 | Main.openPopup(url, 'SelectBiowell', 700, 700); |
---|
496 | } |
---|
497 | function setBioWellCallback(id, name) |
---|
498 | { |
---|
499 | var frm = document.forms['extract']; |
---|
500 | var list = frm.biowell_id; |
---|
501 | if (list.length < 2 || list[1].value == '0') // > |
---|
502 | { |
---|
503 | Forms.addListOption(list, 1, new Option()); |
---|
504 | } |
---|
505 | list[1].value = id; |
---|
506 | list[1].text = name; |
---|
507 | list.selectedIndex = 1; |
---|
508 | } |
---|
509 | |
---|
510 | function parentTypeOnClick() |
---|
511 | { |
---|
512 | var frm = document.forms['extract']; |
---|
513 | var useExtracts = frm.parentType[1].checked; |
---|
514 | frm.sample_id.disabled = useExtracts; |
---|
515 | frm.used_from_sample.disabled = useExtracts; |
---|
516 | frm.extracts.disabled = !useExtracts; |
---|
517 | frm.used_quantity.disabled = !useExtracts; |
---|
518 | parentsChanged = true; |
---|
519 | } |
---|
520 | function sampleOnChange() |
---|
521 | { |
---|
522 | parentsChanged = true; |
---|
523 | } |
---|
524 | |
---|
525 | function selectSampleOnClick() |
---|
526 | { |
---|
527 | var frm = document.forms['extract']; |
---|
528 | var url = '../samples/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; |
---|
529 | url += '&callback=setSampleCallback&resetTemporary=1'; |
---|
530 | url += ItemSubtype.createRelatedFilter('extract', 'SAMPLE'); |
---|
531 | if (frm.sample_id.length > 1) |
---|
532 | { |
---|
533 | var id = Math.abs(parseInt(frm.sample_id[1].value)); |
---|
534 | url += '&item_id='+id; |
---|
535 | } |
---|
536 | Main.openPopup(url, 'SelectSample', 1000, 700); |
---|
537 | } |
---|
538 | function setSampleCallback(id, name) |
---|
539 | { |
---|
540 | var frm = document.forms['extract']; |
---|
541 | var list = frm.sample_id; |
---|
542 | if (list.length < 2 || list[1].value == '0') // > |
---|
543 | { |
---|
544 | Forms.addListOption(list, 1, new Option()); |
---|
545 | } |
---|
546 | list[1].value = id; |
---|
547 | list[1].text = name; |
---|
548 | list.selectedIndex = 1; |
---|
549 | frm.parentType[0].checked = true; |
---|
550 | frm.parentType[1].checked = false; |
---|
551 | parentTypeOnClick(); |
---|
552 | parentsChanged = true; |
---|
553 | } |
---|
554 | |
---|
555 | function addExtractsOnClick() |
---|
556 | { |
---|
557 | var frm = document.forms['extract']; |
---|
558 | var url = 'index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple'; |
---|
559 | url += '&callback=addExtractCallback&resetTemporary=1'; |
---|
560 | url += ItemSubtype.createRelatedFilter('extract', 'EXTRACT'); |
---|
561 | Main.openPopup(url, 'AddExtracts', 1000, 700); |
---|
562 | } |
---|
563 | |
---|
564 | function addExtractCallback(extractId, name) |
---|
565 | { |
---|
566 | var item = Link.getItem('E', extractId); |
---|
567 | if (!item) item = new Item('E', extractId, name+' [-]', '', ''); |
---|
568 | Link.addItem(document.forms['extract'].extracts, item); |
---|
569 | frm.parentType[0].checked = false; |
---|
570 | frm.parentType[1].checked = true; |
---|
571 | parentTypeOnClick(); |
---|
572 | parentsChanged = true; |
---|
573 | } |
---|
574 | function extractsOnChange() |
---|
575 | { |
---|
576 | var frm = document.forms['extract']; |
---|
577 | var item = frm.extracts[frm.extracts.selectedIndex].item; |
---|
578 | if (item && item.id) |
---|
579 | { |
---|
580 | frm.used_quantity.value = item.value; |
---|
581 | frm.used_quantity.focus(); |
---|
582 | } |
---|
583 | else |
---|
584 | { |
---|
585 | frm.used_quantity.value = ''; |
---|
586 | } |
---|
587 | } |
---|
588 | function usedQuantityOnBlur() |
---|
589 | { |
---|
590 | var frm = document.forms['extract']; |
---|
591 | var usedQuantity = frm.used_quantity.value; |
---|
592 | var displayQuantity = usedQuantity == '' ? '-' : usedQuantity+' µg'; |
---|
593 | for (var i = 0; i < frm.extracts.length; i++) // > |
---|
594 | { |
---|
595 | var option = frm.extracts[i]; |
---|
596 | if (option.selected && option.item.id) |
---|
597 | { |
---|
598 | option.item.value = usedQuantity; |
---|
599 | var text = option.text.replace(/\[.*\]/, '['+displayQuantity+']'); |
---|
600 | option.text = text; |
---|
601 | } |
---|
602 | } |
---|
603 | } |
---|
604 | function usedFromSampleOnBlur() |
---|
605 | { |
---|
606 | var frm = document.forms['extract']; |
---|
607 | |
---|
608 | var sampleId = parseInt(frm.sample_id[frm.sample_id.selectedIndex].value); |
---|
609 | if (sampleId < 0) |
---|
610 | { |
---|
611 | frm.sample_id[frm.sample_id.selectedIndex].value = -sampleId; |
---|
612 | } |
---|
613 | } |
---|
614 | |
---|
615 | |
---|
616 | function removeOnClick() |
---|
617 | { |
---|
618 | Link.removeSelected(document.forms['extract'].extracts); |
---|
619 | parentsChanged = true; |
---|
620 | } |
---|
621 | |
---|
622 | function init() |
---|
623 | { |
---|
624 | <% |
---|
625 | if (extract == null) |
---|
626 | { |
---|
627 | %> |
---|
628 | var frm = document.forms['extract']; |
---|
629 | frm.name.focus(); |
---|
630 | frm.name.select(); |
---|
631 | <% |
---|
632 | } |
---|
633 | %> |
---|
634 | initBioWell(); |
---|
635 | initExtracts(); |
---|
636 | parentTypeOnClick(); |
---|
637 | } |
---|
638 | function initExtracts() |
---|
639 | { |
---|
640 | var extracts = document.forms['extract'].extracts; |
---|
641 | <% |
---|
642 | if (extractsQuery != null) |
---|
643 | { |
---|
644 | extractsQuery.include(Include.ALL); |
---|
645 | extractsQuery.order(Orders.asc(Hql.property("name"))); |
---|
646 | ItemResultList<Extract> extracts = extractsQuery.list(dc); |
---|
647 | for (Extract e : extracts) |
---|
648 | { |
---|
649 | if (extract != null) |
---|
650 | { |
---|
651 | String usedQuantity = Values.formatNumber(creationEvent.getUsedQuantity(e), -1); |
---|
652 | %> |
---|
653 | Link.addNewItem(extracts, new Item('E', <%=e.getId()%>, '<%=HTML.javaScriptEncode(e.getName())%> [<%=usedQuantity%> µg]', '<%=usedQuantity%>')); |
---|
654 | <% |
---|
655 | } |
---|
656 | else |
---|
657 | { |
---|
658 | %> |
---|
659 | Link.addItem(extracts, new Item('E', <%=e.getId()%>, '<%=HTML.javaScriptEncode(e.getName())%> [-]', '', '')); |
---|
660 | <% |
---|
661 | |
---|
662 | } |
---|
663 | } |
---|
664 | } |
---|
665 | %> |
---|
666 | } |
---|
667 | </script> |
---|
668 | </base:head> |
---|
669 | <base:body onload="init()"> |
---|
670 | <p> |
---|
671 | <form action="index.jsp?ID=<%=ID%>" method="post" name="extract" onsubmit="return false;"> |
---|
672 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
673 | |
---|
674 | <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3> |
---|
675 | <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" |
---|
676 | position="bottom" remember="<%=extract != null%>" switch="switchTab" |
---|
677 | extensions="<%=invoker%>"> |
---|
678 | <t:tab id="info" title="Extract" validate="validateExtract()" helpid="extract.edit"> |
---|
679 | <table class="form" cellspacing=0> |
---|
680 | <tr> |
---|
681 | <td class="prompt">Name</td> |
---|
682 | <td><input <%=requiredClazz%> type="text" name="name" |
---|
683 | value="<%=HTML.encodeTags(name)%>" |
---|
684 | size="40" maxlength="<%=Extract.MAX_NAME_LENGTH%>"></td> |
---|
685 | </tr> |
---|
686 | <tr valign="top"> |
---|
687 | <td class="prompt">Type</td> |
---|
688 | <td colspan="2"> |
---|
689 | <select name="subtype_id" |
---|
690 | <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>> |
---|
691 | <% |
---|
692 | if (!readCurrentSubtype) |
---|
693 | { |
---|
694 | %> |
---|
695 | <option value="-1">- denied - |
---|
696 | <% |
---|
697 | } |
---|
698 | else |
---|
699 | { |
---|
700 | %> |
---|
701 | <option value="0">-none- |
---|
702 | <% |
---|
703 | for (ItemSubtype subtype : subtypesQuery.list(dc)) |
---|
704 | { |
---|
705 | int id = subtype.getId(); |
---|
706 | if (id != currentSubtypeId && subtype.isRemoved()) continue; |
---|
707 | %> |
---|
708 | <option value="<%=id == currentSubtypeId && extract != null ? -id : id%>" |
---|
709 | <%=id == currentSubtypeId ? "selected" : ""%> |
---|
710 | title="<%=HTML.encodeTags(subtype.getDescription()) %>" |
---|
711 | ><%=HTML.encodeTags(subtype.getName())%> |
---|
712 | <% |
---|
713 | } |
---|
714 | } |
---|
715 | %> |
---|
716 | </select> |
---|
717 | </td> |
---|
718 | </tr> |
---|
719 | <tr> |
---|
720 | <td class="prompt">Tag</td> |
---|
721 | <td> |
---|
722 | <base:select |
---|
723 | id="tag_id" |
---|
724 | clazz="selectionlist" |
---|
725 | required="false" |
---|
726 | current="<%=currentTag%>" |
---|
727 | denied="<%=!readCurrentTag%>" |
---|
728 | recent="<%=recentTags%>" |
---|
729 | newitem="<%=extract == null%>" |
---|
730 | onselect="selectTagOnClick()" |
---|
731 | /> |
---|
732 | </td> |
---|
733 | </tr> |
---|
734 | <tr> |
---|
735 | <td class="prompt">External ID</td> |
---|
736 | <td><input <%=clazz%> type="text" name="external_id" |
---|
737 | value="<%=HTML.encodeTags(extract == null ? Values.getString(cc.getPropertyValue("externalId"), "") : extract.getExternalId())%>" |
---|
738 | size="40" maxlength="<%=Extract.MAX_EXTERNAL_ID_LENGTH%>"></td> |
---|
739 | </tr> |
---|
740 | <tr> |
---|
741 | <td class="prompt">Original quantity</td> |
---|
742 | <td><input <%=clazz%> type="text" name="original_quantity" |
---|
743 | value="<%=Values.formatNumber(extract == null ? Values.getFloat(cc.getPropertyValue("originalQuantity"), null): extract.getOriginalQuantity(), -1)%>" size="12" |
---|
744 | maxlength="10" onkeypress="return Numbers.numberOnly(event)"> (µg)</td> |
---|
745 | </tr> |
---|
746 | <tr> |
---|
747 | <td class="prompt">Created</td> |
---|
748 | <td> |
---|
749 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
750 | <tr> |
---|
751 | <td> |
---|
752 | <input <%=clazz%> type="text" name="event_date" <%=lockEventProperties ? "disabled" : ""%> |
---|
753 | value="<%=HTML.encodeTags(dateFormatter.format(eventDate))%>" |
---|
754 | size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>"> |
---|
755 | |
---|
756 | </td> |
---|
757 | <td> |
---|
758 | <base:button |
---|
759 | onclick="<%="Dates.selectDate('Created', 'extract', 'event_date', null, '"+jsDateFormat+"')"%>" |
---|
760 | image="calendar.png" |
---|
761 | title="Calendar…" |
---|
762 | tooltip="Select a date from a calendar" |
---|
763 | disabled="<%=lockEventProperties%>" |
---|
764 | /> |
---|
765 | </td> |
---|
766 | </tr> |
---|
767 | </table> |
---|
768 | </td> |
---|
769 | </tr> |
---|
770 | <tr> |
---|
771 | <td class="prompt">Registered</td> |
---|
772 | <td><%=dateFormatter.format(creationEvent == null ? new Date() : creationEvent.getEntryDate())%></td> |
---|
773 | </tr> |
---|
774 | <tr> |
---|
775 | <td class="prompt">Protocol</td> |
---|
776 | <td> |
---|
777 | <base:select |
---|
778 | id="protocol_id" |
---|
779 | clazz="selectionlist" |
---|
780 | required="false" |
---|
781 | current="<%=currentProtocol%>" |
---|
782 | denied="<%=!readCurrentProtocol%>" |
---|
783 | recent="<%=recentProtocols%>" |
---|
784 | defaultitem="<%=defaultProtocol%>" |
---|
785 | newitem="<%=extract == null%>" |
---|
786 | onselect="selectProtocolOnClick()" |
---|
787 | onchange="protocolOnChange()" |
---|
788 | disabled="<%=lockEventProperties%>" |
---|
789 | /> |
---|
790 | </td> |
---|
791 | </tr> |
---|
792 | <tr> |
---|
793 | <td class="prompt">Bioplate</td> |
---|
794 | <td> |
---|
795 | <base:select |
---|
796 | id="bioplate_id" |
---|
797 | clazz="selectionlist" |
---|
798 | required="false" |
---|
799 | current="<%=currentBioPlate%>" |
---|
800 | denied="<%=!readCurrentBioPlate%>" |
---|
801 | recent="<%=recentBioPlates%>" |
---|
802 | newitem="<%=extract == null%>" |
---|
803 | onselect="selectBioPlateOnClick()" |
---|
804 | onchange="bioPlateOnChange()" |
---|
805 | disabled="<%=lockedWell%>" |
---|
806 | /> |
---|
807 | </td> |
---|
808 | </tr> |
---|
809 | <tr> |
---|
810 | <td class="prompt">Biowell</td> |
---|
811 | <td> |
---|
812 | <base:select |
---|
813 | id="biowell_id" |
---|
814 | clazz="selectionlist" |
---|
815 | required="false" |
---|
816 | current="<%=null %>" |
---|
817 | denied="<%=!readCurrentBioWell%>" |
---|
818 | newitem="<%=extract == null%>" |
---|
819 | onselect="selectBioWellOnClick()" |
---|
820 | onchange="bioWellOnChange()" |
---|
821 | disabled="<%=lockedWell%>" |
---|
822 | /> |
---|
823 | </td> |
---|
824 | </tr> |
---|
825 | <tr valign=top> |
---|
826 | <td class="prompt">Description</td> |
---|
827 | <td nowrap> |
---|
828 | <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual" |
---|
829 | ><%=HTML.encodeTags(extract == null ? cc.getPropertyValue("description") : extract.getDescription())%></textarea> |
---|
830 | <a href="javascript:Main.zoom('Description', 'extract', 'description')" |
---|
831 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
832 | </td> |
---|
833 | </tr> |
---|
834 | </table> |
---|
835 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
836 | </t:tab> |
---|
837 | |
---|
838 | <t:tab id="parents" title="Parents" helpid="extract.parent"> |
---|
839 | <table class="form" cellspacing=0> |
---|
840 | <tr> |
---|
841 | <td class="prompt">Parent type</td> |
---|
842 | <td> |
---|
843 | <input type="radio" name="parentType" id="parentType.sample" |
---|
844 | value="SAMPLE" onclick="parentTypeOnClick()" |
---|
845 | <%=parentType != Item.EXTRACT ? "checked" : ""%> |
---|
846 | ><label for="parentType.sample">Sample</label> |
---|
847 | <input type="radio" name="parentType" id="parentType.extract" |
---|
848 | value="EXTRACT" onclick="parentTypeOnClick()" |
---|
849 | <%=parentType == Item.EXTRACT ? "checked" : ""%> |
---|
850 | ><label for="parentType.extract">Extract</label> |
---|
851 | </td> |
---|
852 | </tr> |
---|
853 | <tr valign="top"> |
---|
854 | <td class="prompt">Sample</td> |
---|
855 | <td> |
---|
856 | <base:select |
---|
857 | id="sample_id" |
---|
858 | clazz="selectionlist" |
---|
859 | buttonstyle="width: 150px;" |
---|
860 | buttonicon="add.png" |
---|
861 | buttontitle="Select sample…" |
---|
862 | required="false" |
---|
863 | current="<%=currentSample%>" |
---|
864 | denied="<%=!readCurrentSample%>" |
---|
865 | recent="<%=recentSamples%>" |
---|
866 | selectrecent="false" |
---|
867 | newitem="<%=extract == null%>" |
---|
868 | onselect="selectSampleOnClick()" |
---|
869 | onchange="sampleOnChange()" |
---|
870 | /> |
---|
871 | </td> |
---|
872 | </tr> |
---|
873 | <tr> |
---|
874 | <td class="subprompt">-</td> |
---|
875 | <td> |
---|
876 | used quantity |
---|
877 | <input <%=clazz%> type="text" name="used_from_sample" value="<%=Values.formatNumber(usedFromSample, -1)%>" |
---|
878 | size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)" |
---|
879 | onblur="usedFromSampleOnBlur()"> (µg) |
---|
880 | </td> |
---|
881 | </tr> |
---|
882 | <tr valign="top"> |
---|
883 | <td class="prompt">Extracts</td> |
---|
884 | <td> |
---|
885 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
886 | <tr valign="top"> |
---|
887 | <td> |
---|
888 | <select name="extracts" size="5" multiple class="selectionlist" |
---|
889 | onchange="extractsOnChange()"> |
---|
890 | </select> |
---|
891 | <input type="hidden" name="modifiedExtracts" value=""> |
---|
892 | <input type="hidden" name="removedExtracts" value=""> |
---|
893 | </td> |
---|
894 | <td> |
---|
895 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
896 | <tr><td style="padding: 1px 0px 4px 0px;"><base:button |
---|
897 | style="width: 150px;" |
---|
898 | onclick="addExtractsOnClick()" |
---|
899 | title="Add extracts…" |
---|
900 | tooltip="Add extracts" |
---|
901 | /></td></tr> |
---|
902 | <tr><td width="150"><base:button |
---|
903 | style="width: 150px;" |
---|
904 | onclick="removeOnClick()" |
---|
905 | title="Remove" |
---|
906 | tooltip="Remove the selected extracts" |
---|
907 | /></td></tr> |
---|
908 | </table> |
---|
909 | </td> |
---|
910 | </tr> |
---|
911 | </table> |
---|
912 | </td> |
---|
913 | </tr> |
---|
914 | <tr> |
---|
915 | <td class="subprompt">-</td> |
---|
916 | <td>used quantity |
---|
917 | <input <%=clazz%> type="text" name="used_quantity" value="" |
---|
918 | size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)" |
---|
919 | onkeyup="usedQuantityOnBlur();" |
---|
920 | > (µg) |
---|
921 | </td> |
---|
922 | </tr> |
---|
923 | </table> |
---|
924 | </t:tab> |
---|
925 | |
---|
926 | <t:tab id="annotations" title="Annotations & parameters" |
---|
927 | helpid="annotations.edit" tooltip="Enter values for annotations and protocol parameters"> |
---|
928 | <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" |
---|
929 | width="100%" height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0 |
---|
930 | marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe> |
---|
931 | </t:tab> |
---|
932 | |
---|
933 | <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited"> |
---|
934 | |
---|
935 | <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" |
---|
936 | width="100%" height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0 |
---|
937 | marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe> |
---|
938 | </t:tab> |
---|
939 | </t:tabcontrol> |
---|
940 | |
---|
941 | <table align="center"> |
---|
942 | <tr> |
---|
943 | <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td> |
---|
944 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
945 | </tr> |
---|
946 | </table> |
---|
947 | </form> |
---|
948 | </base:body> |
---|
949 | </base:page> |
---|
950 | <% |
---|
951 | } |
---|
952 | finally |
---|
953 | { |
---|
954 | if (dc != null) dc.close(); |
---|
955 | } |
---|
956 | %> |
---|