source: trunk/www/views/reporterlists/edit_reporterlist.jsp @ 6217

Last change on this file since 6217 was 6217, checked in by Nicklas Nordborg, 10 years ago

References #1730: Move in-page onEvent attributes to external *.js files

Got rid of 'clazz' and 'requiredClazz' string constatns used in several JSP scripts. Better to specify class="" directly on each element since there are cases were we want to add more variants.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.6 KB
Line 
1<%-- $Id: edit_reporterlist.jsp 6217 2012-12-14 13:05:00Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, 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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.ItemContext"
30  import="net.sf.basedb.core.Permission"
31  import="net.sf.basedb.core.ReporterList"
32  import="net.sf.basedb.core.PermissionDeniedException"
33  import="net.sf.basedb.clients.web.Base"
34  import="net.sf.basedb.clients.web.util.HTML"
35  import="net.sf.basedb.util.Values"
36  import="net.sf.basedb.core.plugin.GuiContext"
37  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
38  import="net.sf.basedb.clients.web.extensions.JspContext"
39  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
40  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
41  import="java.util.List"
42%>
43<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
44<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
45<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
46<%
47final Item itemType = Item.REPORTERLIST;
48final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
49final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
50final int itemId = cc.getId();
51final String ID = sc.getId();
52final float scale = Base.getScale(sc);
53final DbControl dc = sc.newDbControl();
54try
55{
56  String title = null;
57  String name = null;
58  ReporterList reporterList = null;
59  boolean addReporters = false;
60  boolean mergeReporterLists = false;
61  int numSelectedLists = cc.getSelected().size();
62  String formId = request.getParameter("formId");
63  String fromContext = Values.getString(request.getParameter("fromContext"), "REPORTER");
64  String subContext = request.getParameter("subContext");
65
66  if (itemId == 0)
67  {
68    title = "Create reporter list";
69    cc.removeObject("item");
70    addReporters = Values.getBoolean(request.getParameter("addReporters"));
71    mergeReporterLists = !addReporters && numSelectedLists > 0;
72    name = request.getParameter("name");
73    if (name == null) name = Values.getString(cc.getPropertyValue("name"), "New reporter list");
74  }
75  else
76  {
77    reporterList = ReporterList.getById(dc, itemId);
78    name = reporterList.getName();
79    cc.setObject("item", reporterList);
80    title = "Edit reporter list -- " + HTML.encodeTags(reporterList.getName());
81  }
82  if (reporterList != null) reporterList.checkPermission(Permission.WRITE);
83 
84 
85 
86  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), reporterList);
87  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
88  %>
89  <base:page type="popup" title="<%=title%>">
90  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
91    <ext:scripts context="<%=jspContext%>" />
92    <ext:stylesheets context="<%=jspContext%>" />
93    <script>
94    // Validate the "Reporter list" tab
95    function validateReporterList()
96    {
97      var frm = document.forms['reporterList'];
98      if (Main.trimString(frm.name.value) == '')
99      {
100        Forms.showNotification(frm.name, 'You must enter a name');
101        return false;
102      }
103      if (frm.minCount)
104      {
105        var checked = Forms.getCheckedRadio(frm.create);
106        if (checked.value == 'count')
107        {
108          if (!Numbers.isInteger(frm.minCount.value))
109          {
110            Forms.showNotification(frm.minCount, 'You must specify the number of reporter lists');
111            return false;
112          }
113          else
114          {
115            var minCount = parseInt(frm.minCount.value);
116            if (minCount < 1 || minCount > <%=numSelectedLists%>)
117            {
118              Forms.showNotification(frm.minCount, 'You must specify a value between 1 and <%=numSelectedLists%>');
119              return false;
120            }
121          }
122        }
123      }
124      return true;
125    }
126
127    // Submit the form
128    function saveSettings()
129    {
130      var frm = document.forms['reporterList'];
131      if (TabControl.validateActiveTab('settings'))
132      {
133        if (frm.which) Forms.createHidden(frm, 'items', getSelectedItems().join(','));
134        frm.submit();
135      }
136    }
137   
138    function init()
139    {
140      var frm = document.forms['reporterList'];
141      <%
142      if (reporterList == null)
143      {
144        %>
145        frm.name.focus();
146        frm.name.select();
147        <%
148      }
149      %>
150      if (frm.which && getSelectedItems().length == 0)
151      {
152        frm.which[0].disabled = true;
153        var lblSelected = document.getElementById('lblSelected');
154        lblSelected.disabled = true;
155        Main.addClass(lblSelected, 'disabled');
156      }
157    }
158    // Get the ID:s of all selected reorters
159    var selectedItems = new Array();
160    var hasCheckSelectedItems = false;
161    function getSelectedItems()
162    {
163      <%
164      if (formId != null)
165      {
166        %>
167        if (!hasCheckSelectedItems)
168        {
169          selectedItems = window.opener.Table.getSelected('<%=formId%>');
170          hasCheckedSelectedItems = true;
171        }
172        <%
173      }
174      %>
175      return selectedItems;
176    }
177    function checkRadio(radio, name)
178    {
179      Forms.checkRadio(radio, name);
180    }
181    </script>
182  </base:head>
183  <base:body onload="init()">
184    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
185    <form action="index.jsp?ID=<%=ID%>" method="post" name="reporterList">
186    <input type="hidden" name="cmd" value="UpdateItem">
187    <input type="hidden" name="fromContext" value="<%=fromContext%>">
188    <%
189    if (subContext != null)
190    {
191      %>
192      <input type="hidden" name="subContext" value="<%=subContext%>">
193      <%
194    }
195    %>
196    <t:tabcontrol id="settings"
197      subclass="content dialogtabcontrol"
198      position="bottom" remember="<%=reporterList != null%>"
199      extensions="<%=invoker%>">
200    <t:tab id="info" title="Reporter list" 
201      validate="validateReporterList()" helpid="reporterlist.edit">
202      <table class="fullform input100">
203      <tr>
204        <th>Name</th>
205        <td><input class="text required" type="text" name="name" 
206          value="<%=HTML.encodeTags(name)%>" 
207          maxlength="<%=ReporterList.MAX_NAME_LENGTH%>"></td>
208        <td></td>
209      </tr>
210      <tr>
211        <th>External ID</th>
212        <td><input class="text" type="text" name="external_id" 
213          value="<%=HTML.encodeTags(reporterList == null ? Values.getString(cc.getPropertyValue("externalId")) : reporterList.getExternalId())%>" 
214          maxlength="<%=ReporterList.MAX_EXTERNAL_ID_LENGTH%>"></td>
215        <td></td>
216      </tr>
217      <%
218      if (addReporters)
219      {
220        %>
221        <tr>
222          <th>Which reporters?</th>
223          <td>
224            <input type="radio" name="which" id="whichSelected" value="selected"
225              ><label for="whichSelected" id="lblSelected">Selected items</label><br>
226            <input type="radio" name="which" id="whichPage" value="page"
227              ><label for="whichPage">Current page</label><br>
228            <input type="radio" name="which" id="whichAll" value="all" checked
229              ><label for="whichAll">All pages</label><br>
230          </td>
231          <td></td>
232        </tr>
233        <%
234      }
235      else if (mergeReporterLists)
236      {
237        %>
238        <tr>
239          <th>Add reporters?</th>
240          <td>
241            <input type="radio" name="create" id="createEmpty" value=""
242              ><label for="createEmpty"
243              title="The new reporter list will be empty">No</label><br>
244            <input type="radio" name="create" id="createUnion" value="union" checked
245              ><label for="createUnion" 
246                title="The new reporter list contains all reporters from the selected lists"
247                >Union of selected lists</label> 
248                <base:icon image="set_operations/union_small.png" /><br>
249            <input type="radio" name="create" id="createIntersection" value="intersection"
250              ><label for="createIntersection" 
251                title="The new reporter lists contains only reporters that are present in ALL selected lists"
252                >Intersection of selected lists</label> 
253                <base:icon image="set_operations/intersection_small.png" /><br>
254            <input type="radio" name="create" id="createCount" value="count"
255              ><label for="createCount"
256                title="The new reporter lists contains only reporters that are present in some of selected lists"
257                >Present in at least</label>
258              <input type="text" class="text" name="minCount" size="2" maxlength="2"
259                value="1"
260                onkeypress="return Numbers.integerOnly(event)"
261                onfocus="checkRadio(document.forms['reporterList'].create, 'count');">
262              of the selected lists (1-<%=numSelectedLists%>).
263              <br>
264          </td>
265          <td></td>
266        </tr>
267        <%
268      }
269      %>
270      <tr class="dynamic">
271        <th>Description</th>
272        <td>
273          <textarea class="text" rows="6" name="description" id="description"
274            ><%=HTML.encodeTags(reporterList == null ? cc.getPropertyValue("description") : reporterList.getDescription())%></textarea>
275        </td>
276        <td style="width: 20px;">
277          <base:zoom textarea="description" title="Description" />
278        </td>
279      </tr>
280      </table>
281    </t:tab>
282    </t:tabcontrol>
283    </form>
284
285    <div class="legend">
286      <base:icon image="required.png" />= required information
287    </div>
288
289    <base:buttongroup subclass="dialogbuttons">
290      <base:button onclick="saveSettings()" title="Save" />
291      <base:button onclick="window.close()" title="Cancel" />
292    </base:buttongroup>
293  </base:body>
294  </base:page>
295  <%
296}
297finally
298{
299  if (dc != null) dc.close();
300}
301%>
Note: See TracBrowser for help on using the repository browser.