source: trunk/www/lims/platetypes/eventtypes/edit_eventtype.jsp @ 5920

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

References #1655: GUI improvements

Edit dialogs in plates section of Array LIMS.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1<%-- $Id: edit_eventtype.jsp 5920 2012-01-10 09:41:59Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.SystemItems"
32  import="net.sf.basedb.core.Permission"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.PlateType"
35  import="net.sf.basedb.core.PlateEventType"
36  import="net.sf.basedb.core.ItemSubtype"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.BaseException"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Hql"
43  import="net.sf.basedb.clients.web.Base"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.core.plugin.GuiContext"
47  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
48  import="net.sf.basedb.clients.web.extensions.JspContext"
49  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
50  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
51  import="java.util.List"
52  import="java.util.Set"
53  import="java.util.HashSet"
54  import="java.util.Date"
55%>
56<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
57<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
58<%
59final Item itemType = Item.PLATEEVENTTYPE;
60final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
61final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
62final int itemId = cc.getId();
63final int plateTypeId = Values.getInt(request.getParameter("platetype_id"));
64final String ID = sc.getId();
65final float scale = Base.getScale(sc);
66final DbControl dc = sc.newDbControl();
67try
68{
69  String title = null;
70  PlateEventType eventType = null;
71  PlateType plateType = null;
72 
73  ItemSubtype currentProtocolType = null;
74  boolean readCurrentProtocolType = true;
75  int maxOrdinal = 0;
76 
77  // Load recently used items
78  List<ItemSubtype> recentProtocolTypes = (List<ItemSubtype>)cc.getRecent(dc, Item.ITEMSUBTYPE);
79
80  if (itemId == 0)
81  {
82    title = "Create event type";
83    cc.removeObject("item");
84    plateType = PlateType.getById(dc, plateTypeId);
85    if (cc.getPropertyFilter("protocolType.name") != null)
86    {
87      currentProtocolType = Base.getFirstMatching(dc, ItemSubtype.getQuery(Item.PROTOCOL), "name", cc.getPropertyFilter("protocolType.name"));
88    }
89    maxOrdinal = (int)plateType.getEventTypes().count(dc);
90  }
91  else
92  {
93    eventType = PlateEventType.getById(dc, itemId);
94    plateType = eventType.getPlateType();
95    cc.setObject("item", eventType);
96    title = "Edit event type -- " + HTML.encodeTags(plateType.getName());
97    try
98    {
99      currentProtocolType = eventType.getProtocolType();
100    }
101    catch (PermissionDeniedException ex)
102    {
103      readCurrentProtocolType = false;
104    }
105  }
106  if (eventType != null && !eventType.hasPermission(Permission.WRITE))
107  {
108    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
109  }
110  final String clazz = "class=\"text\"";
111  final String requiredClazz = "class=\"text required\"";
112  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), eventType);
113  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
114  %>
115  <base:page type="popup" title="<%=title%>">
116  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
117    <ext:scripts context="<%=jspContext%>" />
118    <ext:stylesheets context="<%=jspContext%>" />
119    <script language="JavaScript">
120    // Validate the "EventType" tab
121    function validateEventType()
122    {
123      var frm = document.forms['eventtype'];
124      if (Main.trimString(frm.name.value) == '')
125      {
126        alert("You must enter a name");
127        frm.name.focus();
128        return false;
129      }
130      else if (Main.trimString(frm.ordinal.value) == '')
131      {
132        alert("You must enter an ordinal");
133        frm.ordinal.focus();
134        return false;
135      }
136      return true;
137    }
138
139    // Submit the form
140    function saveSettings()
141    {
142      var frm = document.forms['eventtype'];
143      if (TabControl.validateActiveTab('settings'))
144      {
145        frm.submit();
146      }
147    }
148   
149    function selectProtocolTypeOnClick()
150    {
151      var frm = document.forms['eventtype'];
152      var url = '../../../admin/itemsubtypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolTypeCallback';
153      url += '&resetTemporary=1&tmpfilter:INT:itemType=<%=Item.PROTOCOL.getValue()%>';
154      if (frm.protocoltype_id.length > 1)
155      {
156        var id = Math.abs(parseInt(frm.protocoltype_id[1].value));       
157        url += '&item_id='+id;
158      }
159      Main.openPopup(url, 'SelectProtocolType', 1000, 700);
160    }
161    function setProtocolTypeCallback(id, name)
162    {
163      var frm = document.forms['eventtype'];
164      var list = frm.protocoltype_id;
165      if (list.length < 2 || list[1].value == '0') // >
166      {
167        Forms.addListOption(list, 1, new Option());
168      }
169      list[1].value = id;
170      list[1].text = name;
171      list.selectedIndex = 1;
172    }
173   
174    function init()
175    {
176      var frm = document.forms['eventtype'];
177      <%
178      if (eventType == null)
179      {
180        %>
181        frm.name.focus();
182        frm.name.select();
183        <%
184      }
185      %>
186    }
187    </script>
188  </base:head>
189  <base:body onload="init()">
190    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
191   
192    <form action="index.jsp?ID=<%=ID%>" method="post" name="eventtype" onsubmit="return false;">
193    <input type="hidden" name="cmd" value="UpdateItem">
194    <input type="hidden" name="platetype_id" value="<%=plateTypeId%>">
195
196    <t:tabcontrol id="settings"
197      subclass="content dialogtabcontrol"
198      position="bottom" remember="<%=eventType != null%>"
199      extensions="<%=invoker%>">
200    <t:tab id="info" title="Event type" validate="validateEventType()" helpid="plateeventtype.edit">
201      <table class="fullform input100 smaller">
202      <tr>
203        <th>Name</th>
204        <td><input <%=requiredClazz%> type="text" name="name" 
205          value="<%=HTML.encodeTags(eventType == null ? Values.getString(cc.getPropertyValue("name"), "New event type") : eventType.getName())%>" 
206          maxlength="<%=PlateEventType.MAX_NAME_LENGTH%>"></td>
207        <td></td>
208      </tr>
209      <tr>
210        <th>Ordinal</th>
211        <td><input <%=requiredClazz%> type="text" name="ordinal" style="width: 15em;"
212          value="<%=eventType == null ? Values.getInt(cc.getPropertyValue("ordinal"), maxOrdinal+1) : eventType.getOrdinal()%>" 
213          maxlength="10" onkeypress="return Numbers.integerOnly(event)"></td>
214        <td></td>
215      </tr>
216      <tr>
217        <th>Protocol type</th>
218        <td>
219          <base:select 
220            id="protocoltype_id"
221            clazz="selectionlist"
222            required="false"
223            current="<%=currentProtocolType%>"
224            denied="<%=!readCurrentProtocolType%>"
225            recent="<%=recentProtocolTypes%>"
226            newitem="<%=eventType == null%>"
227            onselect="selectProtocolTypeOnClick()"
228          />
229        </td>
230        <td></td>
231      </tr>
232      <tr class="dynamic">
233        <th>Description</th>
234        <td>
235          <textarea <%=clazz%> rows="4" name="description" 
236            ><%=HTML.encodeTags(eventType == null ? cc.getPropertyValue("description") : eventType.getDescription())%></textarea>
237        </td>
238        <td style="width: 20px;">
239          <base:icon image="zoom.png" 
240            onclick="Main.zoom('Description', 'eventtype', 'description')"
241            tooltip="Edit in larger window"
242          />
243        </td>
244      </tr>
245      </table>
246    </t:tab>
247    </t:tabcontrol>
248    </form>
249   
250    <div class="legend">
251      <base:icon image="required.gif" /> = required information
252    </div>
253
254    <base:buttongroup subclass="dialogbuttons">
255      <base:button onclick="saveSettings()" title="Save" />
256      <base:button onclick="window.close()" title="Cancel" />
257    </base:buttongroup>
258  </base:body>
259  </base:page>
260  <%
261}
262finally
263{
264  if (dc != null) dc.close();
265}
266%>
Note: See TracBrowser for help on using the repository browser.