source: trunk/www/lims/plates/events/edit_event.jsp @ 5908

Last change on this file since 5908 was 5908, checked in by Nicklas Nordborg, 10 years ago

References #1655: GUI improvements

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