source: trunk/www/admin/annotationtypecategories/edit_category.jsp @ 5767

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

Fixes #1626: Center-align text on buttons

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 8.9 KB
Line 
1<%-- $Id: edit_category.jsp 5767 2011-09-28 07:31:39Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg, Dominic Oyeniran
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22
23  @author Dominic
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.Type"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.Include"
33  import="net.sf.basedb.core.ItemQuery"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.AnnotationType"
36  import="net.sf.basedb.core.AnnotationTypeCategory"
37  import="net.sf.basedb.core.SystemItems"
38  import="net.sf.basedb.core.Metadata"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.query.Orders"
43  import="net.sf.basedb.core.query.Hql"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.util.Values"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
49  import="net.sf.basedb.clients.web.extensions.JspContext"
50  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
51  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
52  import="java.util.Set"
53%>
54<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
56<%
57final Item itemType = Item.ANNOTATIONTYPECATEGORY;
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
60final int itemId = cc.getId();
61final String ID = sc.getId();
62final float scale = Base.getScale(sc);
63final DbControl dc = sc.newDbControl();
64try
65{
66  String title = null;
67  AnnotationTypeCategory annotationTypeCategory = null;
68
69 
70  if (itemId == 0)
71  {
72    //to create a new annotation category
73    title = "Create annotation type category";
74    cc.removeObject("item");
75  }
76  else
77  {
78    //if user click on edit, to edit annotationcategory
79    annotationTypeCategory = AnnotationTypeCategory.getById(dc, itemId);
80    cc.setObject("item", annotationTypeCategory);
81    title = "Edit annotation type category-- " + HTML.encodeTags(annotationTypeCategory.getName());
82    annotationTypeCategory.checkPermission(Permission.WRITE);
83  }
84 
85  // ---- Query to retrieve annotationtype members for a category
86  ItemQuery<AnnotationType> annotationTypeQuery = null;
87  if (annotationTypeCategory != null)
88  {
89    annotationTypeQuery = annotationTypeCategory.getAnnotationTypes(null);
90    annotationTypeQuery.include(Include.ALL);
91    annotationTypeQuery.order(Orders.asc(Hql.property("name")));
92  }
93 
94  final String clazz = "class=\"text\"";
95  final String requiredClazz = "class=\"text required\"";
96  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), annotationTypeCategory);
97  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
98  %>
99  <base:page type="popup" title="<%=title%>">
100  <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css">
101    <ext:scripts context="<%=jspContext%>" />
102    <ext:stylesheets context="<%=jspContext%>" />
103    <script language="JavaScript">
104    // Validate the "Annotation type category" tab
105    function validateAnnotationTypeCategory()
106    {
107      var frm = document.forms['annotationTypeCategory'];
108      if (Main.trimString(frm.name.value) == '')
109      {
110        alert("You must enter a name");
111        frm.name.focus();
112        return false;
113      }
114      return true;
115    }
116   
117    // Validate the "Members" tab
118    function validateMembers()
119    {
120      return true;
121    }
122
123    // Submit the form
124    function saveSettings()
125    {
126      var frm = document.forms['annotationTypeCategory'];
127      if (TabControl.validateActiveTab('settings'))
128      {
129        frm.addAnnotationTypes.value = Link.getActionIds(1, 'Z').join(',');
130        frm.removeAnnotationTypes.value = Link.getActionIds(-1, 'Z').join(',');       
131        frm.submit();
132      }
133    }
134    // Initialise edit_category web interface   
135   
136    function init()
137    {
138      <%
139      if (annotationTypeCategory == null)
140      {
141        %>
142        var frm = document.forms['annotationTypeCategory'];
143        frm.name.focus();
144        frm.name.select();
145        <%
146      }
147      %>
148      initMembers();
149    }
150   
151    function initMembers()
152    {
153      var members = document.forms['annotationTypeCategory'].members;
154      <%
155      if (annotationTypeQuery != null)
156      {
157        ItemResultList<AnnotationType> annotationTypes = annotationTypeQuery.list(dc);
158        for (AnnotationType annotationType : annotationTypes)
159        {
160          %>
161          Link.addNewItem(members, new Item('Z', <%=annotationType.getId()%>, '<%=HTML.javaScriptEncode(annotationType.getName())%>'));
162          <%
163        }
164      }
165      %>
166    }
167    function addAnnotationTypesOnClick()
168    {
169      var annotationtypes = Link.getListIds(document.forms['annotationTypeCategory'].members, 'Z');
170      var url = '../annotationtypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addAnnotationTypeCallback';
171      url += '&exclude='+annotationtypes.join(',');
172      Main.openPopup(url, 'AddAnnotationTypes', 1000, 700);
173    }
174   
175    function addAnnotationTypeCallback(annotationTypeId, name)
176    {
177      var item = Link.getItem('Z', annotationTypeId);
178      if (!item) item = new Item('Z', annotationTypeId, name);
179      Link.addItem(document.forms['annotationTypeCategory'].members, item);
180    }
181    function removeOnClick()
182    {
183      Link.removeSelected(document.forms['annotationTypeCategory'].members);
184    }
185    </script>
186  </base:head>
187  <base:body onload="init()">
188    <p>
189    <form action="index.jsp?ID=<%=ID%>" method="post" name="annotationTypeCategory" onsubmit="return false;">
190    <input type="hidden" name="cmd" value="UpdateItem">
191
192    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
193    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*280)+"px;"%>" position="bottom"
194      extensions="<%=invoker%>">
195    <t:tab id="info" title="Annotation type category" validate="validateAnnotationTypeCategory()"
196      helpid="annotationtypecategory.edit">
197      <table class="form" cellspacing=0>
198      <tr>
199        <td class="prompt">Name</td>
200        <td><input <%=requiredClazz%> type="text" name="name" 
201          value="<%=HTML.encodeTags(annotationTypeCategory == null ? Values.getString(cc.getPropertyValue("name"), "New annotation type category") : annotationTypeCategory.getName())%>" 
202          size="40" maxlength="<%=AnnotationTypeCategory.MAX_NAME_LENGTH%>"></td>
203      </tr>
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(annotationTypeCategory == null ? cc.getPropertyValue("description") : annotationTypeCategory.getDescription())%></textarea>
209          <a href="javascript:Main.zoom('Description', 'annotationTypeCategory', '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   
217    <t:tab id="members" title="Annotation types" tooltip="Add/remove members of this category" 
218      validate="validateMembers()" helpid="annotationtypecategory.edit.members">
219    <table width="100%">
220    <tr valign="top">
221    <td>
222      <b>Annotation types</b><br>
223      <select name="members" size="14" multiple 
224        style="width: 100%;">
225      </select>
226      <input type="hidden" name="removeAnnotationTypes" value="">
227      <input type="hidden" name="addAnnotationTypes" value="">
228    </td>
229    <td width="200px">
230      <br>
231      <table width="150px">
232      <tr><td><base:button 
233        clazz="leftaligned buttonclass"
234        onclick="addAnnotationTypesOnClick()" 
235        title="Add&nbsp;annotation&nbsp;types&hellip;" 
236        tooltip="Add annotation types to this category"
237        /></td></tr>
238      <tr><td><base:button 
239        clazz="leftaligned buttonclass"
240        onclick="removeOnClick()" 
241        title="Remove" 
242        tooltip="Remove the selected items from this category"
243      /></td></tr>
244      </table>
245    </td>
246    </tr>
247    </table>
248    </t:tab>
249    </t:tabcontrol>
250
251    <table align="center">
252    <tr>
253      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
254      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
255    </tr>
256    </table>
257    </form>
258  </base:body>
259  </base:page>
260  <%
261}
262finally
263{
264  if (dc != null) dc.close();
265}
266%>
Note: See TracBrowser for help on using the repository browser.