/ext-4.0.7/examples/direct/direct.js
JavaScript | 124 lines | 101 code | 9 blank | 14 comment | 4 complexity | 2fd9b129d5696c1d7282fad1e3aa522e MD5 | raw file
1/*
2
3This file is part of Ext JS 4
4
5Copyright (c) 2011 Sencha Inc
6
7Contact: http://www.sencha.com/contact
8
9GNU General Public License Usage
10This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14*/
15Ext.require([
16 'Ext.direct.*',
17 'Ext.panel.Panel',
18 'Ext.form.field.Text',
19 'Ext.toolbar.TextItem'
20]);
21
22Ext.onReady(function(){
23
24 function doEcho(field){
25 TestAction.doEcho(field.getValue(), function(result, event){
26 var transaction = event.getTransaction(),
27 content = Ext.String.format('<b>Successful call to {0}.{1} with response:</b><pre>{2}</pre>',
28 transaction.action, transaction.method, Ext.encode(result));
29
30 updateMain(content);
31 field.reset();
32 });
33 }
34
35 function doMultiply(field){
36 TestAction.multiply(field.getValue(), function(result, event){
37 var transaction = event.getTransaction(),
38 content;
39
40 if (event.status) {
41 content = Ext.String.format('<b>Successful call to {0}.{1} with response:</b><pre>{2}</pre>',
42 transaction.action, transaction.method, Ext.encode(result));
43 } else {
44 content = Ext.String.format('<b>Call to {0}.{1} failed with message:</b><pre>{2}</pre>',
45 transaction.action, transaction.method, event.message);
46 }
47 updateMain(content);
48 field.reset();
49 });
50 }
51
52 function updateMain(content){
53 main.update({
54 data: content
55 });
56 main.body.scroll('b', 100000, true);
57 }
58
59 Ext.direct.Manager.addProvider(Ext.app.REMOTING_API, {
60 type:'polling',
61 url: 'php/poll.php',
62 listeners: {
63 data: function(provider, event){
64 updateMain('<i>' + event.data + '</i>');
65 }
66 }
67 });
68
69 var main = Ext.create('Ext.panel.Panel', {
70 id: 'logger',
71 title: 'Remote Call Log',
72 renderTo: document.body,
73 width: 600,
74 height: 300,
75 tpl: '<p>{data}</p>',
76 tplWriteMode: 'append',
77 autoScroll: true,
78 bodyStyle: 'padding: 5px;',
79 dockedItems: [{
80 dock: 'bottom',
81 xtype: 'toolbar',
82 items: [{
83 hideLabel: true,
84 itemId: 'echoText',
85 xtype: 'textfield',
86 width: 300,
87 emptyText: 'Echo input',
88 listeners: {
89 specialkey: function(field, event){
90 if (event.getKey() === event.ENTER) {
91 doEcho(field);
92 }
93 }
94 }
95 }, {
96 itemId: 'echo',
97 text: 'Echo',
98 handler: function(){
99 doEcho(main.down('#echoText'));
100 }
101 }, '-', {
102 hideLabel: true,
103 itemId: 'multiplyText',
104 xtype: 'textfield',
105 width: 80,
106 emptyText: 'Multiply x 8',
107 listeners: {
108 specialkey: function(field, event){
109 if (event.getKey() === event.ENTER) {
110 doMultiply(field);
111 }
112 }
113 }
114 }, {
115 itemId: 'multiply',
116 text: 'Multiply',
117 handler: function(){
118 doMultiply(main.down('#multiplyText'));
119 }
120 }]
121 }]
122 });
123});
124