statusbar-demo.js
6.54 KB
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
/*
* Ext JS Library 2.1
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.onReady(function(){
// This is a shared function that simulates a load action on a StatusBar.
// It is reused by most of the example panels.
var loadFn = function(btn, statusBar){
btn = Ext.getCmp(btn);
statusBar = Ext.getCmp(statusBar);
btn.disable();
statusBar.showBusy();
(function(){
statusBar.clearStatus({useDefaults:true});
btn.enable();
}).defer(2000);
};
/*
* ================ Basic StatusBar example =======================
*/
new Ext.Panel({
title: 'Basic StatusBar',
renderTo: 'basic',
width: 350,
height: 100,
bodyStyle: 'padding:10px;',
items:[{
xtype: 'button',
id: 'basic-button',
text: 'Do Loading',
handler: loadFn.createCallback('basic-button', 'basic-statusbar')
}],
bbar: new Ext.StatusBar({
defaultText: 'Default status',
id: 'basic-statusbar',
items: [{
text: 'A Button'
}, '-', 'Plain Text', ' ', ' ']
})
});
/*
* ================ Right-aligned StatusBar example =======================
*/
new Ext.Panel({
title: 'Right-aligned StatusBar',
renderTo: 'right-aligned',
width: 350,
height: 100,
bodyStyle: 'padding:10px;',
items:[{
xtype: 'button',
id: 'right-button',
text: 'Do Loading',
handler: loadFn.createCallback('right-button', 'right-statusbar')
}],
bbar: new Ext.StatusBar({
defaultText: 'Default status',
id: 'right-statusbar',
statusAlign: 'right', // the magic config
items: [{
text: 'A Button'
}, '-', 'Plain Text', ' ', ' ']
})
});
/*
* ================ StatusBar Window example =======================
*/
var win = new Ext.Window({
title: 'StatusBar Window',
width: 400,
minWidth: 350,
height: 150,
modal: true,
closeAction: 'hide',
bodyStyle: 'padding:10px;',
items:[{
xtype: 'button',
id: 'win-button',
text: 'Do Loading',
handler: loadFn.createCallback('win-button', 'win-statusbar')
}],
bbar: new Ext.StatusBar({
id: 'win-statusbar',
items: [{
text: 'A Button'
}, '-',
new Date().format('n/d/Y'), ' ', ' ', '-', {
xtype:'tbsplit',
text:'Status Menu',
menuAlign: 'br-tr?',
menu: new Ext.menu.Menu({
items: [{text: 'Item 1'}, {text: 'Item 2'}]
})
}]
})
});
new Ext.Button({
text: 'Show Window',
renderTo: 'window',
handler: function(){
win.show();
}
});
/*
* ================ Ext Word Processor example =======================
*
* The StatusBar used in this example is completely standard. What is
* customized are the styles and event handling to make the example a
* lot more dynamic and application-oriented.
*
*/
// Create these explicitly so we can manipulate them later
var wordCount = new Ext.Toolbar.TextItem('Words: 0');
var charCount = new Ext.Toolbar.TextItem('Chars: 0');
var clock = new Ext.Toolbar.TextItem('');
new Ext.Panel({
title: 'Ext Word Processor',
renderTo: 'word-proc',
width: 500,
autoHeight: true,
bodyStyle: 'padding:5px;',
layout: 'fit',
bbar: new Ext.StatusBar({
id: 'word-status',
// These are just the standard toolbar TextItems we created above. They get
// custom classes below in the render handler which is what gives them their
// customized inset appearance.
items: [wordCount, ' ', charCount, ' ', clock, ' ']
}),
items: {
xtype: 'textarea',
id: 'word-textarea',
enableKeyEvents: true,
grow: true,
growMin: 100,
growMax: 200,
listeners: {
// After each keypress update the word and character count text items
'keypress': {
fn: function(t){
var v = t.getValue(),
wc = 0, cc = v.length ? v.length : 0;
if(cc > 0){
wc = v.match(/\b/g);
wc = wc ? wc.length / 2 : 0;
}
Ext.fly(wordCount.getEl()).update('Words: '+wc);
Ext.fly(charCount.getEl()).update('Chars: '+cc);
},
buffer: 1 // buffer to allow the value to update first
}
}
},
listeners: {
'render': {
fn: function(){
// Add a class to the parent TD of each text item so we can give them
// some custom inset box styling:
Ext.fly(wordCount.getEl().parentNode).addClass('x-status-text-panel');
Ext.fly(charCount.getEl().parentNode).addClass('x-status-text-panel');
Ext.fly(clock.getEl().parentNode).addClass('x-status-text-panel');
// Kick off the clock timer that updates the clock el every second:
Ext.TaskMgr.start({
run: function(){
Ext.fly(clock.getEl()).update(new Date().format('g:i:s A'));
},
interval: 1000
});
}
}
}
});
// This sets up a fake auto-save function. It monitors keyboard activity and after no typing
// has occurred for 1.5 seconds, it updates the status message to indicate that it's saving.
// After a fake delay so that you can see the save activity it will update again to indicate
// that the action succeeded.
Ext.fly('word-textarea').on('keypress', function(){
var sb = Ext.getCmp('word-status');
sb.showBusy('Saving draft...');
(function(){
sb.setStatus({
iconCls: 'x-status-saved',
text: 'Draft auto-saved at ' + new Date().format('g:i:s A')
});
}).defer(4000);
}, this, {buffer:1500});
});