source: trunk/www/common/help/view_help.jsp @ 2978

Last change on this file since 2978 was 2978, checked in by Nicklas Nordborg, 15 years ago

Added session="false" to all jsp pages so we no longer generate unneeded cookies

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1<%-- $Id: view_help.jsp 2978 2006-11-30 07:27:42Z nicklas $
2  ------------------------------------------------------------------
3  BioArray Software Environment (BASE) - http://base.thep.lu.se/
4  Copyright (C) 2006 Martin Svensson
5
6  This file is part of BASE.
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 popupwindow viewing a particular helpsection.
25
26  @param helpid The externalid of the helpsection to display.
27
28  @author Martin
29  @version 2.0
30--%>
31<%@ page session="false"
32  import="net.sf.basedb.core.Client"
33  import="net.sf.basedb.core.DbControl"
34  import="net.sf.basedb.core.Help" 
35  import="net.sf.basedb.core.Permission"
36  import="net.sf.basedb.core.SessionControl"   
37  import="net.sf.basedb.core.ItemNotFoundException"
38  import="net.sf.basedb.clients.web.Base" 
39  import="net.sf.basedb.util.Values"
40  import="net.sf.basedb.clients.web.util.HTML"
41  import="java.util.regex.Pattern"
42  import="java.util.regex.Matcher"
43%>
44<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
45<%!
46private static final Pattern findTag = Pattern.compile("\\{\\@(\\w+)\\s([^\\s]+)\\s*(.*)\\}");
47private String parseTags(String ID, Help help, int includeLevel)
48{
49  StringBuffer sb = new StringBuffer();
50  Matcher m = findTag.matcher(help.getDescription());
51  while (m.find())
52  {
53    String cmd = m.group(1);
54    if ("link".equals(cmd))
55    {
56      m.appendReplacement(sb, "<a href=\"view_help.jsp?ID="+ID+"&external_id=$2\">$3</a>"); 
57    }
58    else if ("include".equals(cmd))
59    {
60      if (includeLevel >= 10)
61      {
62        m.appendReplacement(sb, "[<a href=\"view_help.jsp?ID="+ID+"&external_id=$2\">$2</a>]");
63      }
64      else
65      {
66        String externalId = m.group(2);
67        Help included = null;
68        try
69        {
70          Client c = help.getClient();
71          DbControl dc = help.getDbControl();
72          included = c.getHelpByExternalId(dc, externalId, false);
73        }
74        catch (Throwable t)
75        {}
76        if (included != null)
77        {
78          String includedHelp = parseTags(ID, included, includeLevel+1);
79          m.appendReplacement(sb, includedHelp);
80        }
81      }
82    }
83    else
84    {
85      m.appendReplacement(sb, "cmd=$1, id=$2, rest=$3");
86    }
87  }
88  m.appendTail(sb);
89  return sb.toString();
90}
91%>
92<%
93final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
94final String ID = sc.getId();
95final float scale = Base.getScale(sc);
96final DbControl dc = sc.newDbControl();
97final int clientId = sc.getClientId();
98
99String externalId = request.getParameter("external_id");
100
101try
102{
103  Client c = Client.getById(dc, clientId);
104  Help help = null;
105  String title = "Help is not available";
106  String description = null;
107  boolean writePermission = c.hasPermission(Permission.WRITE);
108 
109  try
110  {
111    help = c.getHelpByExternalId(dc, externalId, false);
112    title = help.getName();
113    description = parseTags(ID, help, 0);
114    writePermission = help.hasPermission(Permission.WRITE);
115  }
116  catch (ItemNotFoundException ex)
117  {}
118%>
119
120  <base:page type="popup" title="Help">
121  <base:head>
122  <script language="JavaScript">
123  function editHelpText()
124  {
125    Main.viewOrEditItem('<%=ID%>', 'HELP', <%=help == null ? 0 : help.getId()%>, true, '&client_id=<%=clientId%>&external_id=<%=externalId%>');
126  }
127  </script>
128  </base:head>
129  <base:body>
130   
131    <h3 class="docked"><%=title%></h3>
132    <div class="boxed" style="height: <%=(int)(scale*440)%>px; overflow: auto;">
133    <%
134    if (help == null || description == null)
135    {
136      %>
137      <div class="error">
138      <br>
139      The help text for the section <b><%=externalId%></b> is not
140      written yet.
141      <br><br>
142      </div>
143      <%
144    }
145    else
146    {
147      %>
148      <%=description%>
149      <%
150    }
151    %>
152    </div>
153    <br>
154    <base:buttongroup align="center">
155      <base:button image="edit.gif" title="Edit&hellip;" 
156        onclick="editHelpText()" visible="<%=writePermission && description != null%>" 
157        tooltip="Edit this help text" />
158      <base:button image="new.gif" title="Create&hellip;"
159        onclick="editHelpText()" visible="<%=writePermission && description == null%>"
160        tooltip="Create this help text" />
161      <base:button image="back.gif" title="Back" onclick="history.go(-1)" />
162      <base:button title="Close" 
163        onclick="window.close()" />
164    </base:buttongroup>
165  </base:body>
166  </base:page>
167  <%
168}
169finally
170{
171  if (dc != null) dc.close();
172}
173%>
Note: See TracBrowser for help on using the repository browser.