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