source: trunk/web/addons/job_monarch/lib/extjs/examples/form/file-upload.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 2.9 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9
10Ext.onReady(function(){
11
12    Ext.QuickTips.init();
13   
14    var msg = function(title, msg){
15        Ext.Msg.show({
16            title: title, 
17            msg: msg,
18            minWidth: 200,
19            modal: true,
20            icon: Ext.Msg.INFO,
21            buttons: Ext.Msg.OK
22        });
23    };
24   
25    var fibasic = new Ext.form.FileUploadField({
26        renderTo: 'fi-basic',
27        width: 400
28    });
29 
30    new Ext.Button({
31        text: 'Get File Path',
32        renderTo: 'fi-basic-btn',
33        handler: function(){
34            var v = fibasic.getValue();
35            msg('Selected File', v && v != '' ? v : 'None');
36        }
37    });
38   
39    var fbutton = new Ext.form.FileUploadField({
40        renderTo: 'fi-button',
41        buttonOnly: true,
42        listeners: {
43            'fileselected': function(fb, v){
44                var el = Ext.fly('fi-button-msg');
45                el.update('<b>Selected:</b> '+v);
46                if(!el.isVisible()){
47                    el.slideIn('t', {
48                        duration: .2,
49                        easing: 'easeIn',
50                        callback: function(){
51                            el.highlight();
52                        }
53                    });
54                }else{
55                    el.highlight();
56                }
57            }
58        }
59    });
60   
61    var fp = new Ext.FormPanel({
62        renderTo: 'fi-form',
63        fileUpload: true,
64        width: 500,
65        frame: true,
66        title: 'File Upload Form',
67        autoHeight: true,
68        bodyStyle: 'padding: 10px 10px 0 10px;',
69        labelWidth: 50,
70        defaults: {
71            anchor: '95%',
72            allowBlank: false,
73            msgTarget: 'side'
74        },
75        items: [{
76            xtype: 'textfield',
77            fieldLabel: 'Name'
78        },{
79            xtype: 'fileuploadfield',
80            id: 'form-file',
81            emptyText: 'Select an image',
82            fieldLabel: 'Photo',
83            name: 'photo-path',
84            buttonCfg: {
85                text: '',
86                iconCls: 'upload-icon'
87            }
88        }],
89        buttons: [{
90            text: 'Save',
91            handler: function(){
92                if(fp.getForm().isValid()){
93                        fp.getForm().submit({
94                            url: 'file-upload.php',
95                            waitMsg: 'Uploading your photo...',
96                            success: function(fp, o){
97                                msg('Success', 'Processed file "'+o.result.file+'" on the server');
98                            }
99                        });
100                }
101            }
102        },{
103            text: 'Reset',
104            handler: function(){
105                fp.getForm().reset();
106            }
107        }]
108    });
109   
110});
Note: See TracBrowser for help on using the repository browser.