source: trunk/www/plugins/net/sf/basedb/plugins/jep_extra_value_calculator.jsp @ 2993

Last change on this file since 2993 was 2993, checked in by Nicklas Nordborg, 17 years ago

Fixes #215: Incorrect use of DynamicSpotQuery? in table view, plot function, filter function, etc.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.2 KB
Line 
1<%-- $Id: jep_extra_value_calculator.jsp 2993 2006-12-01 14:34:35Z 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  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.RawDataType"
33  import="net.sf.basedb.core.BioAssaySet"
34  import="net.sf.basedb.core.Formula"
35  import="net.sf.basedb.core.Job"
36  import="net.sf.basedb.core.ExtraValueType"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.Include"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46  import="java.util.List"
47%>
48<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
49<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
50<%!
51private static void addFormulaOption(StringBuilder options, String formula, String title, String description)
52{
53  options.append("<option value=\"").append(HTML.encodeTags(formula)).append("\"");
54  options.append(" title=\"").append(HTML.encodeTags(description)).append("\"");
55  options.append(">").append(HTML.encodeTags(title)).append("\n");
56}
57%>
58<%
59final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
60final String ID = sc.getId();
61ItemContext cc = (ItemContext)sc.getSessionSetting("plugin.configure.currentContext");
62if (cc == null) cc = sc.getCurrentContext(Item.BIOASSAYSET);
63DbControl dc = null;
64try
65{
66  String errorMessage = (String)sc.getSessionSetting("plugin.configure.errors.message");
67  List<Throwable> errors = (List<Throwable>)sc.getSessionSetting("plugin.configure.errors.list");
68 
69  dc = sc.newDbControl();
70  Job job = (Job)sc.getSessionSetting("plugin.configure.job");
71  dc.reattachItem(job);
72  BioAssaySet source = null;
73  if (job != null) source = (BioAssaySet)job.getParameterValue("source");
74  if (source == null && cc.getId() != 0) source = BioAssaySet.getById(dc, cc.getId());
75  if (source == null) throw new WebException("popup", "No current bioassay set", 
76    "Could not find any current bioassay set. Please select a bioassay set before trying again");
77  int maxRawMappings = source.getMaxRawMappingsForSpot();
78
79  RawDataType rdt = source.getRawDataType();
80 
81  // Current parameter values
82  ExtraValueType currentExtraValueType = (ExtraValueType)job.getParameterValue("extraValueType");
83  String expression = (String)job.getParameterValue("expression");
84 
85 
86  // Predefined formulas
87  ItemQuery<Formula> formulaQuery = Formula.getQuery(Formula.Type.COLUMN_EXPRESSION, rdt);
88  formulaQuery.order(Orders.asc(Hql.property("name")));
89  formulaQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
90  ItemResultList<Formula> formulas = formulaQuery.list(dc);
91  StringBuilder formulaOptions = new StringBuilder();
92  for (Formula f : formulas)
93  {
94    String formula = f.getFormula(0);
95    if (maxRawMappings == 1 || !formula.contains("raw("))
96    {
97      addFormulaOption(formulaOptions, formula, f.getName(), f.getDescription());
98    }
99  }
100 
101  // Load recently used items
102  List<ExtraValueType> recentExtraValueTypes = (List<ExtraValueType>)cc.getRecent(dc, Item.EXTRAVALUETYPE);
103  %>
104  <base:page type="popup" title="Calculate extra value">
105  <base:head styles="parameters.css">
106    <script language="JavaScript">
107    function hideErrorList()
108    {
109      Main.hide('errorlist');
110      Main.show('showerrorlist');
111    }
112    function showErrorList()
113    {
114      Main.show('errorlist');
115      Main.hide('showerrorlist');
116    }
117    function selectExtraValueTypeOnClick()
118    {
119      var frm = document.forms['extraValue'];
120      var url = '../../admin/extravaluetypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setExtraValueTypeCallback';
121      if (frm['parameter:extraValueType'].length > 1)
122      {
123        var id = Math.abs(parseInt(frm['parameter:extraValueType'][1].value));
124        url += '&item_id='+id;
125      }
126      Main.openPopup(url, 'SelectExtraValueType', 1000, 700);
127    }
128    function setExtraValueTypeCallback(id, name)
129    {
130      var frm = document.forms['extraValue'];
131      var list = frm['parameter:extraValueType'];
132      if (list.length < 1 || list[0].value == '0') // >
133      {
134        Forms.addListOption(list, 0, new Option());
135      }
136      list[0].value = id;
137      list[0].text = name;
138      list.selectedIndex = 0;
139    }
140   
141    function presetOnChange(list, formula, label)
142    {
143      var index = list.selectedIndex;
144      formula.value = list[index].value;
145      if (list[index].value != '' && label) label.value = list[index].text;
146    }
147    function openExpressionBuilder()
148    {
149      Main.expressionBuilder('<%=ID%>', 'Expression', 'extraValue', 'parameter:expression', 'COLUMN_EXPRESSION', '<%=rdt.getId()%>', <%=rdt.getChannels()%>, false, <%=source.getId()%>);
150    }
151    function validate()
152    {
153      var frm = document.forms['extraValue'];
154      if (frm['parameter:extraValueType'].selectedIndex < 0)
155      {
156        alert('You must select a type');
157        return false;
158      }
159      else if (Main.trimString(frm['parameter:expression'].value) == '')
160      {
161        alert('You must enter an expression for the extra value');
162        frm['parameter:expression'].focus();
163        return false;
164      }
165      <%
166      if (maxRawMappings != 1)
167      {
168        %>
169        else if (frm['parameter:expression'].value.search(/raw\(/) != -1)
170        {
171          alert('Can\'t use function raw() for bioassaysets with multiple mappings to raw data');
172          frm['parameter:expression'].focus();
173          return false;
174        }
175        <%
176      }
177      %>
178      return true;
179    }
180    function doNext()
181    {
182      if (validate())
183      {
184        var frm = document.forms['extraValue'];
185        frm.submit();
186      }
187    }   
188    </script>
189  </base:head>
190  <base:body>
191    <form name="extraValue" action="index.jsp" method="get" onsubmit="return false;">
192    <input type="hidden" name="ID" value="<%=ID%>">
193    <input type="hidden" name="cmd" value="SetParameters">
194    <input type="hidden" name="parameter:source" value="<%=source.getId()%>">
195   
196    <h3 class="docked">Calculate extra value <base:help helpid="jepextravaluecalculator.options"/></h3>
197    <div class="boxed">
198   
199    <%
200    if (errorMessage != null || (errors != null && errors.size() > 0))
201    {
202      %>
203      <div id="errors" style="margin-bottom: 12px;" class="parameterhelp">
204        <div class="error" style="margin: 0px;">
205        <%=errorMessage %>
206        </div>
207        <%
208        if (errors != null && errors.size() > 0)
209        {
210          %>
211          <div id="showerrorlist" style="display: none;">
212            <base:icon image="bullet.gif" /><a href="javascript:showErrorList()">Show details</a>
213          </div>
214          <div id="errorlist">
215          <ol>
216          <%
217          for (Throwable t : errors)
218          {
219            %>
220            <li><%=t.getMessage()%><br>
221            <%
222          }
223          %>
224          </ol>
225          <base:icon image="bullet.gif" /><a href="javascript:hideErrorList()">Hide details</a>
226          </div>
227          <%
228        }
229        %>
230      </div>
231      <%
232    }
233    %>
234
235      <table class="form" width="100%">
236      <tr valign="top">
237        <td class="prompt">Source bioassay set</td>
238        <td><%=HTML.encodeTags(source.getName())%></td>
239      </tr>
240      <tr>
241        <td class="prompt">Extra value type</td>
242        <td>
243          <base:select 
244            id="parameter:extraValueType"
245            clazz="selectionlist"
246            required="true"
247            current="<%=currentExtraValueType%>"
248            recent="<%=recentExtraValueTypes%>"
249            newitem="true"
250            onselect="selectExtraValueTypeOnClick()"
251          />
252        </td>
253      </tr>
254     
255      <tr>
256        <td class="prompt">Expression</td>
257        <td>
258        <select name="presets" style="width: 32em;"
259          onchange="presetOnChange(this, this.form['parameter:expression'])" 
260          >
261          <option value="">- select from list or enter formula below -
262          <%=formulaOptions.toString()%>
263        </select>
264        </td>
265      </tr>
266     
267      <tr valign="top">
268        <td>&nbsp;</td>
269        <td>
270          <table border="0" cellspacing="0" cellpadding="0">
271          <tr valign="top">
272          <td>
273            <textarea class="text required" name="parameter:expression" 
274              rows="4" cols="50"><%=HTML.encodeTags(expression)%></textarea>&nbsp;
275          </td>
276          <td><base:button onclick="openExpressionBuilder()" 
277            title="Expression builder&hellip;" 
278            image="expression_builder.gif"
279            tooltip="A simple utility for building expressions" />
280          </td>
281          </tr>
282          </table>
283        </td>
284      </tr>
285      </table>
286    </div>
287    </form>
288 
289    <table align="center">
290    <tr>
291      <td width="50%"><base:button onclick="doNext();" title="Next" /></td>
292      <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td>
293    </tr>
294    </table>
295  </base:body>
296  </base:page>
297  <%
298}
299finally
300{
301  if (dc != null) dc.close();
302}%>
Note: See TracBrowser for help on using the repository browser.