1 | <%-- $Id: edit_protocol.jsp 5631 2011-05-16 12:56:23Z 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 | <% |
---|
57 | final Item itemType = Item.PROTOCOL; |
---|
58 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
59 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
60 | final int itemId = cc.getId(); |
---|
61 | final String ID = sc.getId(); |
---|
62 | final float scale = Base.getScale(sc); |
---|
63 | final DbControl dc = sc.newDbControl(); |
---|
64 | try |
---|
65 | { |
---|
66 | String title = null; |
---|
67 | Protocol protocol = null; |
---|
68 | boolean readCurrentProtocolType = true; |
---|
69 | int currentProtocolTypeId = 0; |
---|
70 | boolean readCurrentFile = true; |
---|
71 | File currentFile = null; |
---|
72 | ItemQuery<AnnotationType> parameterQuery = null; |
---|
73 | |
---|
74 | // Load recently used items |
---|
75 | List<File> recentFiles = (List<File>)cc.getRecent(dc, Item.FILE); |
---|
76 | |
---|
77 | if (itemId == 0) |
---|
78 | { |
---|
79 | title = "Create protocol"; |
---|
80 | |
---|
81 | currentProtocolTypeId = Values.getInt(request.getParameter("protocoltype_id")); |
---|
82 | if (currentProtocolTypeId == 0) |
---|
83 | { |
---|
84 | int recentProtocolTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); |
---|
85 | currentProtocolTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentProtocolTypeId); |
---|
86 | } |
---|
87 | cc.removeObject("item"); |
---|
88 | } |
---|
89 | else |
---|
90 | { |
---|
91 | protocol = Protocol.getById(dc, itemId); |
---|
92 | parameterQuery = protocol.getParameters(); |
---|
93 | cc.setObject("item", protocol); |
---|
94 | title = "Edit protocol -- " + HTML.encodeTags(protocol.getName()); |
---|
95 | try |
---|
96 | { |
---|
97 | ItemSubtype pt = protocol.getItemSubtype(); |
---|
98 | if (pt != null) currentProtocolTypeId = pt.getId(); |
---|
99 | } |
---|
100 | catch (PermissionDeniedException ex) |
---|
101 | { |
---|
102 | readCurrentProtocolType = false; |
---|
103 | } |
---|
104 | try |
---|
105 | { |
---|
106 | currentFile = protocol.getFile(); |
---|
107 | } |
---|
108 | catch (PermissionDeniedException ex) |
---|
109 | { |
---|
110 | readCurrentFile = false; |
---|
111 | } |
---|
112 | } |
---|
113 | if (protocol != null && !protocol.hasPermission(Permission.WRITE)) |
---|
114 | { |
---|
115 | throw new PermissionDeniedException(Permission.WRITE, itemType.toString()); |
---|
116 | } |
---|
117 | |
---|
118 | // Query to retrieve protocol types |
---|
119 | final ItemQuery<ItemSubtype> protocolTypeQuery = ItemSubtype.getQuery(itemType); |
---|
120 | protocolTypeQuery.include(Include.ALL); |
---|
121 | protocolTypeQuery.order(Orders.asc(Hql.property("name"))); |
---|
122 | |
---|
123 | final String clazz = "class=\"text\""; |
---|
124 | final String requiredClazz = "class=\"text required\""; |
---|
125 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), protocol); |
---|
126 | ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext); |
---|
127 | %> |
---|
128 | |
---|
129 | <base:page type="popup" title="<%=title%>"> |
---|
130 | <base:head scripts="tabcontrol.js,annotations.js,linkitems.js,ajax.js,json2.js,subtypes.js" styles="tabcontrol.css"> |
---|
131 | <ext:scripts context="<%=jspContext%>" /> |
---|
132 | <ext:stylesheets context="<%=jspContext%>" /> |
---|
133 | <script language="JavaScript"> |
---|
134 | // Validate the "Protocol" tab |
---|
135 | function validateProtocol() |
---|
136 | { |
---|
137 | var frm = document.forms['protocol']; |
---|
138 | if (Main.trimString(frm.name.value) == '') |
---|
139 | { |
---|
140 | alert("You must enter a name"); |
---|
141 | frm.name.focus(); |
---|
142 | return false; |
---|
143 | } |
---|
144 | return true; |
---|
145 | } |
---|
146 | // Validate the "Parameters" tab |
---|
147 | function validateParameters() |
---|
148 | { |
---|
149 | return true; |
---|
150 | } |
---|
151 | |
---|
152 | // Submit the form |
---|
153 | function saveSettings() |
---|
154 | { |
---|
155 | var frm = document.forms['protocol']; |
---|
156 | if (TabControl.validateActiveTab('settings')) |
---|
157 | { |
---|
158 | if (annotationsLoaded) |
---|
159 | { |
---|
160 | Annotations.addModifiedAnnotationsToForm(frames.annotations, frm); |
---|
161 | } |
---|
162 | frm.addedAnnotationTypes.value = Link.getActionIds(1, 'A').join(','); |
---|
163 | frm.removedAnnotationTypes.value = Link.getActionIds(-1, 'A').join(','); |
---|
164 | frm.submit(); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | var annotationsLoaded = false; |
---|
169 | function switchTab(tabControlId, tabId) |
---|
170 | { |
---|
171 | if (TabControl.setActiveTab(tabControlId, tabId)) |
---|
172 | { |
---|
173 | if (tabId == 'annotations' && !annotationsLoaded) |
---|
174 | { |
---|
175 | Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>); |
---|
176 | annotationsLoaded = true; |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | function browseOnClick() |
---|
182 | { |
---|
183 | var frm = document.forms['protocol']; |
---|
184 | var protocolType = Math.abs(frm.protocoltype_id[frm.protocoltype_id.selectedIndex].value); |
---|
185 | var relatedFileSubtype = ItemSubtype.getRelatedSubtype(protocolType, 'FILE', <%=SystemItems.getId(File.PROTOCOL)%>); |
---|
186 | var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&title=Select+protocol&callback=setFileCallback'; |
---|
187 | url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=' + relatedFileSubtype.id; |
---|
188 | if (frm.file_id.length > 1) |
---|
189 | { |
---|
190 | var id = Math.abs(parseInt(frm.file_id[1].value)); |
---|
191 | url += '&item_id='+id; |
---|
192 | } |
---|
193 | Main.openPopup(url, 'SelectFile', 1000, 700); |
---|
194 | } |
---|
195 | function setFileCallback(id, path) |
---|
196 | { |
---|
197 | var frm = document.forms['protocol']; |
---|
198 | var list = frm.file_id; |
---|
199 | if (list.length < 2 || list[1].value == '0') // > |
---|
200 | { |
---|
201 | Forms.addListOption(list, 1, new Option()); |
---|
202 | } |
---|
203 | list[1].value = id; |
---|
204 | list[1].text = path; |
---|
205 | list.selectedIndex = 1; |
---|
206 | } |
---|
207 | |
---|
208 | function init() |
---|
209 | { |
---|
210 | var frm = document.forms['protocol']; |
---|
211 | <% |
---|
212 | if (protocol == null) |
---|
213 | { |
---|
214 | %> |
---|
215 | frm.name.focus(); |
---|
216 | frm.name.select(); |
---|
217 | <% |
---|
218 | } |
---|
219 | if (parameterQuery != null) |
---|
220 | { |
---|
221 | %> |
---|
222 | var annotationTypes = frm.annotationTypes; |
---|
223 | <% |
---|
224 | parameterQuery.include(Include.ALL); |
---|
225 | parameterQuery.order(Orders.asc(Hql.property("name"))); |
---|
226 | ItemResultList<AnnotationType> parameters = parameterQuery.list(dc); |
---|
227 | for (AnnotationType at : parameters) |
---|
228 | { |
---|
229 | %> |
---|
230 | Link.addNewItem(annotationTypes, new Item('A', <%=at.getId()%>, '<%=HTML.javaScriptEncode(at.getName())%>')); |
---|
231 | <% |
---|
232 | } |
---|
233 | } |
---|
234 | %> |
---|
235 | } |
---|
236 | function addAnnotationTypesOnClick() |
---|
237 | { |
---|
238 | var frm = document.forms['protocol']; |
---|
239 | var ids = Link.getListIds(frm.annotationTypes, 'A'); |
---|
240 | var excludes = ids.join(','); |
---|
241 | var url = '../annotationtypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addAnnotationTypeCallback'; |
---|
242 | url += '&resetTemporary=1&tmpfilter:BOOLEAN:protocolParameter=true'; |
---|
243 | url += "&exclude="+excludes; |
---|
244 | Main.openPopup(url, 'AddAnnotationTypes', 1000, 700); |
---|
245 | } |
---|
246 | function addAnnotationTypeCallback(annotationTypeId, name) |
---|
247 | { |
---|
248 | var item = Link.getItem('A', annotationTypeId); |
---|
249 | if (!item) item = new Item('A', annotationTypeId, name); |
---|
250 | Link.addItem(document.forms['protocol'].annotationTypes, item); |
---|
251 | } |
---|
252 | function removeAnnotationTypesOnClick() |
---|
253 | { |
---|
254 | Link.removeSelected(document.forms['protocol'].annotationTypes); |
---|
255 | } |
---|
256 | </script> |
---|
257 | </base:head> |
---|
258 | <base:body onload="init()"> |
---|
259 | <p> |
---|
260 | <form action="index.jsp?ID=<%=ID%>" method="post" name="protocol" onsubmit="return false;"> |
---|
261 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
262 | |
---|
263 | <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3> |
---|
264 | <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" |
---|
265 | position="bottom" remember="<%=protocol != null%>" switch="switchTab" |
---|
266 | extensions="<%=invoker%>"> |
---|
267 | <t:tab id="info" title="Protocol" validate="validateProtocol()" helpid="protocol.edit"> |
---|
268 | <table class="form" cellspacing=0> |
---|
269 | <tr> |
---|
270 | <td class="prompt">Name</td> |
---|
271 | <td><input <%=requiredClazz%> type="text" name="name" |
---|
272 | value="<%=HTML.encodeTags(protocol == null ? Values.getString(cc.getPropertyValue("name"), "New protocol") : protocol.getName())%>" |
---|
273 | size="40" maxlength="<%=Protocol.MAX_NAME_LENGTH%>"></td> |
---|
274 | </tr> |
---|
275 | <tr valign="top"> |
---|
276 | <td class="prompt">Type</td> |
---|
277 | <td colspan="2"> |
---|
278 | <select name="protocoltype_id" |
---|
279 | <%=!readCurrentProtocolType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>> |
---|
280 | <% |
---|
281 | if (!readCurrentProtocolType) |
---|
282 | { |
---|
283 | %> |
---|
284 | <option value="-1">- denied - |
---|
285 | <% |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | for (ItemSubtype protocolType : protocolTypeQuery.list(dc)) |
---|
290 | { |
---|
291 | int id = protocolType.getId(); |
---|
292 | if (id != currentProtocolTypeId && protocolType.isRemoved()) continue; |
---|
293 | %> |
---|
294 | <option value="<%=id == currentProtocolTypeId && protocol != null ? -id : id%>" |
---|
295 | <%=id == currentProtocolTypeId ? "selected" : ""%> |
---|
296 | ><%=HTML.encodeTags(protocolType.getName())%> |
---|
297 | <% |
---|
298 | } |
---|
299 | } |
---|
300 | %> |
---|
301 | </select> |
---|
302 | </td> |
---|
303 | </tr> |
---|
304 | <tr> |
---|
305 | <td class="prompt">External ID</td> |
---|
306 | <td><input <%=clazz%> type="text" name="external_id" |
---|
307 | value="<%=HTML.encodeTags(protocol == null ? Values.getString(cc.getPropertyValue("externalId"), "") : protocol.getExternalId())%>" |
---|
308 | size="40" maxlength="<%=Protocol.MAX_EXTERNAL_ID_LENGTH%>"></td> |
---|
309 | </tr> |
---|
310 | <tr> |
---|
311 | <td class="prompt">File</td> |
---|
312 | <td> |
---|
313 | <base:select |
---|
314 | id="file_id" |
---|
315 | clazz="selectionlist" |
---|
316 | required="false" |
---|
317 | current="<%=currentFile%>" |
---|
318 | denied="<%=!readCurrentFile%>" |
---|
319 | recent="<%=recentFiles%>" |
---|
320 | newitem="<%=protocol == null%>" |
---|
321 | onselect="browseOnClick()" |
---|
322 | /> |
---|
323 | </td> |
---|
324 | </tr> |
---|
325 | |
---|
326 | <tr valign=top> |
---|
327 | <td class="prompt">Description</td> |
---|
328 | <td nowrap> |
---|
329 | <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual" |
---|
330 | ><%=HTML.encodeTags(protocol == null ? cc.getPropertyValue("description") : protocol.getDescription())%></textarea> |
---|
331 | <a href="javascript:Main.zoom('Description', 'protocol', 'description')" |
---|
332 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
333 | </td> |
---|
334 | </tr> |
---|
335 | </table> |
---|
336 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
337 | </t:tab> |
---|
338 | |
---|
339 | <t:tab id="parameters" title="Parameters" |
---|
340 | validate="validateParameters()" helpid="protocol.edit.parameters"> |
---|
341 | <table class="form" cellspacing=0> |
---|
342 | |
---|
343 | <tr valign="top"> |
---|
344 | <td><b>Annotation types</b> |
---|
345 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
346 | <tr valign="top"> |
---|
347 | <td> |
---|
348 | <select name="annotationTypes" size="10" multiple style="width: 20em;"> |
---|
349 | </select> |
---|
350 | <input type="hidden" name="addedAnnotationTypes" value=""> |
---|
351 | <input type="hidden" name="removedAnnotationTypes" value=""> |
---|
352 | </td> |
---|
353 | <td> |
---|
354 | <table border="0"> |
---|
355 | <tr><td width="150"><base:button |
---|
356 | onclick="addAnnotationTypesOnClick()" |
---|
357 | title="Add annotation types…" |
---|
358 | tooltip="Add annotation types" |
---|
359 | /></td></tr> |
---|
360 | <tr><td width="150"><base:button |
---|
361 | onclick="removeAnnotationTypesOnClick()" |
---|
362 | title="Remove" |
---|
363 | tooltip="Remove the selected annotation types" |
---|
364 | /></td></tr> |
---|
365 | </table> |
---|
366 | </td> |
---|
367 | </tr> |
---|
368 | </table> |
---|
369 | </td> |
---|
370 | </tr> |
---|
371 | </table> |
---|
372 | </t:tab> |
---|
373 | |
---|
374 | <t:tab id="annotations" title="Annotations" |
---|
375 | helpid="annotations.edit" tooltip="Enter values for annotations"> |
---|
376 | <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" |
---|
377 | width="100%" height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0 |
---|
378 | marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe> |
---|
379 | </t:tab> |
---|
380 | |
---|
381 | </t:tabcontrol> |
---|
382 | |
---|
383 | <table align="center"> |
---|
384 | <tr> |
---|
385 | <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td> |
---|
386 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
387 | </tr> |
---|
388 | </table> |
---|
389 | </form> |
---|
390 | </base:body> |
---|
391 | </base:page> |
---|
392 | <% |
---|
393 | } |
---|
394 | finally |
---|
395 | { |
---|
396 | if (dc != null) dc.close(); |
---|
397 | } |
---|
398 | %> |
---|