1 | <%-- $Id: edit_event.jsp 3595 2007-07-24 11:11:51Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) Authors contributing to this file. |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 2 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | |
---|
25 | @author Nicklas |
---|
26 | @version 2.0 |
---|
27 | --%> |
---|
28 | <%@ page session="false" |
---|
29 | import="net.sf.basedb.core.SessionControl" |
---|
30 | import="net.sf.basedb.core.DbControl" |
---|
31 | import="net.sf.basedb.core.Item" |
---|
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.Hardware" |
---|
36 | import="net.sf.basedb.core.HardwareType" |
---|
37 | import="net.sf.basedb.core.Include" |
---|
38 | import="net.sf.basedb.core.Plate" |
---|
39 | import="net.sf.basedb.core.PlateType" |
---|
40 | import="net.sf.basedb.core.PlateEvent" |
---|
41 | import="net.sf.basedb.core.PlateEventType" |
---|
42 | import="net.sf.basedb.core.Protocol" |
---|
43 | import="net.sf.basedb.core.ProtocolType" |
---|
44 | import="net.sf.basedb.core.ItemQuery" |
---|
45 | import="net.sf.basedb.core.ItemResultList" |
---|
46 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
47 | import="net.sf.basedb.core.BaseException" |
---|
48 | import="net.sf.basedb.core.query.Hql" |
---|
49 | import="net.sf.basedb.core.query.Restrictions" |
---|
50 | import="net.sf.basedb.core.query.Expressions" |
---|
51 | import="net.sf.basedb.core.query.Orders" |
---|
52 | import="net.sf.basedb.clients.web.Base" |
---|
53 | import="net.sf.basedb.clients.web.WebException" |
---|
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.clients.web.formatter.FormatterFactory" |
---|
58 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
59 | import="java.util.List" |
---|
60 | import="java.util.Set" |
---|
61 | import="java.util.HashSet" |
---|
62 | import="java.util.Date" |
---|
63 | %> |
---|
64 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
65 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
66 | <% |
---|
67 | final Item itemType = Item.PLATEEVENT; |
---|
68 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
69 | final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); |
---|
70 | final int itemId = cc.getId(); |
---|
71 | final int plateId = Values.getInt(request.getParameter("plate_id")); |
---|
72 | final String ID = sc.getId(); |
---|
73 | final float scale = Base.getScale(sc); |
---|
74 | final DbControl dc = sc.newDbControl(); |
---|
75 | try |
---|
76 | { |
---|
77 | String title = null; |
---|
78 | PlateEvent event = null; |
---|
79 | Plate plate = null; |
---|
80 | PlateEventType eventType = null; |
---|
81 | Date eventDate = null; |
---|
82 | |
---|
83 | Protocol currentProtocol = null; |
---|
84 | boolean readCurrentProtocol = true; |
---|
85 | ProtocolType currentProtocolType = null; |
---|
86 | boolean readCurrentProtocolType = true; |
---|
87 | Hardware currentHardware = null; |
---|
88 | boolean readCurrentHardware = true; |
---|
89 | |
---|
90 | // Load recently used items |
---|
91 | List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL); |
---|
92 | List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE); |
---|
93 | |
---|
94 | ItemResultList<PlateEventType> eventTypes = null; |
---|
95 | if (itemId == 0) |
---|
96 | { |
---|
97 | title = "Create event"; |
---|
98 | cc.removeObject("item"); |
---|
99 | |
---|
100 | plate = Plate.getById(dc, plateId); |
---|
101 | ItemQuery<PlateEventType> eventTypesQuery = plate.getPlateType().getEventTypes(); |
---|
102 | eventTypesQuery.order(Orders.asc(Hql.property("ordinal"))); |
---|
103 | eventTypesQuery.join(Hql.leftJoin(null, "plateEvents", "event", |
---|
104 | Restrictions.eq(Hql.property("event", "plate.id"), Expressions.integer(plate.getId())), false)); |
---|
105 | eventTypesQuery.restrict(Restrictions.eq(Hql.alias("event"), null)); |
---|
106 | eventTypes = eventTypesQuery.list(dc); |
---|
107 | if (eventTypes.size() == 0) |
---|
108 | { |
---|
109 | throw new WebException("popup", "No more event types can be created", |
---|
110 | "One event of each event type has already been created for this plate."); |
---|
111 | } |
---|
112 | |
---|
113 | if (cc.getPropertyFilter("protocolType.name") != null) |
---|
114 | { |
---|
115 | currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("protocol.name")); |
---|
116 | } |
---|
117 | |
---|
118 | eventDate = (Date)cc.getPropertyObject("eventDate"); |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | event = PlateEvent.getById(dc, itemId); |
---|
123 | eventType = event.getPlateEventType(); |
---|
124 | eventDate = event.getEventDate(); |
---|
125 | cc.setObject("item", event); |
---|
126 | title = "Edit event -- " + HTML.encodeTags(eventType.getName()); |
---|
127 | try |
---|
128 | { |
---|
129 | currentProtocol = event.getProtocol(); |
---|
130 | } |
---|
131 | catch (PermissionDeniedException ex) |
---|
132 | { |
---|
133 | readCurrentProtocol = false; |
---|
134 | } |
---|
135 | try |
---|
136 | { |
---|
137 | currentProtocolType = eventType.getProtocolType(); |
---|
138 | } |
---|
139 | catch (PermissionDeniedException ex) |
---|
140 | { |
---|
141 | readCurrentProtocolType = false; |
---|
142 | } |
---|
143 | try |
---|
144 | { |
---|
145 | currentHardware = event.getHardware(); |
---|
146 | } |
---|
147 | catch(PermissionDeniedException ex) |
---|
148 | { |
---|
149 | readCurrentHardware = false; |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | if (event != null && !event.hasPermission(Permission.WRITE)) |
---|
154 | { |
---|
155 | throw new PermissionDeniedException(Permission.WRITE, itemType.toString()); |
---|
156 | } |
---|
157 | final String clazz = "class=\"text\""; |
---|
158 | final String requiredClazz = "class=\"text required\""; |
---|
159 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
160 | String dateFormat = FormatterSettings.getDateFormat(sc); |
---|
161 | String jsDateFormat = HTML.javaScriptEncode(dateFormat); |
---|
162 | String htmlDateFormat = HTML.encodeTags(dateFormat); |
---|
163 | %> |
---|
164 | |
---|
165 | <base:page type="popup" title="<%=title%>"> |
---|
166 | <base:head scripts="tabcontrol.js" styles="tabcontrol.css"> |
---|
167 | <script language="JavaScript"> |
---|
168 | // Validate the "Event" tab |
---|
169 | function validateEvent() |
---|
170 | { |
---|
171 | var frm = document.forms['event']; |
---|
172 | return true; |
---|
173 | } |
---|
174 | |
---|
175 | // Submit the form |
---|
176 | function saveSettings() |
---|
177 | { |
---|
178 | var frm = document.forms['event']; |
---|
179 | if (TabControl.validateActiveTab('settings')) |
---|
180 | { |
---|
181 | frm.submit(); |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | var protocolTypeFilter = <%=currentProtocolType != null ? currentProtocolType.getId() : 0%>; |
---|
186 | function selectProtocolOnClick() |
---|
187 | { |
---|
188 | var frm = document.forms['event']; |
---|
189 | var url = '../../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolCallback'; |
---|
190 | if (frm.protocol_id.length > 1) |
---|
191 | { |
---|
192 | var id = Math.abs(parseInt(frm.protocol_id[1].value)); |
---|
193 | url += '&item_id='+id; |
---|
194 | } |
---|
195 | if (protocolTypeFilter) |
---|
196 | { |
---|
197 | url += '&filter:INT:protocolType='+protocolTypeFilter; |
---|
198 | } |
---|
199 | Main.openPopup(url, 'SelectProtocol', 1000, 700); |
---|
200 | } |
---|
201 | function setProtocolCallback(id, name) |
---|
202 | { |
---|
203 | var frm = document.forms['event']; |
---|
204 | var list = frm.protocol_id; |
---|
205 | if (list.length < 2 || list[1].value == '0') // > |
---|
206 | { |
---|
207 | Forms.addListOption(list, 1, new Option()); |
---|
208 | } |
---|
209 | list[1].value = id; |
---|
210 | list[1].text = name; |
---|
211 | list.selectedIndex = 1; |
---|
212 | } |
---|
213 | function selectHardwareOnClick() |
---|
214 | { |
---|
215 | var frm = document.forms['event']; |
---|
216 | var url = '../../../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setHardwareCallback'; |
---|
217 | if (frm.hardware_id.length > 1) |
---|
218 | { |
---|
219 | var id = Math.abs(parseInt(frm.hardware_id[1].value)); |
---|
220 | url += '&item_id='+id; |
---|
221 | } |
---|
222 | Main.openPopup(url, 'SelectHardware', 1000, 700); |
---|
223 | } |
---|
224 | function setHardwareCallback(id, name) |
---|
225 | { |
---|
226 | var frm = document.forms['event']; |
---|
227 | var list = frm.hardware_id; |
---|
228 | if (list.length < 2 || list[1].value == '0') // > |
---|
229 | { |
---|
230 | Forms.addListOption(list, 1, new Option()); |
---|
231 | } |
---|
232 | list[1].value = id; |
---|
233 | list[1].text = name; |
---|
234 | list.selectedIndex = 1; |
---|
235 | } |
---|
236 | |
---|
237 | function init() |
---|
238 | { |
---|
239 | var frm = document.forms['event']; |
---|
240 | plateEventTypeOnChange(); |
---|
241 | } |
---|
242 | <% |
---|
243 | if (event == null) |
---|
244 | { |
---|
245 | %> |
---|
246 | var protocolTypes = new Array(); |
---|
247 | <% |
---|
248 | for (PlateEventType pet : eventTypes) |
---|
249 | { |
---|
250 | try |
---|
251 | { |
---|
252 | ProtocolType pt = pet.getProtocolType(); |
---|
253 | if (pt != null) |
---|
254 | { |
---|
255 | %> |
---|
256 | protocolTypes['P<%=pet.getId()%>'] = <%=pt.getId()%>; |
---|
257 | <% |
---|
258 | } |
---|
259 | } |
---|
260 | catch (Throwable t) |
---|
261 | {} |
---|
262 | } |
---|
263 | } |
---|
264 | %> |
---|
265 | function plateEventTypeOnChange() |
---|
266 | { |
---|
267 | var frm = document.forms['event']; |
---|
268 | if (frm.plateeventtype_id) |
---|
269 | { |
---|
270 | var eventTypeId = frm.plateeventtype_id[frm.plateeventtype_id.selectedIndex].value; |
---|
271 | protocolTypeFilter = protocolTypes['P'+eventTypeId]; |
---|
272 | } |
---|
273 | } |
---|
274 | </script> |
---|
275 | </base:head> |
---|
276 | <base:body onload="init()"> |
---|
277 | <p> |
---|
278 | <form action="index.jsp?ID=<%=ID%>" method="post" name="event" onsubmit="return false;"> |
---|
279 | <input type="hidden" name="cmd" value="UpdateItem"> |
---|
280 | <input type="hidden" name="plate_id" value="<%=plateId%>"> |
---|
281 | |
---|
282 | <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3> |
---|
283 | <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*250)+"px;"%>" |
---|
284 | position="bottom" remember="<%=event != null%>"> |
---|
285 | <t:tab id="info" title="Event" validate="validateEvent()" helpid="plateevent.edit"> |
---|
286 | <table class="form" cellspacing=0> |
---|
287 | <tr> |
---|
288 | <td class="prompt">Event type</td> |
---|
289 | <td> |
---|
290 | <% |
---|
291 | if (event == null) |
---|
292 | { |
---|
293 | %> |
---|
294 | <select name="plateeventtype_id" class="required" onchange="plateEventTypeOnChange()"> |
---|
295 | <% |
---|
296 | for (PlateEventType pet : eventTypes) |
---|
297 | { |
---|
298 | %> |
---|
299 | <option value="<%=pet.getId()%>"><%=pet.getOrdinal()%>. <%=HTML.encodeTags(pet.getName())%> |
---|
300 | <% |
---|
301 | } |
---|
302 | %> |
---|
303 | </select> |
---|
304 | <% |
---|
305 | } |
---|
306 | else |
---|
307 | { |
---|
308 | %> |
---|
309 | <%=eventType.getOrdinal()%>. <%=HTML.encodeTags(eventType.getName())%> |
---|
310 | <% |
---|
311 | } |
---|
312 | %> |
---|
313 | </td> |
---|
314 | </tr> |
---|
315 | <tr> |
---|
316 | <td class="prompt">Event date</td> |
---|
317 | <td> |
---|
318 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
319 | <tr> |
---|
320 | <td> |
---|
321 | <input <%=clazz%> type="text" name="event_date" |
---|
322 | value="<%=dateFormatter.format(eventDate == null ? new Date() : eventDate)%>" |
---|
323 | size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>"> |
---|
324 | |
---|
325 | </td> |
---|
326 | <td> |
---|
327 | <base:button |
---|
328 | onclick="<%="Dates.selectDate('Date', 'event', 'event_date', null, '"+jsDateFormat+"')"%>" |
---|
329 | image="calendar.png" |
---|
330 | title="Calendar…" |
---|
331 | tooltip="Select a date from a calendar" |
---|
332 | /> |
---|
333 | </td> |
---|
334 | </tr> |
---|
335 | </table> |
---|
336 | </td> |
---|
337 | </tr> |
---|
338 | <tr> |
---|
339 | <td class="prompt">Entry date</td> |
---|
340 | <td><%=dateFormatter.format(event == null ? new Date() : event.getEntryDate())%></td> |
---|
341 | </tr> |
---|
342 | <tr> |
---|
343 | <td class="prompt">Protocol</td> |
---|
344 | <td> |
---|
345 | <base:select |
---|
346 | id="protocol_id" |
---|
347 | clazz="selectionlist" |
---|
348 | required="false" |
---|
349 | current="<%=currentProtocol%>" |
---|
350 | denied="<%=!readCurrentProtocol%>" |
---|
351 | recent="<%=recentProtocols%>" |
---|
352 | newitem="<%=event == null%>" |
---|
353 | onselect="selectProtocolOnClick()" |
---|
354 | /> |
---|
355 | </td> |
---|
356 | </tr> |
---|
357 | <tr> |
---|
358 | <td class="prompt">Hardware</td> |
---|
359 | <td> |
---|
360 | <base:select |
---|
361 | id="hardware_id" |
---|
362 | clazz="selectionlist" |
---|
363 | required="false" |
---|
364 | current="<%=currentHardware%>" |
---|
365 | denied="<%=!readCurrentHardware%>" |
---|
366 | recent="<%=recentHardware%>" |
---|
367 | newitem="<%=event == null%>" |
---|
368 | onselect="selectHardwareOnClick()" |
---|
369 | /> |
---|
370 | </td> |
---|
371 | </tr> |
---|
372 | <tr valign=top> |
---|
373 | <td class="prompt">Comment</td> |
---|
374 | <td nowrap> |
---|
375 | <textarea <%=clazz%> rows="4" cols="40" |
---|
376 | name="comment" wrap="virtual"><%=HTML.encodeTags(event == null ? cc.getPropertyValue("comment") : event.getComment())%></textarea> |
---|
377 | <a href="javascript:Main.zoom('Comment', 'event', 'comment')" title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
378 | </td> |
---|
379 | </tr> |
---|
380 | </table> |
---|
381 | <div align=right> <i><base:icon image="required.gif" /> = required information</i></div> |
---|
382 | </t:tab> |
---|
383 | </t:tabcontrol> |
---|
384 | |
---|
385 | <table align="center"> |
---|
386 | <tr> |
---|
387 | <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td> |
---|
388 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
389 | </tr> |
---|
390 | </table> |
---|
391 | </form> |
---|
392 | </base:body> |
---|
393 | </base:page> |
---|
394 | <% |
---|
395 | } |
---|
396 | finally |
---|
397 | { |
---|
398 | if (dc != null) dc.close(); |
---|
399 | } |
---|
400 | %> |
---|