3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This 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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 Ext.Loader.setConfig({
19 Ext.Loader.setPath('Ext.ux', '../ux/');
25 'Ext.ux.statusbar.StatusBar',
26 'Ext.toolbar.TextItem',
30 'Ext.form.field.TextArea'
33 Ext.onReady(function(){
35 // This is a shared function that simulates a load action on a StatusBar.
36 // It is reused by most of the example panels.
37 var loadFn = function(btn, statusBar){
38 btn = Ext.getCmp(btn);
39 statusBar = Ext.getCmp(statusBar);
45 statusBar.clearStatus({useDefaults:true});
51 * ================ Basic StatusBar example =======================
53 Ext.create('Ext.Panel', {
54 title: 'Basic StatusBar',
58 bodyStyle: 'padding:10px;',
63 handler: Ext.Function.pass(loadFn, ['basic-button', 'basic-statusbar'])
65 bbar: Ext.create('Ext.ux.StatusBar', {
66 id: 'basic-statusbar',
68 // defaults to use when the status is cleared:
69 defaultText: 'Default status text',
70 //defaultIconCls: 'default-icon',
72 // values to set initially:
74 iconCls: 'x-status-valid',
76 // any standard Toolbar items:
80 text: 'Show Warning & Clear',
82 var sb = Ext.getCmp('basic-statusbar');
85 iconCls: 'x-status-error',
86 clear: true // auto-clear after a set interval
94 var sb = Ext.getCmp('basic-statusbar');
95 // Set the status bar to show that something is processing:
101 text: 'Clear status',
102 handler: function (){
103 var sb = Ext.getCmp('basic-statusbar');
115 * ================ Right-aligned StatusBar example =======================
117 Ext.create('Ext.Panel', {
118 title: 'Right-aligned StatusBar',
119 renderTo: 'right-aligned',
122 bodyStyle: 'padding:10px;',
127 handler: Ext.Function.pass(loadFn, ['right-button', 'right-statusbar'])
129 bbar: Ext.create('Ext.ux.StatusBar', {
130 defaultText: 'Default status',
131 id: 'right-statusbar',
132 statusAlign: 'right', // the magic config
135 }, '-', 'Plain Text', ' ', ' ']
140 * ================ StatusBar Window example =======================
142 var win = Ext.create('Ext.Window', {
143 title: 'StatusBar Window',
149 bodyStyle: 'padding:10px;',
154 handler: Ext.Function.pass(loadFn, ['win-button', 'win-statusbar'])
156 bbar: Ext.create('Ext.ux.StatusBar', {
158 defaultText: 'Ready',
163 Ext.Date.format(new Date(), 'n/d/Y'), ' ', ' ', '-', {
167 menu: Ext.create('Ext.menu.Menu', {
168 items: [{text: 'Item 1'}, {text: 'Item 2'}]
174 Ext.create('Ext.Button', {
183 * ================ Ext Word Processor example =======================
185 * The StatusBar used in this example is completely standard. What is
186 * customized are the styles and event handling to make the example a
187 * lot more dynamic and application-oriented.
190 // Create these explicitly so we can manipulate them later
191 var wordCount = Ext.create('Ext.toolbar.TextItem', {text: 'Words: 0'}),
192 charCount = Ext.create('Ext.toolbar.TextItem', {text: 'Chars: 0'}),
193 clock = Ext.create('Ext.toolbar.TextItem', {text: Ext.Date.format(new Date(), 'g:i:s A')}),
194 event = Ext.isOpera ? 'keypress' : 'keydown'; // opera behaves a little weird with keydown
196 Ext.create('Ext.Panel', {
197 title: 'Ext Word Processor',
198 renderTo: 'word-proc',
201 bodyStyle: 'padding:5px;',
203 bbar: Ext.create('Ext.ux.StatusBar', {
205 // These are just the standard toolbar TextItems we created above. They get
206 // custom classes below in the render handler which is what gives them their
207 // customized inset appearance.
208 items: [wordCount, ' ', charCount, ' ', clock, ' ']
213 enableKeyEvents: true,
222 // Add a class to the parent TD of each text item so we can give them some custom inset box
223 // styling. Also, since we are using a greedy spacer, we have to add a block level element
224 // into each text TD in order to give them a fixed width (TextItems are spans). Insert a
225 // spacer div into each TD using createChild() so that we can give it a width in CSS.
226 Ext.fly(wordCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
227 Ext.fly(charCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
228 Ext.fly(clock.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
230 // Kick off the clock timer that updates the clock el every second:
231 Ext.TaskManager.start({
233 Ext.fly(clock.getEl()).update(Ext.Date.format(new Date(), 'g:i:s A'));
243 // This sets up a fake auto-save function. It monitors keyboard activity and after no typing
244 // has occurred for 1.5 seconds, it updates the status message to indicate that it's saving.
245 // After a fake delay so that you can see the save activity it will update again to indicate
246 // that the action succeeded.
247 Ext.getCmp('word-textarea').on(event, function(){
248 var sb = Ext.getCmp('word-status');
249 sb.showBusy('Saving draft...');
250 Ext.defer(function(){
252 iconCls: 'x-status-saved',
253 text: 'Draft auto-saved at ' + Ext.Date.format(new Date(), 'g:i:s A')
256 }, null, {buffer:1500});
258 // Set up our event for updating the word/char count
259 Ext.getCmp('word-textarea').on(event, function(comp){
260 var v = comp.getValue(),
262 cc = v.length ? v.length : 0;
266 wc = wc ? wc.length / 2 : 0;
268 wordCount.update('Words: ' + wc);
269 charCount.update('Chars: ' + cc);
270 }, null, {buffer: 1});