source: trunk/www/admin/clients/help/edit_help.jsp @ 3297

Last change on this file since 3297 was 3297, checked in by Nicklas Nordborg, 16 years ago

Do not hide form elements for browsers that can handle layers correctly (ie. all but IE6)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.9 KB
Line 
1<%-- $Id: edit_help.jsp 3297 2007-05-07 11:34:14Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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.SystemItems"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.Include"
36  import="net.sf.basedb.core.Client"
37  import="net.sf.basedb.core.Help"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.BaseException"
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="java.util.List"
48  import="java.util.Set"
49  import="java.util.HashSet"
50  import="java.util.Date"
51%>
52<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
53<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
54<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
55<%@ taglib prefix="m" uri="/WEB-INF/menu.tld" %>
56<%
57final Item itemType = Item.HELP;
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
60final int itemId = cc.getId();
61final int clientId = Values.getInt(request.getParameter("client_id"));
62final String ID = sc.getId();
63final float scale = Base.getScale(sc);
64final DbControl dc = sc.newDbControl();
65try
66{
67  String title = null;
68  Client client = null;
69  Help help = null;
70  String externalId = null;
71 
72  if (itemId == 0)
73  {
74    title = "Create help";
75    cc.removeObject("item");
76    client = Client.getById(dc, clientId);
77    externalId = Values.getString(request.getParameter("external_id"), 
78      cc.getPropertyValue("externalId"));
79  }
80  else
81  {
82    help = Help.getById(dc, itemId);
83    cc.setObject("item", help);
84    title = "Edit help text -- " + HTML.encodeTags(help.getName());
85    externalId = help.getExternalId();
86  }
87  if (help != null) help.checkPermission(Permission.WRITE);
88  final String clazz = "class=\"text\"";
89  final String requiredClazz = "class=\"text required\"";
90  %>
91
92  <base:page type="popup" title="<%=title%>">
93  <base:head scripts="menu.js,tabcontrol.js" styles="toolbar.css,tabcontrol.css,menu.css">
94    <script language="JavaScript">
95    // Validate the "Help" tab
96    function validateHelp()
97    {
98      var frm = document.forms['help'];
99      if (Main.trimString(frm.name.value) == '')
100      {
101        alert("You must enter a name");
102        frm.name.focus();
103        return false;
104      }
105      else if (Main.trimString(frm.external_id.value) == '')
106      {
107        alert("You must enter an external ID");
108        frm.external_id.focus();
109        return false;
110      }
111      return true;
112    }
113
114    // Submit the form
115    function saveSettings()
116    {
117      var frm = document.forms['help'];
118      if (TabControl.validateActiveTab('settings'))
119      {
120        frm.submit();
121      }
122    }
123 
124    function init()
125    {
126      var frm = document.forms['help'];
127      <%
128      if (help == null)
129      {
130        %>
131        frm.name.focus();
132        frm.name.select();
133        <%
134      }
135      %>
136    }
137   
138    /*
139      Enclose the selected text with prefix and suffix. Code taken
140      from Trac: http://projects.edgewall.com/trac/
141    */
142    function encloseSelection(prefix, suffix)
143    {
144      var frm = document.forms['help'];
145      var textarea = frm.description;
146      textarea.focus();
147        var start, end, sel, scrollPos, subst;
148        if (typeof(document["selection"]) != "undefined")
149        {
150          sel = document.selection.createRange().text;
151        }
152        else if (typeof(textarea["setSelectionRange"]) != "undefined")
153        {
154          start = textarea.selectionStart;
155          end = textarea.selectionEnd;
156          scrollPos = textarea.scrollTop;
157          sel = textarea.value.substring(start, end);
158        }
159        if (sel.match(/ $/))
160        {
161          // exclude ending space char, if any
162            sel = sel.substring(0, sel.length - 1);
163            suffix = suffix + " ";
164        }
165        subst = prefix + sel + suffix;
166        if (typeof(document["selection"]) != "undefined")
167        {
168          var range = document.selection.createRange().text = subst;
169          textarea.caretPos -= suffix.length;
170        }
171        else if (typeof(textarea["setSelectionRange"]) != "undefined")
172        {
173          textarea.value = textarea.value.substring(0, start) + subst +
174                           textarea.value.substring(end);
175          if (sel)
176          {
177            textarea.setSelectionRange(start + subst.length, start + subst.length);
178          }
179          else
180          {
181            textarea.setSelectionRange(start + prefix.length, start + prefix.length);
182          }
183          textarea.scrollTop = scrollPos;
184        }
185    }
186    </script>
187  </base:head>
188  <base:body onload="init()">
189    <m:menu
190      id="listtype"
191      style="display: none;">     
192    <m:menuitem 
193      title="Ordered list" 
194      onclick="encloseSelection('&lt;ol&gt;', '&lt;/ol&gt;')"
195      tooltip="Insert an ordered list"
196    />
197    <m:menuitem
198      title="Unordered list"
199      onclick="encloseSelection('&lt;ul&gt;', '&lt;/ul&gt;')"
200      tooltip="Insert an unordered list"
201    />     
202    <m:menuitem
203      title="List item"
204      onclick="encloseSelection('&lt;li&gt;', '&lt;/li&gt;')"
205      tooltip="Insert a listitem."
206    />     
207    </m:menu>
208    <%
209    String tableInsert = "encloseSelection('&lt;table frame=&quot;borders&quot;&gt;', '&lt;/table&gt;')";
210    %>
211    <m:menu
212      id="tableitem"
213      style="display: none;">
214    <m:menuitem
215      title="Table"
216      onclick="<%=tableInsert%>"
217      tooltip="Insert a table"
218    />
219    <m:menuitem
220      title="Row"
221      onclick="encloseSelection('&lt;tr&gt;', '&lt;/tr&gt;')"
222      tooltip="Insert a tablerow."
223    />
224    <m:menuitem
225      title="Cell"
226      onclick="encloseSelection('&lt;td&gt;', '&lt;/td&gt;')"
227      tooltip="Insert a datacell."
228    />
229    </m:menu>
230    <m:menu
231      id="textformats"
232      style="display: none;">
233    <m:menuitem
234      title="Important"
235      onclick="encloseSelection('&lt;imp&gt;', '&lt/imp&gt;')"
236      tooltip="Mark text as important"
237    />
238    <m:menuitem
239      title="Label"
240      onclick="encloseSelection('&lt;lbl&gt;', '&lt/lbl&gt;')"
241      tooltip="Mark text as a label appearing in the interface."
242    />
243    <m:menuitem
244      title="Required"
245      onclick="encloseSelection('&lt;req&gt;', '&lt/req&gt;')"
246      tooltip="Mark text as required user input."
247    />
248    <m:menuitem
249      title="Button text"
250      onclick="encloseSelection('&lt;btn&gt;', '&lt/btn&gt;')"
251      tooltip="Mark text to symbol a button."
252    />
253    <m:menuitem
254      title="Menu text"
255      onclick="encloseSelection('&lt;mnu&gt;', '&lt/mnu&gt;')"
256      tooltip="Mark text to symbol a menu."
257    />
258    </m:menu>   
259    <m:menu
260      id="link"
261      style="display: none;"
262    >
263    <m:menuitem
264      title="Insert helptext"
265      onclick="encloseSelection('{@include ', '}')"
266      tooltip="Insert another helptext in this text."
267    />   
268    <m:menuitem
269      title="Internal link"
270      onclick="encloseSelection('{@link ', '}')"
271      tooltip="Insert a link to another help topic."
272    />
273    <%
274    String insertBookmarkLink = "encloseSelection('&lt;a href=&quot;#&quot&gt;', '&lt/a&gt;')";
275    %>
276    <m:menuitem
277      title="External link"
278      onclick="<%=insertBookmarkLink%>"
279      tooltip="Insert a link to an external web page."
280    />
281    <%
282    String insertBookmark = "encloseSelection('&lt;a&nbsp;name=&quot;&quot;&gt;', '&lt;/a&gt;')";
283    %>
284    <m:menuitem
285      title="Bookmark"
286      onclick="<%=insertBookmark%>"
287      tooltip="Insert a bookmark"
288    />
289    </m:menu>
290    <p>
291    <form action="index.jsp?ID=<%=ID%>" method="post" name="help" onsubmit="return false;">
292    <input type="hidden" name="cmd" value="UpdateItem">
293    <input type="hidden" name="client_id" value="<%=clientId%>">
294
295    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
296    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*360)+"px;"%>" 
297      position="bottom" remember="<%=help != null%>">
298    <t:tab id="info" title="Help text" validate="validateHelp()" helpid="help.edit">
299      <table class="form" cellspacing=0>
300      <tr>
301        <td class="prompt">Title</td>
302        <td><input <%=requiredClazz%> type="text" name="name" 
303          value="<%=HTML.encodeTags(help == null ? Values.getString(cc.getPropertyValue("name"), "New help") : help.getName())%>" 
304          size="40" maxlength="<%=Help.MAX_NAME_LENGTH%>"></td>
305      </tr>
306      <tr>
307        <td class="prompt">External ID</td>
308        <td><input <%=requiredClazz%> type="text" name="external_id" 
309          value="<%=HTML.encodeTags(externalId)%>"
310          size="40" maxlength="<%=Help.MAX_EXTERNAL_ID_LENGTH%>"></td>
311      </tr>   
312         
313      <tr valign=top>
314        <td class="prompt">Help text</td>
315        <td>
316          <tbl:toolbar style="border-right:none;width:176px;">                       
317            <tbl:button 
318              tooltip="Bold"             
319              image="text_bold.png"
320              onclick="encloseSelection('&lt;b&gt;', '&lt;/b&gt;')"
321            />
322            <tbl:button
323              tooltip="Italic"             
324              image="text_italic.png"
325              onclick="encloseSelection('&lt;i&gt;', '&lt;/i&gt;')"
326            />
327            <tbl:button
328              tooltip="Underline"
329              image="text_underline.png"
330              onclick="encloseSelection('&lt;u&gt;', '&lt;/u&gt;')"
331            />                     
332            <tbl:button
333              tooltip="Header 3"
334              image="text_h3.png"
335              onclick="encloseSelection('&lt;h3&gt;', '&lt;/h3&gt;')"
336            />
337            <tbl:button
338              tooltip="Header 4"
339              image="text_h4.png"
340              onclick="encloseSelection('&lt;h4&gt;', '&lt;/h4&gt;')"
341            />
342            <tbl:button
343              tooltip="Textstyle"
344              image="text_style_edit.gif"
345              onclick="Menu.toggleTopMenu(document.getElementById('textformats'), event.clientX, event.clientY); event.cancelBubble = true;"
346            />           
347            <tbl:button
348              tooltip="Table"
349              image="text_table.png"
350              onclick="Menu.toggleTopMenu(document.getElementById('tableitem'), event.clientX, event.clientY); event.cancelBubble = true;"
351            />
352            <tbl:button
353              tooltip="List"
354              image="text_list.gif"
355              onclick="Menu.toggleTopMenu(document.getElementById('listtype'), event.clientX, event.clientY); event.cancelBubble = true;"
356            />
357            <tbl:button
358              tooltip="New line"
359              image="text_newline.gif" 
360              onclick="encloseSelection('&lt;br&gt;', '')"
361            />
362            <tbl:button
363              tooltip="New paragraph"
364              image="text_paragraph.gif"
365              onclick="encloseSelection('&lt;p&gt;', '&lt;/p&gt;')"
366            />     
367            <tbl:button
368              tooltip="New link"
369              image="text_link.png"             
370              onclick="Menu.toggleTopMenu(document.getElementById('link'), event.clientX, event.clientY); event.cancelBubble = true;"
371            />         
372          </tbl:toolbar>
373          <textarea <%=clazz%> rows="16" cols="60" name="description" wrap="virtual"
374            ><%=HTML.encodeTags(help == null ? cc.getPropertyValue("description") : help.getDescription())%></textarea>
375          <a href="javascript:Main.zoom('Help text', 'help', 'description')"
376            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
377        </td>
378      </tr>
379      </table>
380      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
381    </t:tab>
382    </t:tabcontrol>
383
384    <table align="center">
385    <tr>
386      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
387      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
388    </tr>
389    </table>
390    </form>
391  </base:body>
392  </base:page>
393  <%
394}
395finally
396{
397  if (dc != null) dc.close();
398}
399%>
Note: See TracBrowser for help on using the repository browser.