file-upload.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:3k
源码类别:

JavaScript

开发平台:

JavaScript

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