summaryrefslogtreecommitdiff
path: root/swat.obsolete/apps/qooxdoo-examples/test/Transport_6.html
blob: bed19e60d884923ac4426e428f28c0f002a880f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>qooxdoo &raquo; Demo</title>
  <link type="text/css" rel="stylesheet" href="../../resource/css/layout.css"/>
  <!--[if IE]>
  <link type="text/css" rel="stylesheet" href="../../resource/css/layout_ie.css"/>
  <![endif]-->
  <script type="text/javascript" src="../../script/qx.js"></script>
</head>
<body>
  <script type="text/javascript" src="../../script/layout.js"></script>

  <div id="demoDescription">
    <p>Simple test for qooxdoo's transport implementation using some data for an addressbook.</p>
    <p>Using javascript/json content in this case.</p>
  </div>

  <script type="text/javascript">
  qx.core.Init.getInstance().defineMain(function()
  {
    var d = qx.ui.core.ClientDocument.getInstance();

    var lay = new qx.ui.layout.VerticalBoxLayout;
    lay.setLocation(20, 48);
    lay.setRight(335);
    lay.setBottom(48);
    qx.ui.core.ClientDocument.getInstance().add(lay);



    var fsq = new qx.ui.groupbox.GroupBox("Request");
    fsq.setHeight("auto");
    lay.add(fsq);


    var hlay = new qx.ui.layout.HorizontalBoxLayout;
    hlay.setVerticalChildrenAlign("middle");
    hlay.setSpacing(4);
    hlay.auto();
    fsq.add(hlay);


    var cm1 = new qx.ui.form.ComboBox();
    cm1.add(new qx.ui.form.ListItem("data/persons/anita.js"));
    cm1.add(new qx.ui.form.ListItem("data/persons/harald.js"));
    cm1.add(new qx.ui.form.ListItem("data/persons/lisbeth.js"));
    cm1.add(new qx.ui.form.ListItem("data/persons/paul.js"));
    cm1.setSelected(cm1.getList().getFirstChild());
    cm1.setWidth(200);
    cm1.addEventListener("changeSelected", upd);

    hlay.add(cm1);



    var async = new qx.ui.form.CheckBox("Async");
    async.setChecked(true);
    hlay.add(async);


    var spin = new qx.ui.form.Spinner(1);
    hlay.add(spin);



    var btn = new qx.ui.form.Button("Send", "icon/16/apply.png");
    btn.addEventListener("execute", upd);
    hlay.add(btn);


    var inf = new qx.ui.form.TextField("State");
    inf.setWidth(80);
    inf.setReadOnly(true);
    hlay.add(inf);


    var code = new qx.ui.form.TextField("Code");
    code.setWidth(30);
    code.setReadOnly(true);
    hlay.add(code);


    var typ = new qx.ui.form.TextField("Type");
    typ.setWidth(80);
    typ.setReadOnly(true);
    hlay.add(typ);


    var len = new qx.ui.form.TextField("Length");
    len.setWidth(50);
    len.setReadOnly(true);
    hlay.add(len);


    var checken = new qx.ui.form.CheckBox("enabled");
    checken.setChecked(true);
    hlay.add(checken);

    checken.addEventListener("changeChecked", function(e) {
      qx.io.remote.RemoteRequestQueue.setEnabled(e.getData());
    });





    var fsr = new qx.ui.groupbox.GroupBox("Result");
    fsr.setHeight("1*");
    lay.add(fsr);

    var area = new qx.ui.layout.VerticalBoxLayout;
    area.setSpacing(6);
    area.setDimension("100%", "100%");
    fsr.add(area);



    var fgivenname = new qx.ui.basic.Label("Given Name");
    var fname = new qx.ui.basic.Label("Name");
    var fage = new qx.ui.basic.Label("Age");
    var fstreet = new qx.ui.basic.Label("Street");
    var fplz = new qx.ui.basic.Label("PLZ");
    var fcity = new qx.ui.basic.Label("City");
    var fcountry = new qx.ui.basic.Label("Country");
    var fphone = new qx.ui.basic.Label("Phone");

    area.add(fgivenname, fname, fage, fstreet, fplz, fcity, fcountry, fphone);







    function upd(e)
    {
      var val = cm1.getSelected();

      if (!val) {
        return;
      };

      var req;
      for( var i=0, max=parseInt(spin.getValue()); i<max; i++ )
      {
        req = new qx.io.remote.RemoteRequest(val.getLabel(), "GET", "text/json");

        req.setAsynchronous(async.getChecked());
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

        req.setParameter("test1", "value1");
        req.setParameter("test2", "value2");
        req.setParameter("test3", "value3");

        // Force to testing iframe implementation
        // req.setCrossDomain(true);

        // This combination couldn't be handled currently
        // req.setCrossDomain(true);
        // req.setAsynchronous(false);

        req.addEventListener("sending", function(e) {
          inf.setValue("Sending");
        });

        req.addEventListener("receiving", function(e) {
          inf.setValue("Receiving");
        });

        req.addEventListener("completed", function(e)
        {
          inf.setValue("Completed");
          typ.setValue(e.getData().getResponseHeader("Content-Type"));
          len.setValue(e.getData().getResponseHeader("Content-Length"));
          code.setValue(e.getData().getStatusCode().toString());

          var vContent = e.getData().getContent();

          fgivenname.setHtml(vContent.givenName.toString());
          fname.setHtml(vContent.name.toString());
          fage.setHtml(vContent.age.toString());
          fstreet.setHtml(vContent.street.toString());
          fplz.setHtml(vContent.plz.toString());
          fcity.setHtml(vContent.city.toString());
          fcountry.setHtml(vContent.country.toString());
          fphone.setHtml(vContent.phone.toString());

          qx.ui.core.Widget.flushGlobalQueues();
        });

        req.addEventListener("failed", function(e)
        {
          inf.setValue("Failed");
          typ.setValue(e.getData().getResponseHeader("Content-Type"));
          len.setValue(e.getData().getResponseHeader("Content-Length"));
          code.setValue(e.getData().getStatusCode().toString());
        });

        req.addEventListener("timeout", function(e)
        {
          inf.setValue("Timeout");
          typ.setValue(e.getData().getResponseHeader("Content-Type"));
          len.setValue(e.getData().getResponseHeader("Content-Length"));
          code.setValue(e.getData().getStatusCode().toString());
        });

        req.addEventListener("aborted", function(e)
        {
          inf.setValue("Aborted");
          typ.setValue(e.getData().getResponseHeader("Content-Type"));
          len.setValue(e.getData().getResponseHeader("Content-Length"));
          code.setValue(e.getData().getStatusCode().toString());
        });

        req.send();
      };
    };
  });
  </script>
</body>
</html>