source: trunk/www/lims/platetypes/eventtypes/edit_eventtype.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 Id
File size: 8.4 KB
Line 
1<%-- $Id: edit_eventtype.jsp 5908 2011-12-13 13:48:46Z 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    <p>
191    <form action="index.jsp?ID=<%=ID%>" method="post" name="eventtype" onsubmit="return false;">
192    <input type="hidden" name="cmd" value="UpdateItem">
193    <input type="hidden" name="platetype_id" value="<%=plateTypeId%>">
194
195    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
196    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*200)+"px;"%>" 
197      position="bottom" remember="<%=eventType != null%>"
198      extensions="<%=invoker%>">
199    <t:tab id="info" title="Event type" validate="validateEventType()" helpid="plateeventtype.edit">
200      <table class="form" cellspacing=0>
201      <tr>
202        <td class="prompt">Name</td>
203        <td><input <%=requiredClazz%> type="text" name="name" 
204          value="<%=HTML.encodeTags(eventType == null ? Values.getString(cc.getPropertyValue("name"), "New event type") : eventType.getName())%>" 
205          size="40" maxlength="<%=PlateEventType.MAX_NAME_LENGTH%>"></td>
206      </tr>
207      <tr>
208        <td class="prompt">Ordinal</td>
209        <td><input <%=requiredClazz%> type="text" name="ordinal" 
210          value="<%=eventType == null ? Values.getInt(cc.getPropertyValue("ordinal"), maxOrdinal+1) : eventType.getOrdinal()%>" 
211          size="12" maxlength="10" onkeypress="return Numbers.integerOnly(event)"></td>
212      </tr>
213      <tr>
214        <td class="prompt">Protocol type</td>
215        <td>
216          <base:select 
217            id="protocoltype_id"
218            clazz="selectionlist"
219            required="false"
220            current="<%=currentProtocolType%>"
221            denied="<%=!readCurrentProtocolType%>"
222            recent="<%=recentProtocolTypes%>"
223            newitem="<%=eventType == null%>"
224            onselect="selectProtocolTypeOnClick()"
225          />
226        </td>
227      </tr>
228
229      <tr >
230        <td class="prompt">Description</td>
231        <td nowrap>
232          <textarea <%=clazz%> rows="4" cols="40" name="description" 
233            ><%=HTML.encodeTags(eventType == null ? cc.getPropertyValue("description") : eventType.getDescription())%></textarea>
234          <a href="javascript:Main.zoom('Description', 'eventtype', 'description')"
235            title="Edit in larger window"><base:icon image="zoom.png" /></a>
236        </td>
237      </tr>
238      </table>
239      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
240    </t:tab>
241    </t:tabcontrol>
242
243    <table align="center">
244    <tr>
245      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
246      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
247    </tr>
248    </table>
249    </form>
250  </base:body>
251  </base:page>
252  <%
253}
254finally
255{
256  if (dc != null) dc.close();
257}
258%>
Note: See TracBrowser for help on using the repository browser.