source: trunk/www/common/zoom.jsp @ 3057

Last change on this file since 3057 was 3057, checked in by Martin Svensson, 15 years ago

References #146 Added a tag/menu to symbolize menu names in helptexts.
Some more styles for use with help texts also created.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.3 KB
Line 
1<%-- $Id: zoom.jsp 3057 2007-01-11 14:00:55Z martin $
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  Open a larger window for editing text in a textarea.
25
26  @param title The title of the input field that is zoomed
27  @param form The name of the form where the zoomed input field is located
28  @param textarea The name of the textarea that is zoomed
29
30  @author Nicklas
31  @version 2.0
32--%>
33<%@ page session="false"
34  import="net.sf.basedb.util.Values"
35%>
36<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
37<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
38<%@ taglib prefix="m" uri="/WEB-INF/menu.tld" %>
39<%
40  String title = request.getParameter("title");
41  String form = request.getParameter("form");
42  String textarea = request.getParameter("textarea");
43  boolean disabled = Values.getBoolean(request.getParameter("disabled"));
44  String callback = request.getParameter("callback");
45%>
46<base:page type="popup" title="<%=title%>">
47<base:head scripts="menu.js" styles="menu.css,help.css">
48  <script language="JavaScript">
49  function getText()
50  {
51    var frm = document.forms["zoom"];
52    frm.zoom.value = window.opener.document.forms['<%=form%>'].elements['<%=textarea%>'].value;
53    frm.zoom.focus();
54  }
55  function setTextAndClose()
56  {
57    var value = document.forms["zoom"].zoom.value;
58    var element = window.opener.document.forms['<%=form%>'].elements['<%=textarea%>'];
59    element.value = value;
60    element.focus();
61    <%
62    if (callback != null)
63    {
64      %>
65      window.opener.<%=callback%>(value);
66      <%
67    }
68    %>
69    window.close();
70  }
71 
72  /*
73    Enclose the selected text with prefix and suffix. Code taken
74    from Trac: http://projects.edgewall.com/trac/
75  */
76  function encloseSelection(prefix, suffix)
77  {
78    var frm = document.forms['zoom'];
79    var textarea = frm.zoom;
80    textarea.focus();
81      var start, end, sel, scrollPos, subst;
82      if (typeof(document["selection"]) != "undefined")
83      {
84        sel = document.selection.createRange().text;
85      }
86      else if (typeof(textarea["setSelectionRange"]) != "undefined")
87      {
88        start = textarea.selectionStart;
89        end = textarea.selectionEnd;
90        scrollPos = textarea.scrollTop;
91        sel = textarea.value.substring(start, end);
92      }
93      if (sel.match(/ $/))
94      {
95        // exclude ending space char, if any
96          sel = sel.substring(0, sel.length - 1);
97          suffix = suffix + " ";
98      }
99      subst = prefix + sel + suffix;
100      if (typeof(document["selection"]) != "undefined")
101      {
102        var range = document.selection.createRange().text = subst;
103        textarea.caretPos -= suffix.length;
104      }
105      else if (typeof(textarea["setSelectionRange"]) != "undefined")
106      {
107        textarea.value = textarea.value.substring(0, start) + subst +
108                         textarea.value.substring(end);
109        if (sel)
110        {
111          textarea.setSelectionRange(start + subst.length, start + subst.length);
112        }
113        else
114        {
115          textarea.setSelectionRange(start + prefix.length, start + prefix.length);
116        }
117        textarea.scrollTop = scrollPos;
118      }
119  }
120  </script>
121</base:head>
122<base:body onload="getText()">
123  <m:menu
124    id="listtype"
125    style="display: none;">     
126  <m:menuitem 
127    title="Ordered list" 
128    onclick="encloseSelection('&lt;ol&gt&lt;li&gt;', '&lt;/li&gt;&lt;/ol&gt;')"
129    tooltip="Insert an ordered list"
130  />
131  <m:menuitem
132    title="Unordered list"
133    onclick="encloseSelection('&lt;ul&gt;&lt;li&gt;', '&lt;/li&gt;&lt;/ul&gt;')"
134    tooltip="Insert an unordered list"
135  />     
136  <m:menuitem
137    title="List item"
138    onclick="encloseSelection('&lt;li&gt;', '&lt;/li&gt;')"
139    tooltip="Insert a listitem."
140  />     
141  </m:menu>
142  <%
143  String tableInsert = "encloseSelection('&lt;table frame=&quot;borders&quot;&gt;', '&lt;/table&gt;')";
144  %>
145  <m:menu
146    id="tableitem"
147    style="display: none;">
148  <m:menuitem
149    title="Table"
150    onclick="<%=tableInsert%>"
151    tooltip="Insert a table"
152  />
153  <m:menuitem
154    title="Row"
155    onclick="encloseSelection('&lt;tr&gt;', '&lt;/tr&gt;')"
156    tooltip="Insert a tablerow."
157  />
158  <m:menuitem
159    title="Cell"
160    onclick="encloseSelection('&lt;td&gt;', '&lt;/td&gt;')"
161    tooltip="Insert a datacell."
162  />
163  </m:menu>
164  <m:menu
165    id="textformats"
166    style="display: none;">
167  <m:menuitem
168    title="Important"
169    onclick="encloseSelection('&lt;imp&gt;', '&lt/imp&gt;')"
170    tooltip="Mark text as important"
171  />
172  <m:menuitem
173    title="User input"
174    onclick="encloseSelection('&lt;ui&gt;', '&lt/ui&gt;')"
175    tooltip="Mark text as user input."
176  />
177  <m:menuitem
178    title="Required"
179    onclick="encloseSelection('&lt;req&gt;', '&lt/req&gt;')"
180    tooltip="Mark text as required user input."
181  />
182  <m:menuitem
183    title="Button text"
184    onclick="encloseSelection('&lt;btn&gt;', '&lt/btn&gt;')"
185    tooltip="Mark text to symbol a button."
186  />
187  <m:menuitem
188    title="Menu text"
189    onclick="encloseSelection('&lt;mnu&gt;', '&lt/mnu&gt;')"
190    tooltip="Mark text to symbol a menu."
191  />
192  </m:menu>   
193  <m:menu
194    id="link"
195    style="display: none;"
196  >
197  <m:menuitem
198    title="Insert helptext"
199    onclick="encloseSelection('{@include ', '}')"
200    tooltip="Insert another helptext in this text."
201  />   
202  <m:menuitem
203    title="External link"
204    onclick="encloseSelection('{@link ', '}')"
205    tooltip="Insert an external link."
206  />
207  <%
208  String insertBookmarkLink = "encloseSelection('&lt;a href=&quot;#&quot&gt;', '&lt/a&gt;')";
209  %>
210  <m:menuitem
211    title="Internal link"
212    onclick="<%=insertBookmarkLink%>"
213    tooltip="Insert a link to a part in this text."
214  />
215  <%
216  String insertBookmark = "encloseSelection('&lt;a&nbsp;name=&quot;&quot;&gt;', '&lt;/a&gt;')";
217  %>
218  <m:menuitem
219    title="Bookmark"
220    onclick="<%=insertBookmark%>"
221    tooltip="Insert a bookmark"
222  />
223  </m:menu>
224  <form name="zoom" onsubmit="return false;">
225    <table align="center">
226    <tr>
227    <td>
228      <h3 class="docked"><%=title%> <base:help helpid="zoom.edit" /></h3>
229      <%
230      if (form.equals("help"))
231      {
232      %>
233        <tbl:toolbar clazz="editbar">                       
234          <tbl:button 
235            tooltip="Bold"
236            clazz="buttonclass"
237            image="text_bold.png"
238            onclick="encloseSelection('&lt;b&gt;', '&lt;/b&gt;')"
239          />
240          <tbl:button
241            tooltip="Italic"             
242            clazz="buttonclass"
243            image="text_italic.png"
244            onclick="encloseSelection('&lt;i&gt;', '&lt;/i&gt;')"
245          />
246          <tbl:button
247            tooltip="Underline"
248            clazz="buttonclass"
249            image="text_underline.png"
250            onclick="encloseSelection('&lt;u&gt;', '&lt;/u&gt;')"
251          />                     
252          <tbl:button
253            tooltip="Header 3"
254            clazz="buttonclass"
255            style="padding: 1px;"
256            image="text_h3.png"
257            onclick="encloseSelection('&lt;h3&gt;', '&lt;/h3&gt;')"
258          />
259          <tbl:button
260            tooltip="Header 4"
261            clazz="buttonclass"
262            style="padding: 1px;"
263            image="text_h4.png"
264            onclick="encloseSelection('&lt;h4&gt;', '&lt;/h4&gt;')"
265          />
266          <tbl:button
267            tooltip="Textstyle"
268            clazz="buttonclass"
269            image="text_style_edit.gif"
270            onclick="Menu.toggleTopMenu(document.getElementById('textformats'), event.clientX, event.clientY); event.cancelBubble = true;"
271          />           
272          <tbl:button
273            tooltip="Table"
274            clazz="buttonclass"
275            image="text_table.png"
276            onclick="Menu.toggleTopMenu(document.getElementById('tableitem'), event.clientX, event.clientY); event.cancelBubble = true;"
277          />
278          <tbl:button
279            tooltip="List"
280            clazz="buttonclass"
281            image="text_list.gif"
282            onclick="Menu.toggleTopMenu(document.getElementById('listtype'), event.clientX, event.clientY); event.cancelBubble = true;"
283          />
284          <tbl:button
285            tooltip="New line"
286            image="text_newline.gif" 
287            clazz="buttonclass"
288            onclick="encloseSelection('&lt;br&gt;', '')"
289          />
290          <tbl:button
291            tooltip="New paragraph"
292            clazz="buttonclass"
293            image="text_paragraph.gif"
294            onclick="encloseSelection('&lt;p&gt;', '&lt;/p&gt;')"
295          /> 
296          <tbl:button
297            tooltip="New link"
298            clazz="buttonclass"
299            image="text_link.png"
300            onclick="Menu.toggleTopMenu(document.getElementById('link'), event.clientX, event.clientY); event.cancelBubble = true;"
301          />             
302        </tbl:toolbar>
303        <%
304      }
305      %>
306      <textarea name="zoom" rows="30" cols="80" wrap="soft" 
307        <%=disabled ? "class=\"disabled\" disabled readonly" : ""%>></textarea>
308    </td>
309    </tr>
310    </table>
311 
312    <%
313    if (disabled)
314    {
315      %>
316      <table align="center">
317      <tr>
318        <td><base:button onclick="window.close()" title="Close" /></td>
319      </tr>
320      </table>
321      <%
322    }
323    else
324    {
325      %>
326      <table align="center">
327      <tr>
328        <td width="50%"><base:button onclick="setTextAndClose()" title="Ok" /></td>
329        <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
330      </tr>
331      </table>
332      <%
333    }
334    %>
335  </form>
336</base:body>
337</base:page>
Note: See TracBrowser for help on using the repository browser.