Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / form / file-upload.js
index 3f6af7e..32039aa 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
-    Ext.QuickTips.init();\r
-    \r
-    var msg = function(title, msg){\r
-        Ext.Msg.show({\r
-            title: title, \r
-            msg: msg,\r
-            minWidth: 200,\r
-            modal: true,\r
-            icon: Ext.Msg.INFO,\r
-            buttons: Ext.Msg.OK\r
-        });\r
-    };\r
-    \r
-    var fibasic = new Ext.form.FileUploadField({\r
-        renderTo: 'fi-basic',\r
-        width: 400\r
-    });\r
\r
-    new Ext.Button({\r
-        text: 'Get File Path',\r
-        renderTo: 'fi-basic-btn',\r
-        handler: function(){\r
-            var v = fibasic.getValue();\r
-            msg('Selected File', v && v != '' ? v : 'None');\r
-        }\r
-    });\r
-    \r
-    var fbutton = new Ext.form.FileUploadField({\r
-        renderTo: 'fi-button',\r
-        buttonOnly: true,\r
-        listeners: {\r
-            'fileselected': function(fb, v){\r
-                var el = Ext.fly('fi-button-msg');\r
-                el.update('<b>Selected:</b> '+v);\r
-                if(!el.isVisible()){\r
-                    el.slideIn('t', {\r
-                        duration: .2,\r
-                        easing: 'easeIn',\r
-                        callback: function(){\r
-                            el.highlight();\r
-                        }\r
-                    });\r
-                }else{\r
-                    el.highlight();\r
-                }\r
-            }\r
-        }\r
-    });\r
-    \r
-    var fp = new Ext.FormPanel({\r
-        renderTo: 'fi-form',\r
-        fileUpload: true,\r
-        width: 500,\r
-        frame: true,\r
-        title: 'File Upload Form',\r
-        autoHeight: true,\r
-        bodyStyle: 'padding: 10px 10px 0 10px;',\r
-        labelWidth: 50,\r
-        defaults: {\r
-            anchor: '95%',\r
-            allowBlank: false,\r
-            msgTarget: 'side'\r
-        },\r
-        items: [{\r
-            xtype: 'textfield',\r
-            fieldLabel: 'Name'\r
-        },{\r
-            xtype: 'fileuploadfield',\r
-            id: 'form-file',\r
-            emptyText: 'Select an image',\r
-            fieldLabel: 'Photo',\r
-            name: 'photo-path',\r
-            buttonCfg: {\r
-                text: '',\r
-                iconCls: 'upload-icon'\r
-            }\r
-        }],\r
-        buttons: [{\r
-            text: 'Save',\r
-            handler: function(){\r
-                if(fp.getForm().isValid()){\r
-                       fp.getForm().submit({\r
-                           url: 'file-upload.php',\r
-                           waitMsg: 'Uploading your photo...',\r
-                           success: function(fp, o){\r
-                               msg('Success', 'Processed file "'+o.result.file+'" on the server');\r
-                           }\r
-                       });\r
-                }\r
-            }\r
-        },{\r
-            text: 'Reset',\r
-            handler: function(){\r
-                fp.getForm().reset();\r
-            }\r
-        }]\r
-    });\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.require([
+    'Ext.form.field.File',
+    'Ext.form.Panel',
+    'Ext.window.MessageBox'
+]);
+
+Ext.onReady(function(){
+
+    var msg = function(title, msg) {
+        Ext.Msg.show({
+            title: title,
+            msg: msg,
+            minWidth: 200,
+            modal: true,
+            icon: Ext.Msg.INFO,
+            buttons: Ext.Msg.OK
+        });
+    };
+
+    var fibasic = Ext.create('Ext.form.field.File', {
+        renderTo: 'fi-basic',
+        width: 400,
+        hideLabel: true
+    });
+
+    Ext.create('Ext.button.Button', {
+        text: 'Get File Path',
+        renderTo: 'fi-basic-btn',
+        handler: function(){
+            var v = fibasic.getValue();
+            msg('Selected File', v && v != '' ? v : 'None');
+        }
+    });
+
+    Ext.create('Ext.form.field.File', {
+        renderTo: 'fi-button',
+        buttonOnly: true,
+        hideLabel: true,
+        listeners: {
+            'change': function(fb, v){
+                var el = Ext.get('fi-button-msg');
+                el.update('<b>Selected:</b> '+v);
+                if(!el.isVisible()){
+                    el.slideIn('t', {
+                        duration: 200,
+                        easing: 'easeIn',
+                        listeners: {
+                            afteranimate: function() {
+                                el.highlight();
+                                el.setWidth(null);
+                            }
+                        }
+                    });
+                }else{
+                    el.highlight();
+                }
+            }
+        }
+    });
+
+    Ext.create('Ext.form.Panel', {
+        renderTo: 'fi-form',
+        width: 500,
+        frame: true,
+        title: 'File Upload Form',
+        bodyPadding: '10 10 0',
+
+        defaults: {
+            anchor: '100%',
+            allowBlank: false,
+            msgTarget: 'side',
+            labelWidth: 50
+        },
+
+        items: [{
+            xtype: 'textfield',
+            fieldLabel: 'Name'
+        },{
+            xtype: 'filefield',
+            id: 'form-file',
+            emptyText: 'Select an image',
+            fieldLabel: 'Photo',
+            name: 'photo-path',
+            buttonText: '',
+            buttonConfig: {
+                iconCls: 'upload-icon'
+            }
+        }],
+
+        buttons: [{
+            text: 'Save',
+            handler: function(){
+                var form = this.up('form').getForm();
+                if(form.isValid()){
+                    form.submit({
+                        url: 'file-upload.php',
+                        waitMsg: 'Uploading your photo...',
+                        success: function(fp, o) {
+                            msg('Success', 'Processed file "' + o.result.file + '" on the server');
+                        }
+                    });
+                }
+            }
+        },{
+            text: 'Reset',
+            handler: function() {
+                this.up('form').getForm().reset();
+            }
+        }]
+    });
+
+});