-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
130 lines (110 loc) · 3.76 KB
/
example.js
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
/**
* Mastering Ext.Direct example script
*
* @author Ing. Jozef Sakalos
* @copyright (c) 2009, by Ing. Jozef Sakalos
* @date 16. September 2009
* @version 1.0
* @revision $Id$
*/
Ext.BLANK_IMAGE_URL='ext/resources/images/default/s.gif';
Ext.onReady(function() {
/**
* This function is called when Ext.Direct request
* response arrives from the server.
*
* @param {String/Object/Array/Null} response
* That what is returned by server method
* @param {Ext.Direct.RemotingEvent/Ext.Direct.ExceptionEvent} e
*/
var callback = function(response, e) {
// uncomment if you want to inspect arguments in Firebug Console
// console.log(response, e);
var status = '<b>Success</b>'
var text = '';
// success handling - e.status is success flag:
// true is success, false is failure
if(true === e.status) {
// response argument is same as e.result
text = response;
}
// failure handling
else {
status = '<b><i>Failure</i></b>'
// in the case of an exception, we don't have response but message
text = e.message;
}
// grab the center body
var body = win.items.itemAt(1).body;
// display the response
body.createChild({
tag:'div'
,cls:'response'
,html:status + ': ' + text
});
// scroll down
body.scrollTo('top', 100000, true);
};
// create Ext.Direct test window
var win = new Ext.Window({
title:'Mastering Ext.Direct by Saki'
,width:600
,height:400
,closable:false
,layout:'border'
,border:false
,items:[{
// west region with buttons
region:'west'
,width:160
,minSize:160
,split:true
,defaults:{minWidth:120}
,layout:'table'
,bodyStyle:'padding:20px'
,layoutConfig:{columns:1, tableAttrs:{style:{width:'100%'}}}
,items:[{
xtype:'button'
,text:'Car.start()'
// a delegate is needed if we want to pass arguments
,handler:Anopier.Car.start.createDelegate(null, [callback])
},{
xtype:'button'
,text:'Car.go(80)'
// a delegate is needed if we want to pass arguments
,handler:Anopier.Car.go.createDelegate(null, [80, callback])
},{
xtype:'button'
,text:'Car.go(250)'
// a delegate is needed if we want to pass arguments
,handler:Anopier.Car.go.createDelegate(null, [250, callback])
},{
xtype:'button'
,text:'Car.stop()'
// a delegate is needed if we want to pass arguments
,handler:Anopier.Car.stop.createDelegate(null, [callback])
},{
xtype:'button'
,text:'Send All'
// another option is inline function that executes calls
,handler:function() {
// the following calls will be combined in one request
Anopier.Car.start(callback);
Anopier.Car.go(80, callback);
Anopier.Car.go(250, callback);
Anopier.Car.stop(callback);
}
}]
},{
// responses are displayed here
region:'center'
,autoScroll:true
,tbar:['->', {
text:'Clear'
,handler:function(){win.items.itemAt(1).body.update('')}
}]
}]
});
win.show();
});
// eof