source: branches/2.4-stable/www/common/anytoany/edit_anytoany.jsp @ 3707

Last change on this file since 3707 was 3707, checked in by Nicklas Nordborg, 14 years ago

Fixes #740: Missing AnyToAny? item causes ItemNotFoundException? when viewing a transformation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 6.3 KB
Line 
1<%-- $Id: edit_anytoany.jsp 3707 2007-09-05 09:29:16Z 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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.AnyToAny"
35  import="net.sf.basedb.core.BasicItem"
36  import="net.sf.basedb.core.File"
37  import="net.sf.basedb.core.Nameable"
38  import="net.sf.basedb.core.PermissionDeniedException"
39  import="net.sf.basedb.core.ItemNotFoundException"
40  import="net.sf.basedb.clients.web.Base"
41  import="net.sf.basedb.clients.web.util.HTML"
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<%!
47private String getName(BasicItem item, boolean readItem, boolean missingItem, Item itemType, int id)
48{
49  String name = "";
50  if (item instanceof File)
51  {
52    File toFile = (File)item;
53    name = HTML.encodeTags(toFile.getPath().toString());
54  }
55  else if (item instanceof Nameable)
56  {
57    Nameable nameable = (Nameable)item;
58    name = HTML.encodeTags(nameable.getName());
59  }
60  else if (!readItem)
61  {
62    name = "<i>- denied -</i>";
63  }
64  else if (missingItem)
65  {
66    name = "<i>- missing -</i> (" + itemType.toString() + "; id=" + id + ")";
67  }
68  else if (item == null)
69  {
70    name = "<i>- none -</i>";
71  }
72  else
73  {
74    name = HTML.encodeTags(item.toString());
75  }
76  if (item != null)
77  {
78    name += " [" + item.getType() + "]";
79  }
80  return name;
81}
82
83%>
84<%
85final Item itemType = Item.ANYTOANY;
86final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
87final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
88final int itemId = cc.getId();
89final String ID = sc.getId();
90final float scale = Base.getScale(sc);
91final DbControl dc = sc.newDbControl();
92try
93{
94  String title = null;
95  AnyToAny anyToAny = null;
96
97  String fromName = "";
98  String toName = "";
99 
100  if (itemId == 0)
101  {
102    throw new PermissionDeniedException(Permission.CREATE, "Any-to-any link");
103  }
104  else
105  {
106    anyToAny = AnyToAny.getById(dc, itemId);
107    cc.setObject("item", anyToAny);
108    title = "Edit any-to-any link -- " + HTML.encodeTags(anyToAny.getName());
109   
110    BasicItem to = null;
111    boolean readTo = true;
112    boolean missingTo = false;
113   
114    BasicItem from = null;
115    boolean readFrom = true;
116    boolean missingFrom = false;
117   
118    try
119    {
120      to = anyToAny.getTo();
121    }
122    catch (PermissionDeniedException ex)
123    {
124      readTo = false;
125    }
126    catch (ItemNotFoundException ex)
127    {
128      missingTo = true;
129    }
130   
131    try
132    {
133      from = anyToAny.getFrom();
134    }
135    catch (PermissionDeniedException ex)
136    {
137      readFrom = false;
138    }
139    catch (ItemNotFoundException ex)
140    {
141      missingFrom = true;
142    }
143 
144    toName = getName(to, readTo, missingTo, anyToAny.getToType(), anyToAny.getToId());
145    fromName = getName(from, readFrom, missingFrom, anyToAny.getFromType(), anyToAny.getFromId());
146  }
147  if (anyToAny != null) anyToAny.checkPermission(Permission.WRITE);
148 
149  final String clazz = "class=\"text\"";
150  final String requiredClazz = "class=\"text required\"";
151  %>
152
153  <base:page type="popup" title="<%=title%>">
154  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
155    <script language="JavaScript">
156    // Validate the "AnyToAny" tab
157    function validateAnyToAny()
158    {
159      var frm = document.forms['anytoany'];
160      if (Main.trimString(frm.name.value) == '')
161      {
162        alert("You must enter a name");
163        frm.name.focus();
164        return false;
165      }
166      return true;
167    }
168
169    // Submit the form
170    function saveSettings()
171    {
172      var frm = document.forms['anytoany'];
173      if (TabControl.validateActiveTab('settings'))
174      {
175        frm.submit();
176      }
177    }
178   
179    </script>
180  </base:head>
181  <base:body>
182    <p>
183    <form action="index.jsp?ID=<%=ID%>" method="post" name="anytoany" onsubmit="return false;">
184    <input type="hidden" name="cmd" value="UpdateItem">
185
186    <h3 class="docked"><%=title%></h3>
187    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*160)+"px;"%>" 
188      position="bottom" remember="<%=anyToAny != null%>">
189    <t:tab id="info" title="Any-to-any link" validate="validateAnyToAny()">
190      <table class="form" cellspacing=0>
191      <tr>
192        <td class="prompt">From</td>
193        <td><%=fromName%></td>
194      </tr>
195      <tr>
196        <td class="prompt">To</td>
197        <td><%=toName%></td>
198      </tr>
199      <tr>
200        <td class="prompt">Name</td>
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          size="40" maxlength="<%=AnyToAny.MAX_NAME_LENGTH%>"></td>
204      </tr>
205      <tr valign=top>
206        <td class="prompt">Description</td>
207        <td nowrap>
208          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
209            ><%=HTML.encodeTags(anyToAny == null ? cc.getPropertyValue("description") : anyToAny.getDescription())%></textarea>
210          <a href="javascript:Main.zoom('Description', 'label', 'description')"
211            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
212        </td>
213      </tr>
214      </table>
215      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
216    </t:tab>
217    </t:tabcontrol>
218
219    <table align="center">
220    <tr>
221      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
222      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
223    </tr>
224    </table>
225    </form>
226  </base:body>
227  </base:page>
228  <%
229}
230finally
231{
232  if (dc != null) dc.close();
233}
234%>
Note: See TracBrowser for help on using the repository browser.