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

Last change on this file since 2456 was 2456, checked in by Nicklas Nordborg, 16 years ago

TabControl? no longer remembers the last tab when creating new items (the first tab must
always be active in this case)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.2 KB
Line 
1<%-- $Id: edit_event.jsp 2456 2006-06-30 09:45:37Z 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
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.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.ProtocolType"
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.clients.web.util.Values"
54  import="java.util.List"
55  import="java.util.Set"
56  import="java.util.HashSet"
57  import="java.util.Date"
58%>
59<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
60<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
61<%
62final Item itemType = Item.PLATEEVENT;
63final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
64final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
65final int itemId = cc.getId();
66final int plateId = Values.getInt(request.getParameter("plate_id"));
67final String ID = sc.getId();
68final float scale = Base.getScale(sc);
69final DbControl dc = sc.newDbControl();
70try
71{
72  String title = null;
73  PlateEvent event = null;
74  Plate plate = null;
75  PlateEventType eventType = null;
76
77  Protocol currentProtocol = null;
78  boolean readCurrentProtocol = true;
79  ProtocolType currentProtocolType = null;
80  boolean readCurrentProtocolType = true;
81
82  ItemResultList<PlateEventType> eventTypes = null;
83  if (itemId == 0)
84  {
85    title = "Create event";
86    cc.removeObject("item");
87   
88    plate = Plate.getById(dc, plateId);
89    ItemQuery<PlateEventType> eventTypesQuery = plate.getPlateType().getEventTypes();
90    eventTypesQuery.order(Orders.asc(Hql.property("ordinal")));
91    eventTypesQuery.join(Hql.leftJoin(null, "plateEvents", "event", 
92      Restrictions.eq(Hql.property("event", "plate"), Hql.entity(plate))));
93    eventTypesQuery.restrict(Restrictions.eq(Hql.alias("event"), null));
94    eventTypes = eventTypesQuery.list(dc);
95    if (eventTypes.size() == 0)
96    {
97      throw new WebException("popup", "No more event types can be created", 
98        "One event of each event type has already been created for this plate.");
99    }
100   
101   
102    if (cc.getPropertyFilter("protocolType.name") != null)
103    {
104      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("protocol.name"));
105    }
106  }
107  else
108  {
109    event = PlateEvent.getById(dc, itemId);
110    eventType = event.getPlateEventType();
111    cc.setObject("item", event);
112    title = "Edit event  -- " + HTML.encodeTags(eventType.getName());
113    try
114    {
115      currentProtocol = event.getProtocol();
116    }
117    catch (PermissionDeniedException ex)
118    {
119      readCurrentProtocol = false;
120    }
121    try
122    {
123      currentProtocolType = eventType.getProtocolType();
124    }
125    catch (PermissionDeniedException ex)
126    {
127      readCurrentProtocolType = false;
128    }
129  }
130 
131  if (event != null && !event.hasPermission(Permission.WRITE))
132  {
133    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
134  }
135  final String clazz = "class=\"text\"";
136  final String requiredClazz = "class=\"text required\"";
137  %>
138
139  <base:page type="popup" title="<%=title%>">
140  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
141    <script language="JavaScript">
142    // Validate the "Event" tab
143    function validateEvent()
144    {
145      var frm = document.forms['event'];
146      return true;
147    }
148
149    // Submit the form
150    function saveSettings()
151    {
152      var frm = document.forms['event'];
153      if (TabControl.validateActiveTab('settings'))
154      {
155        frm.submit();
156      }
157    }
158   
159    var protocolTypeFilter = <%=currentProtocolType != null ? currentProtocolType.getId() : 0%>;
160    function selectProtocolOnClick()
161    {
162      var frm = document.forms['event'];
163      var url = '../../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolCallback';
164      if (frm.protocol_id.length > 1)
165      {
166        var id = Math.abs(parseInt(frm.protocol_id[1].value));       
167        url += '&item_id='+id;
168      }
169      if (protocolTypeFilter)
170      {
171        url += '&filter:INT:protocolType='+protocolTypeFilter;
172      }
173      Main.openPopup(url, 'SelectProtocol', 1000, 700);
174    }
175    function setProtocolCallback(protocolId, name)
176    {
177      var frm = document.forms['event'];
178      if (frm.protocol_id.length < 2) // >
179      {
180        frm.protocol_id[frm.protocol_id.length] = new Option();
181      }
182      frm.protocol_id[1].value = protocolId;
183      frm.protocol_id[1].text = name;
184      frm.protocol_id.selectedIndex = 1;
185    }
186
187    function init()
188    {
189      var frm = document.forms['event'];
190      plateEventTypeOnChange();
191    }
192    <%
193    if (event == null)
194    {
195      %>
196      var protocolTypes = new Array();
197      <%
198      for (PlateEventType pet : eventTypes)
199      {
200        try
201        {
202          ProtocolType pt = pet.getProtocolType();
203          if (pt != null)
204          {
205            %>
206            protocolTypes['P<%=pet.getId()%>'] = <%=pt.getId()%>;
207            <%
208          }
209        }
210        catch (Throwable t)
211        {}
212      }
213    }
214    %>
215    function plateEventTypeOnChange()
216    {
217      var frm = document.forms['event'];
218      if (frm.plateeventtype_id)
219      {
220        var eventTypeId = frm.plateeventtype_id[frm.plateeventtype_id.selectedIndex].value;
221        protocolTypeFilter = protocolTypes['P'+eventTypeId];
222      }
223    }
224    </script>
225  </base:head>
226  <base:body onload="init()">
227    <p>
228    <form action="index.jsp?ID=<%=ID%>" method="post" name="event" onsubmit="return false;">
229    <input type="hidden" name="cmd" value="UpdateItem">
230    <input type="hidden" name="plate_id" value="<%=plateId%>">
231
232    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
233    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*250)+"px;"%>" 
234      position="bottom" remember="<%=event != null%>">
235    <t:tab id="info" title="Event" validate="validateEvent()" helpid="plateevent.edit">
236      <table class="form" cellspacing=0>
237      <tr>
238        <td class="prompt">Event type</td>
239        <td>
240          <%
241          if (event == null)
242          {
243            %>
244            <select name="plateeventtype_id" class="required" onchange="plateEventTypeOnChange()">
245            <%
246            for (PlateEventType pet : eventTypes)
247            {
248              %>
249              <option value="<%=pet.getId()%>"><%=pet.getOrdinal()%>. <%=HTML.encodeTags(pet.getName())%>
250              <%
251            }
252            %>
253            </select>
254            <%
255          }
256          else
257          {
258            %>
259            <%=eventType.getOrdinal()%>. <%=HTML.encodeTags(eventType.getName())%>
260            <%
261          }
262          %>
263        </td>
264      </tr>
265      <tr>
266        <td class="prompt">Event date</td>
267        <td>
268          <table border="0" cellspacing="0" cellpadding="0">
269          <tr>
270          <td>
271            <input <%=clazz%> type="text" name="event_date" 
272              value="<%=Values.formatDate(event == null ? Values.getDate(cc.getPropertyValue("eventDate"), new Date()) : event.getEventDate())%>" 
273              size="12" maxlength="10" onkeypress="return Dates.dateOnly(event)">
274            (yyyy-mm-dd)&nbsp;
275          </td>
276          <td>
277          <base:button 
278            onclick="Dates.selectDate('Date', 'event', 'event_date')" 
279            image="calendar.png"
280            title="Calendar&hellip;" 
281            tooltip="Select a date from a calendar" 
282          />
283          </td>
284          </tr>
285          </table>
286        </td>
287      </tr>
288      <tr>
289        <td class="prompt">Entry date</td>
290        <td><%=Values.formatDate(event == null ? new Date() : event.getEntryDate())%></td>
291      </tr>
292      <tr>
293        <td class="prompt">Protocol</td>
294        <td>
295          <table border="0" cellspacing="0" cellpadding="0">
296          <tr>
297          <td>
298            <select name="protocol_id" size="1" 
299              <%=!readCurrentProtocol ? "disabled readonly class=\"disabled\"" : ""%>
300              style="width: 20em;">
301            <%
302            if (!readCurrentProtocol)
303            {
304              %>
305              <option value="-1">- denied -
306              <%
307            }
308            else
309            {
310              %>
311              <option value="0">- none -
312              <%
313              if (currentProtocol != null)
314              {
315                %>
316                <option value="<%=event == null ? currentProtocol.getId() : -currentProtocol.getId()%>" 
317                  selected><%=HTML.encodeTags(currentProtocol.getName())%>
318                <%
319              }
320            }
321            %>
322            </select>
323            &nbsp;
324          </td>
325          <td><base:button onclick="selectProtocolOnClick()" 
326            title="Select&hellip;" disabled="<%=!readCurrentProtocol%>" /></td>
327          </tr>
328          </table>
329        </td>
330      </tr>
331      <tr valign=top>
332        <td class="prompt">Comment</td>
333        <td nowrap>
334          <textarea <%=clazz%> rows="4" cols="40" 
335            name="comment" wrap="virtual"><%=HTML.encodeTags(event == null ? cc.getPropertyValue("comment") : event.getComment())%></textarea>
336          <a href="javascript:Main.zoom('Comment', 'event', 'comment')" title="Edit in larger window"><base:icon image="zoom.gif" /></a>
337        </td>
338      </tr>
339      </table>
340      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
341    </t:tab>
342    </t:tabcontrol>
343
344    <table align="center">
345    <tr>
346      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
347      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
348    </tr>
349    </table>
350    </form>
351  </base:body>
352  </base:page>
353  <%
354}
355finally
356{
357  if (dc != null) dc.close();
358}
359%>
Note: See TracBrowser for help on using the repository browser.