source: trunk/www/common/anytoany/edit_anytoany.jsp @ 5923

Last change on this file since 5923 was 5923, checked in by Nicklas Nordborg, 10 years ago

References #1655: GUI improvements

  • Edit dialogs for bioassay set, bioassay, transformation and some other experiment related dialogs
  • Analysis plug-in that have special jsp forms
  • Change history
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 6.2 KB
Line 
1<%-- $Id: edit_anytoany.jsp 5923 2012-01-11 14:29:26Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg, Martin Svensson
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 Nicklas
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.ItemContext"
31  import="net.sf.basedb.core.Permission"
32  import="net.sf.basedb.core.AnyToAny"
33  import="net.sf.basedb.core.BasicItem"
34  import="net.sf.basedb.core.File"
35  import="net.sf.basedb.core.Nameable"
36  import="net.sf.basedb.core.PermissionDeniedException"
37  import="net.sf.basedb.core.ItemNotFoundException"
38  import="net.sf.basedb.clients.web.Base"
39  import="net.sf.basedb.clients.web.util.HTML"
40  import="net.sf.basedb.util.Values"
41%>
42<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
43<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
44<%!
45private String getName(BasicItem item, boolean readItem, boolean missingItem, Item itemType, int id)
46{
47  String name = "";
48  if (item instanceof File)
49  {
50    File toFile = (File)item;
51    name = HTML.encodeTags(toFile.getPath().toString());
52  }
53  else if (item instanceof Nameable)
54  {
55    Nameable nameable = (Nameable)item;
56    name = HTML.encodeTags(nameable.getName());
57  }
58  else if (!readItem)
59  {
60    name = "<i>- denied -</i>";
61  }
62  else if (missingItem)
63  {
64    name = "<i>- missing -</i> (" + itemType.toString() + "; id=" + id + ")";
65  }
66  else if (item == null)
67  {
68    name = "<i>- none -</i>";
69  }
70  else
71  {
72    name = HTML.encodeTags(item.toString());
73  }
74  if (item != null)
75  {
76    name += " [" + item.getType() + "]";
77  }
78  return name;
79}
80
81%>
82<%
83final Item itemType = Item.ANYTOANY;
84final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
85final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
86final int itemId = cc.getId();
87final String ID = sc.getId();
88final float scale = Base.getScale(sc);
89final DbControl dc = sc.newDbControl();
90try
91{
92  String title = null;
93  AnyToAny anyToAny = null;
94
95  String fromName = "";
96  String toName = "";
97 
98  if (itemId == 0)
99  {
100    throw new PermissionDeniedException(Permission.CREATE, "Any-to-any link");
101  }
102  else
103  {
104    anyToAny = AnyToAny.getById(dc, itemId);
105    cc.setObject("item", anyToAny);
106    title = "Edit any-to-any link -- " + HTML.encodeTags(anyToAny.getName());
107   
108    BasicItem to = null;
109    boolean readTo = true;
110    boolean missingTo = false;
111   
112    BasicItem from = null;
113    boolean readFrom = true;
114    boolean missingFrom = false;
115   
116    try
117    {
118      to = anyToAny.getTo();
119    }
120    catch (PermissionDeniedException ex)
121    {
122      readTo = false;
123    }
124    catch (ItemNotFoundException ex)
125    {
126      missingTo = true;
127    }
128   
129    try
130    {
131      from = anyToAny.getFrom();
132    }
133    catch (PermissionDeniedException ex)
134    {
135      readFrom = false;
136    }
137    catch (ItemNotFoundException ex)
138    {
139      missingFrom = true;
140    }
141 
142    toName = getName(to, readTo, missingTo, anyToAny.getToType(), anyToAny.getToId());
143    fromName = getName(from, readFrom, missingFrom, anyToAny.getFromType(), anyToAny.getFromId());
144  }
145  if (anyToAny != null) anyToAny.checkPermission(Permission.WRITE);
146 
147  final String clazz = "class=\"text\"";
148  final String requiredClazz = "class=\"text required\"";
149  %>
150
151  <base:page type="popup" title="<%=title%>">
152  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
153    <script language="JavaScript">
154    // Validate the "AnyToAny" tab
155    function validateAnyToAny()
156    {
157      var frm = document.forms['anytoany'];
158      if (Main.trimString(frm.name.value) == '')
159      {
160        alert("You must enter a name");
161        frm.name.focus();
162        return false;
163      }
164      return true;
165    }
166
167    // Submit the form
168    function saveSettings()
169    {
170      var frm = document.forms['anytoany'];
171      if (TabControl.validateActiveTab('settings'))
172      {
173        frm.submit();
174      }
175    }
176   
177    </script>
178  </base:head>
179  <base:body>
180    <h1><%=title%></h1>
181    <form action="index.jsp?ID=<%=ID%>" method="post" name="anytoany" onsubmit="return false;">
182    <input type="hidden" name="cmd" value="UpdateItem">
183
184    <t:tabcontrol id="settings"
185      subclass="content dialogtabcontrol"
186      position="bottom" remember="<%=anyToAny != null%>">
187    <t:tab id="info" title="Any-to-any link" validate="validateAnyToAny()">
188      <table class="fullform input100 smaller">
189      <tr>
190        <th>From</th>
191        <td><%=fromName%></td>
192        <td></td>
193      </tr>
194      <tr>
195        <th>To</th>
196        <td><%=toName%></td>
197        <td></td>
198      </tr>
199      <tr>
200        <th>Name</th>
201        <td><input <%=requiredClazz%> type="text" name="name" 
202          value="<%=HTML.encodeTags(anyToAny == null ? Values.getString(cc.getPropertyValue("name"), "New any-to-any link") : anyToAny.getName())%>" 
203          maxlength="<%=AnyToAny.MAX_NAME_LENGTH%>"></td>
204        <td></td>
205      </tr>
206      <tr class="dynamic">
207        <th>Description</th>
208        <td>
209          <textarea <%=clazz%> rows="6" name="description" 
210            ><%=HTML.encodeTags(anyToAny == null ? cc.getPropertyValue("description") : anyToAny.getDescription())%></textarea>
211        </td>
212        <td style="width: 20px;">
213          <base:icon image="zoom.png" 
214            onclick="Main.zoom('Description', 'anytoany', 'description')"
215            tooltip="Edit in larger window"
216          />
217        </td>
218      </tr>
219      </table>
220    </t:tab>
221    </t:tabcontrol>
222    </form>
223   
224    <div class="legend">
225      <base:icon image="required.gif" /> = required information
226    </div>
227
228    <base:buttongroup subclass="dialogbuttons">
229      <base:button onclick="saveSettings()" title="Save" />
230      <base:button onclick="window.close()" title="Cancel" />
231    </base:buttongroup>
232  </base:body>
233  </base:page>
234  <%
235}
236finally
237{
238  if (dc != null) dc.close();
239}
240%>
Note: See TracBrowser for help on using the repository browser.