source: trunk/www/admin/software/edit_software.jsp @ 5643

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

References #1597: Subtypes of items

Cleanup code and JSP pages. Added some utility functions to make it easier to load and use subtypes. Added subtype functionality to BioSource.

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