source: trunk/www/biomaterials/labels/edit_label.jsp @ 5492

Last change on this file since 5492 was 5492, checked in by Nicklas Nordborg, 11 years ago

References #1545: Add extension points to edit pages

Fixed on all biomaterial lims pages.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 5.3 KB
Line 
1<%-- $Id: edit_label.jsp 5492 2010-11-16 08:47:29Z 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.Label"
34  import="net.sf.basedb.core.PermissionDeniedException"
35  import="net.sf.basedb.clients.web.Base"
36  import="net.sf.basedb.clients.web.util.HTML"
37  import="net.sf.basedb.core.plugin.GuiContext"
38  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
39  import="net.sf.basedb.clients.web.extensions.JspContext"
40  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
41  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
42  import="net.sf.basedb.util.Values"
43%>
44<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
45<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
46<%
47final Item itemType = Item.LABEL;
48final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
49final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
50final int itemId = cc.getId();
51final String ID = sc.getId();
52final float scale = Base.getScale(sc);
53final DbControl dc = sc.newDbControl();
54try
55{
56  String title = null;
57  Label label = null;
58
59  if (itemId == 0)
60  {
61    title = "Create label";
62    cc.removeObject("item");
63  }
64  else
65  {
66    label = Label.getById(dc, itemId);
67    cc.setObject("item", label);
68    title = "Edit label -- " + HTML.encodeTags(label.getName());
69  }
70  if (label != null && !label.hasPermission(Permission.WRITE))
71  {
72    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
73  }
74 
75  final String clazz = "class=\"text\"";
76  final String requiredClazz = "class=\"text required\"";
77  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), label);
78  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
79  %>
80  <base:page type="popup" title="<%=title%>">
81  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
82    <ext:scripts context="<%=jspContext%>" />
83    <ext:stylesheets context="<%=jspContext%>" />
84    <script language="JavaScript">
85    // Validate the "Label" tab
86    function validateLabel()
87    {
88      var frm = document.forms['label'];
89      if (Main.trimString(frm.name.value) == '')
90      {
91        alert("You must enter a name");
92        frm.name.focus();
93        return false;
94      }
95      return true;
96    }
97
98    // Submit the form
99    function saveSettings()
100    {
101      var frm = document.forms['label'];
102      if (TabControl.validateActiveTab('settings'))
103      {
104        frm.submit();
105      }
106    }
107   
108    function init()
109    {
110      <%
111      if (label == null)
112      {
113        %>
114        var frm = document.forms['label'];
115        frm.name.focus();
116        frm.name.select();
117        <%
118      }
119      %>
120    }
121    </script>
122  </base:head>
123  <base:body onload="init()">
124    <p>
125    <form action="index.jsp?ID=<%=ID%>" method="post" name="label" onsubmit="return false;">
126    <input type="hidden" name="cmd" value="UpdateItem">
127
128    <h3 class="docked"><%=title%> <base:help tabcontrol="settings"/></h3>
129    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*160)+"px;"%>" 
130      position="bottom"  remember="<%=label != null%>"
131      extensions="<%=invoker%>">
132    <t:tab id="info" title="Label" validate="validateLabel()" helpid="label.edit">
133      <table class="form" cellspacing=0>
134      <tr>
135        <td class="prompt">Name</td>
136        <td><input <%=requiredClazz%> type="text" name="name" 
137          value="<%=HTML.encodeTags(label == null ? Values.getString(cc.getPropertyValue("name"), "New label") : label.getName())%>" 
138          size="40" maxlength="<%=Label.MAX_NAME_LENGTH%>"></td>
139      </tr>
140      <tr valign=top>
141        <td class="prompt">Description</td>
142        <td nowrap>
143          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
144            ><%=HTML.encodeTags(label == null ? cc.getPropertyValue("description") : label.getDescription())%></textarea>
145          <a href="javascript:Main.zoom('Description', 'label', 'description')"
146            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
147        </td>
148      </tr>
149      </table>
150      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
151    </t:tab>
152    </t:tabcontrol>
153
154    <table align="center">
155    <tr>
156      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
157      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
158    </tr>
159    </table>
160    </form>
161  </base:body>
162  </base:page>
163  <%
164}
165finally
166{
167  if (dc != null) dc.close();
168}
169%>
Note: See TracBrowser for help on using the repository browser.