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

Last change on this file since 3675 was 3675, checked in by Jari Häkkinen, 14 years ago

Fixing copyright statements. Fixing svn properties.

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