r25048: From the archives (patch found in one of my old working trees):
[jelmer/samba4-debian.git] / webapps / qooxdoo-0.6.5-sdk / frontend / application / sample / source / html / test / RPC_1.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4   <title>qooxdoo &raquo; Demo &raquo; Sample</title>
5   <link type="text/css" rel="stylesheet" href="../../css/layout.css"/>
6   <!--[if IE]>
7   <link type="text/css" rel="stylesheet" href="../../css/layout_ie.css"/>
8   <![endif]-->
9   <script type="text/javascript" src="../../script/sample.js"></script>
10   <script type="text/javascript" src=".qxrpc"></script>
11   <!-- With the above script, the service URL for a J2EE application can be
12        automatically determined, no matter on what path it's deployed. -->
13 </head>
14 <body>
15   <script type="text/javascript" src="../../script/layout.js"></script>
16
17   <div id="demoDescription">
18     <p><strong>Only works together with a RPC backend!</strong></p>
19     <p>Test for RPC functionality.</p>
20     <p>
21       This test calls a simple echo-style service on the server. The server
22       method accepts a string and sends back a string that says
23       "Client said: [input string]".
24     </p>
25   </div>
26
27   <script type="text/javascript">
28 //    qx.Settings.setCustomOfClass("qx.io.remote.Exchange", "enableDebug", true);
29     qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true);
30
31     qx.core.Init.getInstance().defineMain(function() {
32       var layout1 = new qx.ui.layout.VerticalBoxLayout();
33       layout1.setTop(40);
34       layout1.setLeft(20);
35       layout1.setSpacing(4);
36
37       var async = new qx.ui.form.CheckBox("Asynchronous (must be checked if cross-domain is selected)");
38       layout1.add(async);
39
40       var crossDomain = new qx.ui.form.CheckBox("Cross Domain");
41       layout1.add(crossDomain);
42
43       layout1.add(new qx.ui.basic.Label("URL:"));
44       var defaultURL = qx.io.remote.Rpc.makeServerURL();
45       if (defaultURL == null) {
46         defaultURL = "/services/";
47       }
48       var url = new qx.ui.form.TextField(defaultURL);
49       layout1.add(url);
50
51       layout1.add(new qx.ui.basic.Label("Service:"));
52       var service = new qx.ui.form.TextField("qooxdoo.test");
53       layout1.add(service);
54
55       layout1.add(new qx.ui.basic.Label("Method:"));
56       var method = new qx.ui.form.TextField("echo");
57       layout1.add(method);
58
59       var layout2 = new qx.ui.layout.HorizontalBoxLayout();
60       layout2.setHeight("auto");
61       layout2.setVerticalChildrenAlign("middle");
62       layout2.setSpacing(4);
63       var message = new qx.ui.form.TextField("Hello");
64       message.setWidth(200);
65       layout2.add(message);
66       var send = new qx.ui.form.Button("Send to server");
67       layout2.add(send);
68       var abort = new qx.ui.form.Button("Abort");
69       abort.setEnabled(false);
70       layout2.add(abort);
71       layout1.add(layout2);
72
73       // We'll be setting url and service upon execute; no need to do it now.
74       var rpc = new qx.io.remote.Rpc();
75       rpc.setTimeout(10000);
76       var mycall = null;
77
78       send.addEventListener("execute", function() {
79         // Allow the user to reset the URL and Service on each call
80         rpc.setUrl(url.getValue());
81         rpc.setServiceName(service.getValue());
82         rpc.setCrossDomain(crossDomain.isChecked());
83
84         if (async.isChecked()) {
85           send.setEnabled(false);
86           abort.setEnabled(true);
87           mycall = rpc.callAsync(function(result, ex, id) {
88             mycall = null;
89             if (ex == null) {
90               alert("Async(" + id + ") result: " + result);
91             } else {
92               alert("Async(" + id + ") exception: " + ex);
93             }
94             send.setEnabled(true);
95             abort.setEnabled(false);
96           }, method.getValue(), message.getValue());
97         } else {
98           try {
99             var result = rpc.callSync(method.getValue(), message.getValue());
100             alert("Sync result: " + result);
101           } catch (ex) {
102             alert("Sync exception: " + ex);
103           }
104         }
105       });
106
107       abort.addEventListener("execute", function() {
108         rpc.abort(mycall);
109       });
110
111       var d = qx.ui.core.ClientDocument.getInstance();
112       d.add(layout1);
113     });
114   </script>
115 </body>
116 </html>