source: trunk/www/biomaterials/tags/edit_tag.jsp @ 5632

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

References #1153: Handling short read transcript sequence data

Replaced Label with Tag. It re-uses much of the old code including the database table.

The code compiles and most test programs pass. Not all gui pages in the web client work. Since LabeledExtract is going to be removed functionality that is related with this may not do what is expected.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 6.8 KB
Line 
1<%-- $Id: edit_tag.jsp 5632 2011-05-17 09:35:34Z 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.Tag"
34  import="net.sf.basedb.core.ItemSubtype"
35  import="net.sf.basedb.core.PermissionDeniedException"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.Include"
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.core.plugin.GuiContext"
43  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
44  import="net.sf.basedb.clients.web.extensions.JspContext"
45  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
46  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
47  import="net.sf.basedb.util.Values"
48%>
49<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
50<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
51<%
52final Item itemType = Item.TAG;
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  Tag tag = null;
63  boolean readCurrentTagType = true;
64  int currentTagTypeId = 0;
65
66  if (itemId == 0)
67  {
68    title = "Create tag";
69    cc.removeObject("item");
70    currentTagTypeId = Values.getInt(request.getParameter("tagtype_id"));
71    if (currentTagTypeId == 0) 
72    {
73      int recentTagTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
74      currentTagTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentTagTypeId);
75    }
76  }
77  else
78  {
79    tag = Tag.getById(dc, itemId);
80    tag.checkPermission(Permission.WRITE);
81    cc.setObject("item", tag);
82    title = "Edit tag -- " + HTML.encodeTags(tag.getName());
83    try
84    {
85      ItemSubtype tagType = tag.getItemSubtype();
86      if (tagType != null) currentTagTypeId = tagType.getId();
87    }
88    catch (PermissionDeniedException ex)
89    {
90      readCurrentTagType = false;
91    }
92  }
93 
94  // Query to retrieve protocol types
95  final ItemQuery<ItemSubtype> tagTypeQuery = ItemSubtype.getQuery(itemType);
96  tagTypeQuery.include(Include.ALL);
97  tagTypeQuery.order(Orders.asc(Hql.property("name")));
98
99  final String clazz = "class=\"text\"";
100  final String requiredClazz = "class=\"text required\"";
101  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), tag);
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 "Tag" tab
110    function validateTag()
111    {
112      var frm = document.forms['tag'];
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['tag'];
126      if (TabControl.validateActiveTab('settings'))
127      {
128        frm.submit();
129      }
130    }
131   
132    function init()
133    {
134      <%
135      if (tag == null)
136      {
137        %>
138        var frm = document.forms['tag'];
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="tag" 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*160)+"px;"%>" 
154      position="bottom"  remember="<%=tag != null%>"
155      extensions="<%=invoker%>">
156    <t:tab id="info" title="Tag" validate="validateTag()" helpid="tag.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(tag == null ? Values.getString(cc.getPropertyValue("name"), "New tag") : tag.getName())%>" 
162          size="40" maxlength="<%=Tag.MAX_NAME_LENGTH%>"></td>
163      </tr>
164      <tr valign="top">
165        <td class="prompt">Type</td>
166        <td colspan="2">
167          <select name="tagtype_id" 
168            <%=!readCurrentTagType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>>
169          <%
170          if (!readCurrentTagType)
171          {
172            %>
173            <option value="-1">- denied -
174            <%
175          }
176          else
177          {
178            for (ItemSubtype tagType : tagTypeQuery.list(dc))
179            {
180              int id = tagType.getId();
181              if (id != currentTagTypeId && tagType.isRemoved()) continue;
182              %>
183              <option value="<%=id == currentTagTypeId && tag != null ? -id : id%>" 
184                <%=id == currentTagTypeId ? "selected" : ""%>
185                ><%=HTML.encodeTags(tagType.getName())%>
186              <%
187            }
188          }
189          %>
190          </select>
191        </td>
192      </tr>
193      <tr valign=top>
194        <td class="prompt">Description</td>
195        <td nowrap>
196          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
197            ><%=HTML.encodeTags(tag == null ? cc.getPropertyValue("description") : tag.getDescription())%></textarea>
198          <a href="javascript:Main.zoom('Description', 'tag', 'description')"
199            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
200        </td>
201      </tr>
202      </table>
203      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
204    </t:tab>
205    </t:tabcontrol>
206
207    <table align="center">
208    <tr>
209      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
210      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
211    </tr>
212    </table>
213    </form>
214  </base:body>
215  </base:page>
216  <%
217}
218finally
219{
220  if (dc != null) dc.close();
221}
222%>
Note: See TracBrowser for help on using the repository browser.