Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / statusbar / statusbar-demo.js
index c7b0478..561611a 100644 (file)
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-\r
-Ext.onReady(function(){\r
-    \r
-    // This is a shared function that simulates a load action on a StatusBar.\r
-    // It is reused by most of the example panels.\r
-    var loadFn = function(btn, statusBar){\r
-        btn = Ext.getCmp(btn);\r
-        statusBar = Ext.getCmp(statusBar);\r
-        \r
-        btn.disable();\r
-        statusBar.showBusy();\r
-        \r
-        (function(){\r
-            statusBar.clearStatus({useDefaults:true});\r
-            btn.enable();\r
-        }).defer(2000);\r
-    };\r
-    \r
-/*\r
- * ================  Basic StatusBar example  =======================\r
- */\r
-    new Ext.Panel({\r
-        title: 'Basic StatusBar',\r
-        renderTo: 'basic',\r
-        width: 350,\r
-        height: 100,\r
-        bodyStyle: 'padding:10px;',\r
-        items:[{\r
-            xtype: 'button',\r
-            id: 'basic-button',\r
-            text: 'Do Loading',\r
-            handler: loadFn.createCallback('basic-button', 'basic-statusbar')\r
-        }],\r
-        bbar: new Ext.StatusBar({\r
-            defaultText: 'Default status',\r
-            id: 'basic-statusbar',\r
-               items: [{\r
-                   text: 'A Button'\r
-               }, '-', 'Plain Text', ' ', ' ']\r
-        })\r
-    });\r
-    \r
-/*\r
- * ================  Right-aligned StatusBar example  =======================\r
- */\r
-    new Ext.Panel({\r
-        title: 'Right-aligned StatusBar',\r
-        renderTo: 'right-aligned',\r
-        width: 350,\r
-        height: 100,\r
-        bodyStyle: 'padding:10px;',\r
-        items:[{\r
-            xtype: 'button',\r
-            id: 'right-button',\r
-            text: 'Do Loading',\r
-            handler: loadFn.createCallback('right-button', 'right-statusbar')\r
-        }],\r
-        bbar: new Ext.StatusBar({\r
-            defaultText: 'Default status',\r
-            id: 'right-statusbar',\r
-            statusAlign: 'right', // the magic config\r
-            items: [{\r
-                text: 'A Button'\r
-            }, '-', 'Plain Text', ' ', ' ']\r
-        })\r
-    });\r
-    \r
-/*\r
- * ================  StatusBar Window example  =======================\r
- */\r
-    var win = new Ext.Window({\r
-        title: 'StatusBar Window',\r
-        width: 400,\r
-        minWidth: 350,\r
-        height: 150,\r
-        modal: true,\r
-        closeAction: 'hide',\r
-        bodyStyle: 'padding:10px;',\r
-        items:[{\r
-            xtype: 'button',\r
-            id: 'win-button',\r
-            text: 'Do Loading',\r
-            handler: loadFn.createCallback('win-button', 'win-statusbar')\r
-        }],\r
-        bbar: new Ext.StatusBar({\r
-            id: 'win-statusbar',\r
-            defaultText: 'Ready',\r
-            items: [{\r
-                text: 'A Button'\r
-            }, '-',\r
-            new Date().format('n/d/Y'), ' ', ' ', '-', {\r
-                xtype:'tbsplit',\r
-                text:'Status Menu',\r
-                menuAlign: 'br-tr?',\r
-                menu: new Ext.menu.Menu({\r
-                    items: [{text: 'Item 1'}, {text: 'Item 2'}]\r
-                })\r
-            }]\r
-        })\r
-    });\r
-    \r
-    new Ext.Button({\r
-        text: 'Show Window',\r
-        renderTo: 'window',\r
-        handler: function(){\r
-            win.show();\r
-        }\r
-    });\r
-    \r
-/*\r
- * ================  Ext Word Processor example  =======================\r
- * \r
- * The StatusBar used in this example is completely standard.  What is \r
- * customized are the styles and event handling to make the example a\r
- * lot more dynamic and application-oriented.\r
- * \r
- */\r
-    // Create these explicitly so we can manipulate them later\r
-    var wordCount = new Ext.Toolbar.TextItem('Words: 0');\r
-    var charCount = new Ext.Toolbar.TextItem('Chars: 0');\r
-    var clock = new Ext.Toolbar.TextItem('');\r
-    \r
-    new Ext.Panel({\r
-        title: 'Ext Word Processor',\r
-        renderTo: 'word-proc',\r
-        width: 500,\r
-        autoHeight: true,\r
-        bodyStyle: 'padding:5px;',\r
-        layout: 'fit',\r
-        bbar: new Ext.StatusBar({\r
-            id: 'word-status',\r
-            // These are just the standard toolbar TextItems we created above.  They get\r
-            // custom classes below in the render handler which is what gives them their\r
-            // customized inset appearance.\r
-            items: [wordCount, ' ', charCount, ' ', clock, ' ']\r
-        }),\r
-        items: {\r
-            xtype: 'textarea',\r
-            id: 'word-textarea',\r
-            enableKeyEvents: true,\r
-            grow: true,\r
-            growMin: 100,\r
-            growMax: 200,\r
-            listeners: {\r
-                // After each keypress update the word and character count text items\r
-                'keypress': {\r
-                    fn: function(t){\r
-                        var v = t.getValue(),\r
-                            wc = 0, cc = v.length ? v.length : 0;\r
-                            \r
-                        if(cc > 0){\r
-                            wc = v.match(/\b/g);\r
-                            wc = wc ? wc.length / 2 : 0;\r
-                        }\r
-                           Ext.fly(wordCount.getEl()).update('Words: '+wc);\r
-                        Ext.fly(charCount.getEl()).update('Chars: '+cc);\r
-                       },\r
-                    buffer: 1 // buffer to allow the value to update first\r
-                }\r
-            }\r
-        },\r
-        listeners: {\r
-            'render': {\r
-                fn: function(){\r
-                    // Add a class to the parent TD of each text item so we can give them some custom inset box \r
-                    // styling. Also, since we are using a greedy spacer, we have to add a block level element\r
-                    // into each text TD in order to give them a fixed width (TextItems are spans).  Insert a\r
-                    // spacer div into each TD using createChild() so that we can give it a width in CSS.\r
-                    Ext.fly(wordCount.getEl().parentNode).addClass('x-status-text-panel').createChild({cls:'spacer'});\r
-                    Ext.fly(charCount.getEl().parentNode).addClass('x-status-text-panel').createChild({cls:'spacer'});\r
-                    Ext.fly(clock.getEl().parentNode).addClass('x-status-text-panel').createChild({cls:'spacer'});\r
-                    \r
-                    // Kick off the clock timer that updates the clock el every second:\r
-                                   Ext.TaskMgr.start({\r
-                                       run: function(){\r
-                                           Ext.fly(clock.getEl()).update(new Date().format('g:i:s A'));\r
-                                       },\r
-                                       interval: 1000\r
-                                   });\r
-                }\r
-            }\r
-        }\r
-    });\r
-    \r
-    // This sets up a fake auto-save function.  It monitors keyboard activity and after no typing\r
-    // has occurred for 1.5 seconds, it updates the status message to indicate that it's saving.\r
-    // After a fake delay so that you can see the save activity it will update again to indicate\r
-    // that the action succeeded.\r
-    Ext.fly('word-textarea').on('keypress', function(){\r
-        var sb = Ext.getCmp('word-status');\r
-        sb.showBusy('Saving draft...');\r
-        (function(){\r
-            sb.setStatus({\r
-                iconCls: 'x-status-saved',\r
-                text: 'Draft auto-saved at ' + new Date().format('g:i:s A')\r
-            });\r
-        }).defer(4000);\r
-    }, this, {buffer:1500});\r
-    \r
-});
\ No newline at end of file
+/*
+
+This file is part of Ext JS 4
+
+Copyright (c) 2011 Sencha Inc
+
+Contact:  http://www.sencha.com/contact
+
+GNU General Public License Usage
+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.
+
+If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
+
+*/
+Ext.Loader.setConfig({
+    enabled: true
+});
+
+Ext.Loader.setPath('Ext.ux', '../ux/');
+
+Ext.require([
+  'Ext.panel.Panel',
+  'Ext.button.Button',
+  'Ext.window.Window',
+  'Ext.ux.statusbar.StatusBar',
+  'Ext.toolbar.TextItem',
+  'Ext.menu.Menu',
+  'Ext.toolbar.Spacer',
+  'Ext.button.Split',
+  'Ext.form.field.TextArea'
+]);
+
+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();
+
+         Ext.defer(function(){
+            statusBar.clearStatus({useDefaults:true});
+            btn.enable();
+        }, 2000);
+    };
+
+/*
+ * ================  Basic StatusBar example  =======================
+ */
+    Ext.create('Ext.Panel', {
+        title: 'Basic StatusBar',
+        renderTo: 'basic',
+        width: 550,
+        height: 100,
+        bodyStyle: 'padding:10px;',
+        items:[{
+            xtype: 'button',
+            id: 'basic-button',
+            text: 'Do Loading',
+            handler: Ext.Function.pass(loadFn, ['basic-button', 'basic-statusbar'])
+        }],
+        bbar: Ext.create('Ext.ux.StatusBar', {
+            id: 'basic-statusbar',
+
+            // defaults to use when the status is cleared:
+            defaultText: 'Default status text',
+            //defaultIconCls: 'default-icon',
+        
+            // values to set initially:
+            text: 'Ready',
+            iconCls: 'x-status-valid',
+
+            // any standard Toolbar items:
+            items: [
+                {
+                    xtype: 'button',
+                    text: 'Show Warning & Clear',
+                    handler: function (){
+                        var sb = Ext.getCmp('basic-statusbar');
+                        sb.setStatus({
+                            text: 'Oops!',
+                            iconCls: 'x-status-error',
+                            clear: true // auto-clear after a set interval
+                        });
+                    }
+                },
+                {
+                    xtype: 'button',
+                    text: 'Show Busy',
+                    handler: function (){
+                        var sb = Ext.getCmp('basic-statusbar');
+                        // Set the status bar to show that something is processing:
+                        sb.showBusy();
+                    }
+                },
+                {
+                    xtype: 'button',
+                    text: 'Clear status',
+                    handler: function (){
+                        var sb = Ext.getCmp('basic-statusbar');
+                        // once completed
+                        sb.clearStatus(); 
+                    }
+                },
+                '-',
+                'Plain Text'
+            ]
+        })
+    });
+
+/*
+ * ================  Right-aligned StatusBar example  =======================
+ */
+    Ext.create('Ext.Panel', {
+        title: 'Right-aligned StatusBar',
+        renderTo: 'right-aligned',
+        width: 550,
+        height: 100,
+        bodyStyle: 'padding:10px;',
+        items:[{
+            xtype: 'button',
+            id: 'right-button',
+            text: 'Do Loading',
+            handler: Ext.Function.pass(loadFn, ['right-button', 'right-statusbar'])
+        }],
+        bbar: Ext.create('Ext.ux.StatusBar', {
+            defaultText: 'Default status',
+            id: 'right-statusbar',
+            statusAlign: 'right', // the magic config
+            items: [{
+                text: 'A Button'
+            }, '-', 'Plain Text', ' ', ' ']
+        })
+    });
+
+/*
+ * ================  StatusBar Window example  =======================
+ */
+    var win = Ext.create('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: Ext.Function.pass(loadFn, ['win-button', 'win-statusbar'])
+        }],
+        bbar: Ext.create('Ext.ux.StatusBar', {
+            id: 'win-statusbar',
+            defaultText: 'Ready',
+            items: [{
+                xtype: 'button',
+                text: 'A Button'
+            }, '-',
+            Ext.Date.format(new Date(), 'n/d/Y'), ' ', ' ', '-', {
+                xtype:'splitbutton',
+                text:'Status Menu',
+                menuAlign: 'br-tr?',
+                menu: Ext.create('Ext.menu.Menu', {
+                    items: [{text: 'Item 1'}, {text: 'Item 2'}]
+                })
+            }]
+        })
+    });
+
+    Ext.create('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 = Ext.create('Ext.toolbar.TextItem', {text: 'Words: 0'}),
+        charCount = Ext.create('Ext.toolbar.TextItem', {text: 'Chars: 0'}), 
+        clock = Ext.create('Ext.toolbar.TextItem', {text: Ext.Date.format(new Date(), 'g:i:s A')}),
+        event = Ext.isOpera ? 'keypress' : 'keydown'; // opera behaves a little weird with keydown
+
+    Ext.create('Ext.Panel', {
+        title: 'Ext Word Processor',
+        renderTo: 'word-proc',
+        width: 500,
+        autoHeight: true,
+        bodyStyle: 'padding:5px;',
+        layout: 'fit',
+        bbar: Ext.create('Ext.ux.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,
+            hideLabel: true,
+            grow: true,
+            growMin: 100,
+            growMax: 200
+        },
+        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. Also, since we are using a greedy spacer, we have to add a block level element
+                    // into each text TD in order to give them a fixed width (TextItems are spans).  Insert a
+                    // spacer div into each TD using createChild() so that we can give it a width in CSS.
+                    Ext.fly(wordCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
+                    Ext.fly(charCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
+                    Ext.fly(clock.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});
+
+                    // Kick off the clock timer that updates the clock el every second:
+                 Ext.TaskManager.start({
+                     run: function(){
+                         Ext.fly(clock.getEl()).update(Ext.Date.format(new Date(), 'g:i:s A'));
+                     },
+                     interval: 1000
+                 });
+                },
+                delay: 100
+            }
+        }
+    });
+
+    // 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.getCmp('word-textarea').on(event, function(){
+        var sb = Ext.getCmp('word-status');
+        sb.showBusy('Saving draft...');
+        Ext.defer(function(){
+            sb.setStatus({
+                iconCls: 'x-status-saved',
+                text: 'Draft auto-saved at ' + Ext.Date.format(new Date(), 'g:i:s A')
+            });
+        }, 4000);
+    }, null, {buffer:1500});
+    
+    // Set up our event for updating the word/char count
+    Ext.getCmp('word-textarea').on(event, function(comp){
+        var v = comp.getValue(),
+            wc = 0, 
+            cc = v.length ? v.length : 0;
+
+        if (cc > 0) {
+            wc = v.match(/\b/g);
+            wc = wc ? wc.length / 2 : 0;
+        }
+        wordCount.update('Words: ' + wc);
+        charCount.update('Chars: ' + cc);
+    }, null, {buffer: 1});
+
+});
+