13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
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
Ext.require([
    'Ext.direct.*',
    'Ext.panel.Panel',
    'Ext.form.field.Text',
    'Ext.toolbar.TextItem'
]);
 
Ext.onReady(function(){
    
    function doEcho(field){
        TestAction.doEcho(field.getValue(), function(result, event){
            var transaction = event.getTransaction(),
                content = Ext.String.format('<b>Successful call to {0}.{1} with response:</b><pre>{2}</pre>',
                    transaction.action, transaction.method, Ext.encode(result));
            
            updateMain(content);
            field.reset();
        });
    }
    
    function doMultiply(field){
        TestAction.multiply(field.getValue(), function(result, event){
            var transaction = event.getTransaction(),
                content;
                
            if (event.status) {
                content = Ext.String.format('<b>Successful call to {0}.{1} with response:</b><pre>{2}</pre>',
                    transaction.action, transaction.method, Ext.encode(result));
            } else {
                content = Ext.String.format('<b>Call to {0}.{1} failed with message:</b><pre>{2}</pre>',
                    transaction.action, transaction.method, event.message);
            }
            updateMain(content);
            field.reset();
        });
    }
    
    function updateMain(content){
        main.update({
            data: content
        });
        main.body.scroll('b', 100000, true);
    }
    
    Ext.direct.Manager.addProvider(Ext.app.REMOTING_API, {
        type:'polling',
        url: 'php/poll.php',
        listeners: {
            data: function(provider, event){
                updateMain('<i>' + event.data + '</i>');
            }
        }
    });
    
    var main = Ext.create('Ext.panel.Panel', {
        // The id is used for styling
        id: 'logger',
        title: 'Remote Call Log',
        renderTo: document.body,
        width: 600,
        height: 300,
        tpl: '<p>{data}</p>',
        tplWriteMode: 'append',
        autoScroll: true,
        bodyPadding: 5,
        dockedItems: [{
            dock: 'bottom',
            xtype: 'toolbar',
            items: [{
                hideLabel: true,
                itemId: 'echoText',
                xtype: 'textfield',
                width: 300,
                emptyText: 'Echo input',
                listeners: {
                    specialkey: function(field, event){
                        if (event.getKey() === event.ENTER) {
                            doEcho(field);
                        }
                    }
                }
            }, {
                itemId: 'echo',
                text: 'Echo',
                handler: function(){
                    doEcho(main.down('#echoText'));
                }
            }, '-', {
                hideLabel: true,
                itemId: 'multiplyText',
                xtype: 'textfield',
                width: 90,
                emptyText: 'Multiply x 8',
                listeners: {
                    specialkey: function(field, event){
                        if (event.getKey() === event.ENTER) {
                            doMultiply(field);
                        }
                    }
                }
            }, {
                itemId: 'multiply',
                text: 'Multiply',
                handler: function(){
                    doMultiply(main.down('#multiplyText'));
                }
            }]
        }]
    });
});