source: trunk/www/admin/hardware/edit_hardware.jsp @ 5630

Last change on this file since 5630 was 5630, checked in by Nicklas Nordborg, 12 years ago

References #1597: Subtypes of items

Added Subtypable interface and ItemSubtype item (and corresponding data-layer classes). File, Protocol, Software and Hardware are implementing the new interface and the FileType, ProtocolType, SoftwareType and HardwareType + data-layer classes have been deleted.

The rest of the changes are dependencies that have been updated to use the new subtype functionality.

There is no updgrade script yet. This will need to move existing *Type items into ItemSubtype and update all links from the other items. Then it can remove the old columns and tables. We also need to fix context-related information, but I think we have most functionality for this.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.3 KB
Line 
1<%-- $Id: edit_hardware.jsp 5630 2011-05-13 12:54:50Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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.Permission"
33  import="net.sf.basedb.core.Hardware"
34  import="net.sf.basedb.core.ItemSubtype"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.ItemResultList"
37  import="net.sf.basedb.core.PermissionDeniedException"
38  import="net.sf.basedb.core.query.Orders"
39  import="net.sf.basedb.core.query.Hql"
40  import="net.sf.basedb.clients.web.Base"
41  import="net.sf.basedb.clients.web.util.HTML"
42  import="net.sf.basedb.util.Values"
43  import="net.sf.basedb.core.plugin.GuiContext"
44  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
45  import="net.sf.basedb.clients.web.extensions.JspContext"
46  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
47  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
48%>
49<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
50<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
51<%
52final Item itemType = Item.HARDWARE;
53final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
54final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
55final int itemId = cc.getId();
56final String ID = sc.getId();
57final float scale = Base.getScale(sc);
58final DbControl dc = sc.newDbControl();
59try
60{
61  String title = null;
62  Hardware hardware = null;
63  boolean readCurrentHardwareType = true;
64  int currentHardwareTypeId = 0;
65
66  if (itemId == 0)
67  {
68    title = "Create hardware";
69    cc.removeObject("item");
70    currentHardwareTypeId = Values.getInt(request.getParameter("hardwaretype_id"));
71    if (currentHardwareTypeId == 0)
72    {
73      int recentHardwareTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
74      currentHardwareTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentHardwareTypeId);
75    }
76  }
77  else
78  {
79    hardware = Hardware.getById(dc, itemId);
80    cc.setObject("item", hardware);
81    title = "Edit hardware -- " + HTML.encodeTags(hardware.getName());
82    try
83    {
84      ItemSubtype ht = hardware.getItemSubtype();
85      if (ht != null) currentHardwareTypeId = ht.getId();
86    }
87    catch (PermissionDeniedException ex)
88    {
89      readCurrentHardwareType = false;
90    }
91  }
92  if (hardware != null && !hardware.hasPermission(Permission.WRITE))
93  {
94    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
95  }
96 
97  // Query to retrieve file types
98  final ItemQuery<ItemSubtype> hardwareTypeQuery = ItemSubtype.getQuery(itemType);
99  hardwareTypeQuery.order(Orders.asc(Hql.property("name")));
100 
101  final String clazz = "class=\"text\"";
102  final String requiredClazz = "class=\"text required\"";
103  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), hardware);
104  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
105  %>
106  <base:page type="popup" title="<%=title%>">
107  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
108    <ext:scripts context="<%=jspContext%>" />
109    <ext:stylesheets context="<%=jspContext%>" />
110    <script language="JavaScript">
111    // Validate the "Hardware" tab
112    function validateHardware()
113    {
114      var frm = document.forms['hardware'];
115      if (Main.trimString(frm.name.value) == '')
116      {
117        alert("You must enter a name");
118        frm.name.focus();
119        return false;
120      }
121      return true;
122    }
123
124    // Submit the form
125    function saveSettings()
126    {
127      var frm = document.forms['hardware'];
128      if (TabControl.validateActiveTab('settings'))
129      {
130        frm.submit();
131      }
132    }
133   
134    function init()
135    {
136      <%
137      if (hardware == null)
138      {
139        %>
140        var frm = document.forms['hardware'];
141        frm.name.focus();
142        frm.name.select();
143        <%
144      }
145      %>
146    }
147    </script>
148  </base:head>
149  <base:body onload="init()">
150    <p>
151    <form action="index.jsp?ID=<%=ID%>" method="post" name="hardware" onsubmit="return false;">
152    <input type="hidden" name="cmd" value="UpdateItem">
153
154    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
155    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*180)+"px;"%>" 
156      position="bottom"  remember="<%=hardware != null%>"
157      extensions="<%=invoker%>">
158    <t:tab id="info" title="Hardware" validate="validateHardware()" helpid="hardware.edit">
159      <table class="form" cellspacing=0>
160      <tr>
161        <td class="prompt">Name</td>
162        <td><input <%=requiredClazz%> type="text" name="name" 
163          value="<%=HTML.encodeTags(hardware == null ? Values.getString(cc.getPropertyValue("name"), "New hardware") : hardware.getName())%>" 
164          size="40" maxlength="<%=Hardware.MAX_NAME_LENGTH%>"></td>
165      </tr>
166      <tr>
167        <td class="prompt">Version</td>
168        <td><input <%=clazz%> type="text" name="version" 
169          value="<%=HTML.encodeTags(hardware == null ? cc.getPropertyValue("versionString") : hardware.getVersionString())%>" 
170          size="40" maxlength="<%=Hardware.MAX_VERSIONSTRING_LENGTH%>"></td>
171      </tr>
172      <tr valign="top">
173        <td class="prompt">Type</td>
174        <td colspan="2">
175          <select name="hardwaretype_id" 
176            <%=!readCurrentHardwareType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>>
177          <%
178          if (!readCurrentHardwareType)
179          {
180            %>
181            <option value="-1">- denied -
182            <%
183          }
184          else
185          {
186            for (ItemSubtype hardwareType : hardwareTypeQuery.list(dc))
187            {
188              int id = hardwareType.getId();
189              %>
190              <option value="<%=id == currentHardwareTypeId && hardware != null ? -id : id%>" 
191                <%=id == currentHardwareTypeId ? "selected" : ""%>
192                ><%=HTML.encodeTags(hardwareType.getName())%>
193              <%
194            }
195          }
196          %>
197          </select>
198        </td>
199      </tr>
200 
201      <tr valign=top>
202        <td class="prompt">Description</td>
203        <td nowrap>
204          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
205            ><%=HTML.encodeTags(hardware == null ? cc.getPropertyValue("description") : hardware.getDescription())%></textarea>
206          <a href="javascript:Main.zoom('Description', 'hardware', 'description')"
207            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
208        </td>
209      </tr>
210      </table>
211      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
212    </t:tab>
213    </t:tabcontrol>
214
215    <table align="center">
216    <tr>
217      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
218      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
219    </tr>
220    </table>
221    </form>
222  </base:body>
223  </base:page>
224  <%
225}
226finally
227{
228  if (dc != null) dc.close();
229}
230%>
Note: See TracBrowser for help on using the repository browser.