1 | <%-- $Id: edit_protocol.jsp 6254 2013-03-22 07:28:26Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
---|
5 | |
---|
6 | This file is part of BASE - BioArray Software Environment. |
---|
7 | Available at http://base.thep.lu.se/ |
---|
8 | |
---|
9 | BASE is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License |
---|
11 | as published by the Free Software Foundation; either version 3 |
---|
12 | of the License, or (at your option) any later version. |
---|
13 | |
---|
14 | BASE is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | ------------------------------------------------------------------ |
---|
22 | |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page pageEncoding="UTF-8" session="false" |
---|
28 | import="net.sf.basedb.core.SessionControl" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.ItemContext" |
---|
32 | import="net.sf.basedb.core.Permission" |
---|
33 | import="net.sf.basedb.core.Protocol" |
---|
34 | import="net.sf.basedb.core.ItemSubtype" |
---|
35 | import="net.sf.basedb.core.AnnotationType" |
---|
36 | import="net.sf.basedb.core.File" |
---|
37 | import="net.sf.basedb.core.SystemItems" |
---|
38 | import="net.sf.basedb.core.ItemQuery" |
---|
39 | import="net.sf.basedb.core.ItemResultList" |
---|
40 | import="net.sf.basedb.core.Include" |
---|
41 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
42 | import="net.sf.basedb.core.query.Orders" |
---|
43 | import="net.sf.basedb.core.query.Hql" |
---|
44 | import="net.sf.basedb.clients.web.Base" |
---|
45 | import="net.sf.basedb.clients.web.util.HTML" |
---|
46 | import="net.sf.basedb.util.Values" |
---|
47 | import="net.sf.basedb.core.plugin.GuiContext" |
---|
48 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
49 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
50 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
51 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
52 | import="java.util.List" |
---|
53 | %> |
---|
54 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
55 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
56 | <%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %> |
---|
57 | <% |
---|
58 | final Item itemType = Item.PROTOCOL; |
---|
59 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
60 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
61 | final int itemId = cc.getId(); |
---|
62 | final String ID = sc.getId(); |
---|
63 | final float scale = Base.getScale(sc); |
---|
64 | final DbControl dc = sc.newDbControl(); |
---|
65 | try |
---|
66 | { |
---|
67 | String title = null; |
---|
68 | Protocol protocol = null; |
---|
69 | boolean readCurrentSubtype = true; |
---|
70 | int currentSubtypeId = 0; |
---|
71 | boolean readCurrentFile = true; |
---|
72 | File currentFile = null; |
---|
73 | ItemQuery<AnnotationType> parameterQuery = null; |
---|
74 | |
---|
75 | // Load recently used items |
---|
76 | List<File> recentFiles = (List<File>)cc.getRecent(dc, Item.FILE); |
---|
77 | |
---|
78 | if (itemId == 0) |
---|
79 | { |
---|
80 | title = "Create protocol"; |
---|
81 | |
---|
82 | currentSubtypeId = Values.getInt(request.getParameter("subtype_id")); |
---|
83 | if (currentSubtypeId == 0) |
---|
84 | { |
---|
85 | int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); |
---|
86 | currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId); |
---|
87 | } |
---|
88 | cc.removeObject("item"); |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | protocol = Protocol.getById(dc, itemId); |
---|
93 | protocol.checkPermission(Permission.WRITE); |
---|
94 | |
---|
95 | parameterQuery = protocol.getParameters(); |
---|
96 | cc.setObject("item", protocol); |
---|
97 | title = "Edit protocol -- " + HTML.encodeTags(protocol.getName()); |
---|
98 | try |
---|
99 | { |
---|
100 | ItemSubtype subtype = protocol.getItemSubtype(); |
---|
101 | if (subtype != null) currentSubtypeId = subtype.getId(); |
---|
102 | } |
---|
103 | catch (PermissionDeniedException ex) |
---|
104 | { |
---|
105 | readCurrentSubtype = false; |
---|
106 | } |
---|
107 | try |
---|
108 | { |
---|
109 | currentFile = protocol.getFile(); |
---|
110 | } |
---|
111 | catch (PermissionDeniedException ex) |
---|
112 | { |
---|
113 | readCurrentFile = false; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | // Query to retrieve protocol types |
---|
118 | final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType); |
---|
119 | subtypesQuery.include(Include.ALL); |
---|
120 | |
---|
121 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), protocol); |
---|
122 | ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext); |
---|
123 | %> |
---|
124 | <base:page type="popup" title="<%=title%>"> |
---|
125 | <base:head scripts="tabcontrol.js,linkitems.js,subtypes.js" styles="tabcontrol.css"> |
---|
126 | <ext:scripts context="<%=jspContext%>" /> |
---|
127 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
128 | <script> |
---|
129 | // Validate the "Protocol" tab |
---|
130 | function validateProtocol() |
---|
131 | { |
---|
132 | var frm = document.forms['protocol']; |
---|
133 | if (Main.trimString(frm.name.value) == '') |
---|
134 | { |
---|
135 | Forms.showNotification(frm.name, 'You must enter a name'); |
---|
136 | return false; |
---|
137 | } |
---|
138 | return true; |
---|
139 | } |
---|
140 | // Validate the "Parameters" tab |
---|
141 | function validateParameters() |
---|
142 | { |
---|
143 | return true; |
---|
144 | } |
---|
145 | |
---|
146 | // Submit the form |
---|
147 | function saveSettings() |
---|
148 | { |
---|
149 | var frm = document.forms['protocol']; |
---|
150 | if (TabControl.validateActiveTab('settings')) |
---|
151 | { |
---|
152 | Annotations.saveModifiedAnnotationsToForm(frm); |
---|
153 | frm.addedAnnotationTypes.value = Link.getActionIds(1, 'A').join(','); |
---|
154 | frm.removedAnnotationTypes.value = Link.getActionIds(-1, 'A').join(','); |
---|
155 | frm.submit(); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | function loadAnnotationsFrame() |
---|
160 | { |
---|
161 | Annotations.autoLoadEditFrame(null, ItemSubtype.getSubtypeId('protocol')); |
---|
162 | } |
---|
163 | |
---|
164 | function browseOnClick() |
---|
165 | { |
---|
166 | var frm = document.forms['protocol']; |
---|
167 | var subtype = Math.abs(frm.subtype_id[frm.subtype_id.selectedIndex].value); |
---|
168 | var relatedFileSubtype = ItemSubtype.getRelatedSubtype(subtype, 'FILE', <%=SystemItems.getId(File.PROTOCOL)%>); |
---|
169 | var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&title=Select+protocol+file&callback=setFileCallback'; |
---|
170 | url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=' + relatedFileSubtype.id; |
---|
171 | if (frm.file_id.length > 1) |
---|
172 | { |
---|
173 | var id = Math.abs(parseInt(frm.file_id[1].value)); |
---|
174 | url += '&item_id='+id; |
---|
175 | } |
---|
176 | Main.openPopup(url, 'SelectFile', 1050, 700); |
---|
177 | } |
---|
178 | function setFileCallback(id, path) |
---|
179 | { |
---|
180 | var frm = document.forms['protocol']; |
---|
181 | var list = frm.file_id; |
---|
182 | if (list.length < 2 || list[1].value == '0') // > |
---|
183 | { |
---|
184 | Forms.addListOption(list, 1, new Option()); |
---|
185 | } |
---|
186 | list[1].value = id; |
---|
187 | list[1].text = path; |
---|
188 | list.selectedIndex = 1; |
---|
189 | } |
---|
190 | |
---|
191 | function init() |
---|
192 | { |
---|
193 | var frm = document.forms['protocol']; |
---|
194 | <% |
---|
195 | if (protocol == null) |
---|
196 | { |
---|
197 | %> |
---|
198 | frm.name.focus(); |
---|
199 | frm.name.select(); |
---|
200 | subtypeOnChange(); |
---|
201 | <% |
---|
202 | } |
---|
203 | if (parameterQuery != null) |
---|
204 | { |
---|
205 | %> |
---|
206 | var annotationTypes = frm.annotationTypes; |
---|
207 | <% |
---|
208 | parameterQuery.include(Include.ALL); |
---|
209 | parameterQuery.order(Orders.asc(Hql.property("name"))); |
---|
210 | ItemResultList<AnnotationType> parameters = parameterQuery.list(dc); |
---|
211 | for (AnnotationType at : parameters) |
---|
212 | { |
---|
213 | %> |
---|
214 | Link.addNewItem(annotationTypes, new Item('A', <%=at.getId()%>, '<%=HTML.javaScriptEncode(at.getName())%>')); |
---|
215 | <% |
---|
216 | } |
---|
217 | } |
---|
218 | %> |
---|
219 | } |
---|
220 | function addAnnotationTypesOnClick() |
---|
221 | { |
---|
222 | var frm = document.forms['protocol']; |
---|
223 | var ids = Link.getListIds(frm.annotationTypes, 'A'); |
---|
224 | var excludes = ids.join(','); |
---|
225 | var url = '../annotationtypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addAnnotationTypeCallback'; |
---|
226 | url += '&resetTemporary=1&tmpfilter:BOOLEAN:protocolParameter=true'; |
---|
227 | url += "&exclude="+excludes; |
---|
228 | Main.openPopup(url, 'AddAnnotationTypes', 1050, 700); |
---|
229 | } |
---|
230 | function addAnnotationTypeCallback(annotationTypeId, name) |
---|
231 | { |
---|
232 | var item = Link.getItem('A', annotationTypeId); |
---|
233 | if (!item) item = new Item('A', annotationTypeId, name); |
---|
234 | Link.addItem(document.forms['protocol'].annotationTypes, item); |
---|
235 | } |
---|
236 | function removeAnnotationTypesOnClick() |
---|
237 | { |
---|
238 | Link.removeSelected(document.forms['protocol'].annotationTypes); |
---|
239 | } |
---|
240 | |
---|
241 | function subtypeOnChange() |
---|
242 | { |
---|
243 | var frm = document.forms['protocol']; |
---|
244 | if (frm.replaceExistingDefault) |
---|
245 | { |
---|
246 | var subtypeId = ItemSubtype.getSubtypeId('protocol'); |
---|
247 | var defaultInfo = ItemSubtype.getRecentAndDefaultInfo(subtypeId, 'PROTOCOL'); |
---|
248 | var currentDefaultDiv = document.getElementById('currentDefault'); |
---|
249 | |
---|
250 | var tooltip = ''; |
---|
251 | var html = ''; |
---|
252 | var checked = true; |
---|
253 | var disabled = false; |
---|
254 | |
---|
255 | var numDefaults = defaultInfo['default'] ? defaultInfo['default'].length : 0; |
---|
256 | if (numDefaults == 1) |
---|
257 | { |
---|
258 | html = '('+Main.encodeTags(Main.cutString(defaultInfo['default'][0].name, 40)) + ')'; |
---|
259 | } |
---|
260 | else if (numDefaults == 0) |
---|
261 | { |
---|
262 | html = '(-none-)'; |
---|
263 | checked = false; |
---|
264 | disabled = true; |
---|
265 | } |
---|
266 | else |
---|
267 | { |
---|
268 | html = '(' + numDefaults + ' different)'; |
---|
269 | for (var i = 0; i < numDefaults; i++) |
---|
270 | { |
---|
271 | tooltip += Main.encodeTags(defaultInfo['default'][i].name) + '\n'; |
---|
272 | } |
---|
273 | checked = false; |
---|
274 | } |
---|
275 | |
---|
276 | currentDefaultDiv.title = tooltip; |
---|
277 | currentDefaultDiv.innerHTML = html; |
---|
278 | frm.replaceExistingDefault.checked = checked; |
---|
279 | frm.replaceExistingDefault.disabled = disabled; |
---|
280 | } |
---|
281 | } |
---|
282 | </script> |
---|
283 | </base:head> |
---|
284 | <base:body onload="init()"> |
---|
285 | <h1><%=title%> <base:help tabcontrol="settings" /></h1> |
---|
286 | <form action="index.jsp?ID=<%=ID%>" method="post" name="protocol"> |
---|
287 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
288 | |
---|
289 | <t:tabcontrol id="settings" |
---|
290 | subclass="content dialogtabcontrol" |
---|
291 | position="bottom" remember="<%=protocol != null%>" |
---|
292 | extensions="<%=invoker%>"> |
---|
293 | <t:tab id="info" title="Protocol" validate="validateProtocol()" helpid="protocol.edit"> |
---|
294 | <table class="fullform input100 smaller"> |
---|
295 | <tr> |
---|
296 | <th>Name</th> |
---|
297 | <td><input class="text required" type="text" name="name" |
---|
298 | value="<%=HTML.encodeTags(protocol == null ? Values.getString(cc.getPropertyValue("name"), "New protocol") : protocol.getName())%>" |
---|
299 | maxlength="<%=Protocol.MAX_NAME_LENGTH%>"></td> |
---|
300 | <td></td> |
---|
301 | </tr> |
---|
302 | <tr> |
---|
303 | <th>Type</th> |
---|
304 | <td> |
---|
305 | <select name="subtype_id" |
---|
306 | <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%> |
---|
307 | onchange="subtypeOnChange()" |
---|
308 | > |
---|
309 | <% |
---|
310 | if (!readCurrentSubtype) |
---|
311 | { |
---|
312 | %> |
---|
313 | <option value="-1">- denied - |
---|
314 | <% |
---|
315 | } |
---|
316 | else |
---|
317 | { |
---|
318 | %> |
---|
319 | <option value="0">-none- |
---|
320 | <% |
---|
321 | for (ItemSubtype subtype : subtypesQuery.list(dc)) |
---|
322 | { |
---|
323 | int id = subtype.getId(); |
---|
324 | if (id != currentSubtypeId && subtype.isRemoved()) continue; |
---|
325 | %> |
---|
326 | <option value="<%=id == currentSubtypeId && protocol != null ? -id : id%>" |
---|
327 | <%=id == currentSubtypeId ? "selected" : ""%> |
---|
328 | title="<%=HTML.encodeTags(subtype.getDescription()) %>" |
---|
329 | ><%=HTML.encodeTags(subtype.getName())%> |
---|
330 | <% |
---|
331 | } |
---|
332 | } |
---|
333 | %> |
---|
334 | </select> |
---|
335 | </td> |
---|
336 | <td></td> |
---|
337 | </tr> |
---|
338 | <tr> |
---|
339 | <th>External ID</th> |
---|
340 | <td><input class="text" type="text" name="external_id" |
---|
341 | value="<%=HTML.encodeTags(protocol == null ? Values.getString(cc.getPropertyValue("externalId"), "") : protocol.getExternalId())%>" |
---|
342 | maxlength="<%=Protocol.MAX_EXTERNAL_ID_LENGTH%>"></td> |
---|
343 | <td></td> |
---|
344 | </tr> |
---|
345 | <tr> |
---|
346 | <th>File</th> |
---|
347 | <td> |
---|
348 | <base:select |
---|
349 | id="file_id" |
---|
350 | clazz="selectionlist" |
---|
351 | required="false" |
---|
352 | current="<%=currentFile%>" |
---|
353 | denied="<%=!readCurrentFile%>" |
---|
354 | recent="<%=recentFiles%>" |
---|
355 | newitem="<%=protocol == null%>" |
---|
356 | onselect="browseOnClick()" |
---|
357 | /> |
---|
358 | </td> |
---|
359 | <td></td> |
---|
360 | </tr> |
---|
361 | <tr class="dynamic"> |
---|
362 | <th>Description</th> |
---|
363 | <td> |
---|
364 | <textarea class="text" rows="6" name="description" id="description" |
---|
365 | ><%=HTML.encodeTags(protocol == null ? cc.getPropertyValue("description") : protocol.getDescription())%></textarea> |
---|
366 | </td> |
---|
367 | <td style="width: 20px;"> |
---|
368 | <base:zoom textarea="description" title="Description" /> |
---|
369 | </td> |
---|
370 | </tr> |
---|
371 | <% |
---|
372 | if (sc.getActiveProjectId() != 0 && protocol == null && sc.getActiveProjectPermissions().contains(Permission.WRITE)) |
---|
373 | { |
---|
374 | %> |
---|
375 | <tr> |
---|
376 | <th></th> |
---|
377 | <td style="white-space: nowrap; overflow: hidden; padding-bottom: 2px;"> |
---|
378 | <input type="checkbox" id="setAsProjectDefault" name="setAsProjectDefault" value="1" |
---|
379 | checked><label for="setAsProjectDefault">Add as project default</label><br> |
---|
380 | <input type="checkbox" id="replaceExistingDefault" name="replaceExistingDefault" value="1" |
---|
381 | checked><label for="replaceExistingDefault">Replace existing default</label> |
---|
382 | <span id="currentDefault" style="font-style: italic;"></span> |
---|
383 | </td> |
---|
384 | <td></td> |
---|
385 | </tr> |
---|
386 | <% |
---|
387 | } |
---|
388 | %> |
---|
389 | </table> |
---|
390 | </t:tab> |
---|
391 | |
---|
392 | <t:tab id="parameters" title="Parameters" |
---|
393 | validate="validateParameters()" helpid="protocol.edit.parameters"> |
---|
394 | <table class="fullform input100"> |
---|
395 | <tr class="big"> |
---|
396 | <th>Annotation types</th> |
---|
397 | <td> |
---|
398 | <div class="selectionlist"> |
---|
399 | <table> |
---|
400 | <tr> |
---|
401 | <td> |
---|
402 | <select name="annotationTypes" size="20" multiple> |
---|
403 | </select> |
---|
404 | </td> |
---|
405 | <td style="vertical-align: top;"> |
---|
406 | <base:buttongroup vertical="true"> |
---|
407 | <base:button |
---|
408 | subclass="leftaligned" |
---|
409 | style="width: 15em;" |
---|
410 | onclick="addAnnotationTypesOnClick()" |
---|
411 | title="Add annotation types…" |
---|
412 | tooltip="Add annotation types" |
---|
413 | /> |
---|
414 | <base:button |
---|
415 | subclass="leftaligned" |
---|
416 | style="width: 15em;" |
---|
417 | onclick="removeAnnotationTypesOnClick()" |
---|
418 | title="Remove" |
---|
419 | tooltip="Remove the selected annotation types" |
---|
420 | /> |
---|
421 | </base:buttongroup> |
---|
422 | <input type="hidden" name="addedAnnotationTypes" value=""> |
---|
423 | <input type="hidden" name="removedAnnotationTypes" value=""> |
---|
424 | </td> |
---|
425 | </tr> |
---|
426 | </table> |
---|
427 | </div> |
---|
428 | </td> |
---|
429 | </tr> |
---|
430 | <tr class="dynamic"> |
---|
431 | <th></th> |
---|
432 | <td></td> |
---|
433 | </tr> |
---|
434 | </table> |
---|
435 | </t:tab> |
---|
436 | |
---|
437 | <t:tab id="annotations" title="Annotations" helpid="annotations.edit" activate="loadAnnotationsFrame()"> |
---|
438 | <jsp:include page="../../common/annotations/annotate_frameset.jsp"> |
---|
439 | <jsp:param name="item_type" value="<%=itemType.name()%>" /> |
---|
440 | <jsp:param name="item_id" value="<%=itemId%>" /> |
---|
441 | <jsp:param name="ID" value="<%=ID%>" /> |
---|
442 | </jsp:include> |
---|
443 | </t:tab> |
---|
444 | </t:tabcontrol> |
---|
445 | </form> |
---|
446 | |
---|
447 | <div class="legend"> |
---|
448 | <base:icon image="required.png" />= required information |
---|
449 | </div> |
---|
450 | |
---|
451 | <base:buttongroup subclass="dialogbuttons"> |
---|
452 | <base:button onclick="saveSettings()" title="Save" /> |
---|
453 | <base:button onclick="window.close()" title="Cancel" /> |
---|
454 | </base:buttongroup> |
---|
455 | </base:body> |
---|
456 | </base:page> |
---|
457 | <% |
---|
458 | } |
---|
459 | finally |
---|
460 | { |
---|
461 | if (dc != null) dc.close(); |
---|
462 | } |
---|
463 | %> |
---|