source: trunk/www/admin/software/edit_software.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.4 KB
Line 
1<%-- $Id: edit_software.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.Software"
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.SOFTWARE;
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  Software software = null;
63  boolean readCurrentSoftwareType = true;
64  int currentSoftwareTypeId = 0;
65
66  if (itemId == 0)
67  {
68    title = "Create software";
69    cc.removeObject("item");
70    currentSoftwareTypeId = Values.getInt(request.getParameter("softwaretype_id"));
71    if (currentSoftwareTypeId == 0)
72    {
73      int recentSoftwareTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
74      currentSoftwareTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSoftwareTypeId);
75    }
76  }
77  else
78  {
79    software = Software.getById(dc, itemId);
80    cc.setObject("item", software);
81    title = "Edit software -- " + HTML.encodeTags(software.getName());
82    try
83    {
84      ItemSubtype st = software.getItemSubtype();
85      if (st != null) currentSoftwareTypeId = st.getId();
86    }
87    catch (PermissionDeniedException ex)
88    {
89      readCurrentSoftwareType = false;
90    }
91  }
92  if (software != null && !software.hasPermission(Permission.WRITE))
93  {
94    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
95  }
96 
97  // Query to retrieve file types
98  final ItemQuery<ItemSubtype> softwareTypeQuery = ItemSubtype.getQuery(itemType);
99  softwareTypeQuery.order(Orders.asc(Hql.property("name"))); 
100  final String clazz = "class=\"text\"";
101  final String requiredClazz = "class=\"text required\"";
102  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), software);
103  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
104  %>
105  <base:page type="popup" title="<%=title%>">
106  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
107    <ext:scripts context="<%=jspContext%>" />
108    <ext:stylesheets context="<%=jspContext%>" />
109    <script language="JavaScript">
110    // Validate the "Software" tab
111    function validateSoftware()
112    {
113      var frm = document.forms['software'];
114      if (Main.trimString(frm.name.value) == '')
115      {
116        alert("You must enter a name");
117        frm.name.focus();
118        return false;
119      }
120      return true;
121    }
122
123    // Submit the form
124    function saveSettings()
125    {
126      var frm = document.forms['software'];
127      if (TabControl.validateActiveTab('settings'))
128      {
129        frm.submit();
130      }
131    }
132   
133    function init()
134    {
135      <%
136      if (software == null)
137      {
138        %>
139        var frm = document.forms['software'];
140        frm.name.focus();
141        frm.name.select();
142        <%
143      }
144      %>
145    }
146    </script>
147  </base:head>
148  <base:body onload="init()">
149    <p>
150    <form action="index.jsp?ID=<%=ID%>" method="post" name="software" onsubmit="return false;">
151    <input type="hidden" name="cmd" value="UpdateItem">
152
153    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
154    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*180)+"px;"%>" 
155      position="bottom"  remember="<%=software != null%>"
156      extensions="<%=invoker%>">
157    <t:tab id="info" title="Software" validate="validateSoftware()" helpid="software.edit">
158      <table class="form" cellspacing=0>
159      <tr>
160        <td class="prompt">Name</td>
161        <td><input <%=requiredClazz%> type="text" name="name" 
162          value="<%=HTML.encodeTags(software == null ? Values.getString(cc.getPropertyValue("name"), "New software") : software.getName())%>" 
163          size="40" maxlength="<%=Software.MAX_NAME_LENGTH%>"></td>
164      </tr>
165      <tr>
166        <td class="prompt">Version</td>
167        <td><input <%=clazz%> type="text" name="version" 
168          value="<%=HTML.encodeTags(software == null ? cc.getPropertyValue("versionString") : software.getVersionString())%>" 
169          size="40" maxlength="<%=Software.MAX_VERSIONSTRING_LENGTH%>"></td>
170      </tr>
171      <tr valign="top">
172        <td class="prompt">Type</td>
173        <td colspan="2">
174          <select name="softwaretype_id" 
175            <%=!readCurrentSoftwareType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>>
176          <%
177          if (!readCurrentSoftwareType)
178          {
179            %>
180            <option value="-1">- denied -
181            <%
182          }
183          else
184          {
185            for (ItemSubtype softwareType : softwareTypeQuery.list(dc))
186            {
187              int id = softwareType.getId();
188              %>
189              <option value="<%=id == currentSoftwareTypeId && software != null ? -id : id%>" 
190                <%=softwareType.getId() == currentSoftwareTypeId ? "selected" : ""%>
191                ><%=HTML.encodeTags(softwareType.getName())%>
192              <%
193            }
194          }
195          %>
196          </select>
197        </td>
198      </tr>
199 
200      <tr valign=top>
201        <td class="prompt">Description</td>
202        <td nowrap>
203          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
204            ><%=HTML.encodeTags(software == null ? cc.getPropertyValue("description") : software.getDescription())%></textarea>
205          <a href="javascript:Main.zoom('Description', 'software', 'description')"
206            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
207        </td>
208      </tr>
209      </table>
210      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
211    </t:tab>
212    </t:tabcontrol>
213
214    <table align="center">
215    <tr>
216      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
217      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
218    </tr>
219    </table>
220    </form>
221  </base:body>
222  </base:page>
223  <%
224}
225finally
226{
227  if (dc != null) dc.close();
228}
229%>
Note: See TracBrowser for help on using the repository browser.