]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/expressions/expression_engine_test.html
Release 6.4.0
[Github/sugarcrm.git] / tests / expressions / expression_engine_test.html
1 <!--
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 -->
38
39 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
40 <html lang='en'>
41 <head>
42 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
43
44 <title>SUGAR Arithmetic Engine (JS)</title>
45
46
47 <!-- yui js -->
48 <script type="text/javascript" src="../../cache/include/javascript/sugar_grp1_yui.js"></script>
49 <script type="text/javascript" src="../../cache/include/javascript/sugar_grp1.js"></script>
50
51
52 <!--  sugar expressions js -->
53 <!-- <script language="javascript" src="./javascript/ExpressionJS.php"></script> -->
54
55 <script language="javascript" src="../../include/Expressions/javascript/expressions.js"></script>
56 <script language="javascript" src="../../cache/Expressions/functions_cache.js"></script>
57
58 <!-- custom js -->
59 <script language="javascript">
60 YAHOO.util.Event.onDOMReady( function() {
61         var container = new YAHOO.widget.Overlay("container", {fixedcenter:true, visible:true, width:"400px"});
62         container.render();
63 });
64
65 function checkEnter(e) {
66         var characterCode; // literal character code will be stored in this variable
67
68         characterCode = e.keyCode;
69
70         if ( characterCode == 13 ) {
71                 evalExpression();
72                 document.getElementById('expression').select();
73                 return false;
74         } else {
75                 return true;
76         }
77 }
78
79 var i = 0;
80
81 function print_r(o, d) {
82         var ret = "";
83         if (d == null) d = 0;
84         if (typeof(o) == "object") {
85                 ret = "Array\n";
86                 for (var j = 0; j < d; j++) {
87                         ret += "\t";
88                 }
89                 ret += "(\n";
90                 for (i in o) {
91                         for (var j = 0; j <= d; j++) {
92                                 ret += "\t";
93                         }
94                         ret += "[" + i + "] => " + print_r(o[i], d + 2) + "\n"; 
95                 }
96                 for (var j = 0; j < d; j++) {
97                         ret += "\t";
98                 }
99                 ret += ")";
100         } else if (typeof(o != "undefined")){
101                 ret += o;
102         }
103         
104         return ret;
105 }
106
107 function evalExpression() {
108         var parser = new SUGAR.expressions.ExpressionParser();
109         var output = document.getElementById('results');
110         var expression = document.getElementById('expression').value;
111
112         if ( expression == 'clear' ) {
113                 init();
114                 return;
115         }
116
117         var out = "";
118
119         out += '<div class="expression">' + expression + ':</div>';
120
121         try {
122                 var result = parser.evaluate(expression);
123                 result = result.evaluate();
124                 out += '<div class="result" id="js_result_' + resultCount + '">' + print_r(result, 0) + "</div>";
125         } catch (e) {
126                 if (e.message)
127                         alert(e.message);
128                 out += '<div class="result" id="js_result_' + resultCount + '">' + e + "</div>";
129         }
130
131         out += "<div class='clearer'></div>";
132
133         var x = (i++%2);
134
135         output.innerHTML = "<div class='casing" + x + "'>" + out + "</div>" + output.innerHTML;
136         ajaxEvalExpression(expression);
137 }
138
139 function ajaxEvalExpression(expr) {
140         YAHOO.util.Connect.asyncRequest('POST', 'expression_engine_eval.php', 
141                 {
142                         success: function(o){
143                                 var output = document.getElementById('results');
144                                 output.innerHTML = "<div class='ajax result' id='php_result_" + resultCount + "'>" + o.responseText + "</div>" + output.innerHTML;
145                                 resultCount++;
146                         }
147                 }, "expression=" + expr);
148 }
149
150
151
152 function init() {
153         resultCount = 0;
154         document.getElementById('results').innerHTML = "";
155 }
156
157
158 window.onload = init;
159
160 </script>
161
162
163 <style type="text/css">
164
165 BODY {
166         background: #BFBFBF;
167         font-family: Trebuchet MS;
168 }
169
170 .expression {
171         font-size:  10pt;
172         float: left;
173 }
174
175 .casing0 {
176         padding: 5px;
177         background: #E4E4E4;
178 }
179
180 .casing1 {
181         padding: 5px;
182         background: #f4f4f4;
183 }
184
185 .ajax {
186         padding: 5px;
187         background: #a0f4a0;
188 }
189
190 .result {
191         font-family: Verdana;
192         font-size: 10pt;
193         font-weight: bold;
194         float: right;
195 }
196
197 .clearer {
198         clear: both;
199 }
200
201 #results {
202         margin: 0 auto;
203         width: 350px;
204         height: 350px;
205         border: 1px solid #cccccc;
206         overflow:auto;
207         padding: 10px;
208         background: #ffffff;
209 }
210
211
212 #container {
213         width: 400px;
214         margin: 0 auto;
215         height: 400px;
216         background: #ffffff;
217         background: #EFEFEF;
218         border: 1px solid #000;
219         padding: 30px;
220 }
221
222
223 #input {
224         text-align: center;
225         height: 50px;
226         margin: 0 auto;
227 }
228
229 #input INPUT[type=text] {
230         font-family: Courier New;
231 }
232
233 </style>
234
235 </head>
236
237 <body>
238
239 <!-- div id="overlay" style="width: 100%; height: 100%;position: absolute; left: 0px; top: 0px; background: #BFBFBF; z-index: -10;"></div -->
240
241
242 <div id="container">
243
244         <div id="results">
245         </div>
246
247         <div id="input">
248                 <input type="text" id="expression" style="width: 288px" onkeypress="checkEnter(event)">
249                 <input type="button" id="evaluate_button" value="Evaluate" onclick="evalExpression()">
250                 <input type="button" id="clear_button" value="Clear" onclick="init()">
251         </div>
252
253 </div>
254
255 </body>
256
257 </html>