`
yang_kunlun
  • 浏览: 77229 次
  • 性别: Icon_minigender_1
  • 来自: 地球
最近访客 更多访客>>
社区版块
存档分类
最新评论

Upload_dialog.js example

    博客分类:
  • Ext
阅读更多
var Application = {};
Application.uploadDialog = {
  progressBarText:'Uploading:{0},{1}%finish',
  statuBarText:'File Number:{0}  ,Size:{1}',
  fileQueued:function(file){
    var obj=Application.uploadDialog;

    var filetype=(file.type.substr(1)).toUpperCase();
    //  if(filetype=='JPG' | filetype=='GIF'){
    var data=[];
    data.push([file.id,'selected',file.name,file.size,filetype]);
    obj.uploadGrid.store.loadData(data,true);
    obj.uploadAction[1].enable();
    obj.uploadAction[2].enable();
    obj.uploadAction[3].enable();
    obj.stateInfo.getEl().innerHTML=String.format(obj.statuBarText,obj.uploadGrid.store.getCount(),Ext.util.Format.fileSize(obj.uploadGrid.store.sum('size')));
  //  }
  //   var filetype=(file.type.substr(1)).toUpperCase();
  //
  //                                     if(filetype=='JPG' | filetype=='GIF'){
  //
  //                                               swfu.startUpload();
  //
  //                                     }else{
  //
  //                                               Ext.Msg.alert('错误','only jpg,gif')
  //
  //                                     }
  },

  uploadFileStar:function(file){
    var obj=Application.uploadDialog;
    var index=obj.findData(file.id);
    if(index>=0){
      obj.uploadGrid.store.getAt(index).set('state','uploading');
    }
    obj.uploadProgressBar.updateProgress(0,String.format(obj.progressBarText,file.name,0));
    return true;
  },

  uploadProgress:function(file,bytesloaded){
    var obj=Application.uploadDialog
    var percent = Math.ceil((bytesloaded / file.size) * 100);
    obj.uploadProgressBar.updateProgress(percent/100,String.format(obj.progressBarText,file.name,percent));
  },

  uploadFileComplete:function(file,serverData){
    var msg = Ext.decode(serverData);
    var obj=Application.uploadDialog;
    var index=obj.findData(file.id);
    if (msg.success){
      if(index>=0){
        obj.uploadGrid.store.getAt(index).set('state','ok');
      }
      if(obj.swfu.getStats().files_queued>0)
        obj.swfu.startUpload();
    }else{
      if(index>=0){
        obj.uploadGrid.store.getAt(index).set('state','Upload Failed');
        Ext.Msg.alert('error','You are not able to upload any more photo as you have exceeded your photo quota. You are currently using ' + msg.space + 'M/ 1024 M of your photo quota!');
      }
    }
  },

  uploadFileCancelled:function(file, queuelength){
  },

  uploadQueueComplete:function(file){
    try {
      var obj=Application.uploadDialog;
      obj.uploadProgressBar.updateProgress(1,'success');
      obj.uploadAction[2].enable();
      obj.uploadAction[4].enable();
      Ext.getCmp("view_photo").store.reload({
        callback: function(){
        //          tpl = ""
        //           <div>
        //    <h2>Gallery Space</h2>
        //    <p>Total: 8M</p>
        //    <p>Using: <%= @used_space %> M</p>
        //    <p>Photo number: <%= @user_photo.size %></p>
        //  </div>
        //          tp
        }
      });
//      Ext.getCmp("info").load({
//        url: "/photos/update_panel"
//      });
    } catch (ex) {
      this.debug(ex);
    }
  },
  fileQueueError:function(file,error,msg){
    switch (error) {
      case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
        Ext.Msg.alert('error','You can not upload files greater than 2MB!')
        break;
      case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
        Ext.Msg.alert('error','Not to select file of zeno size!')
        break;
      case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
        Ext.Msg.alert('error','You are not able to upload any more photo as you have exceeded your photo quota. You are currently using 95/100 of your photo quota!')
        break;
      case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
        Ext.Msg.alert('error','Only select JPG,GIF,PNG file!')
        break;
      default:
        Ext.Msg.alert('Upload Failed','Error:'+error+',file_name'+file.name)
        break;
    }
  },
  uploadError:function(file,error,msg){
    var index=Application.uploadDialog.findData(file.id);
    if(index>=0)
      Application.uploadDialog.uploadGrid.store.getAt(index).set('state','faild');
  //alert(errcode+','+file.name+','+msg);
  },
  uploadCancel:function(file, queuelength){
    var index=Application.uploadDialog.findData(file.id);
    if(index>=0)
      Application.uploadDialog.uploadGrid.store.getAt(index).set('state','unselected');
  },

  fileDialogStart:function(){
  },

  fileDialogComplete:function (num_files_queued){

  },

  findData:function(id){
    var rowindex=Application.uploadDialog.uploadGrid.store.find('id',id);
    return rowindex;
  },
  show:function(){
    if(!this.dialog)
      this.initDialog();
    this.uploadGrid.store.removeAll();
    //    if(data)
    //    this.classStore.loadData(data);
    //   this.uploadAction[0].enable();
    //   this.uploadAction[1].disable();
    //   this.uploadAction[2].disable();
    //   this.uploadAction[3].disable();
    //   this.uploadAction[4].enable();
    //this.uploadProgressBar.updateProgress(0,'');
    this.dialog.show();
    Application.uploadDialog.swfu=new SWFUpload({

      upload_url:"/photos/create",
      //  prevent_swf_caching : false,
      file_post_name : "Filedata",
      file_size_limit : "2MB",
      file_types : "*.jpg;*.jpeg;*.gif;*.png",
      file_types_description : "Picture",
      file_upload_limit : 10,
      custom_settings : {
        myFileListTarget : "upload",
        degraded_container_id : "divDegraded"
      },
//      post_params :
//      {
//        "userid" : 1
//      },

      requeue_on_error: false,
      button_placeholder_id: "add_picture",
      button_image_url: "/javascripts/gallery/images/add_image.png",
      button_width: "50",
      button_height: "17",
      button_text: "Add",
      button_text_left_padding: 20,
      //            button_icon: 'add_gallery_btn',
      //   button_disable : false,
      button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES,
      button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
      file_dialog_start_handler : Application.uploadDialog.fileDialogStart,
      file_queued_handler : Application.uploadDialog.fileQueued,
      file_queue_error_handler : Application.uploadDialog.fileQueueError,
      file_dialog_complete_handler : Application.uploadDialog.fileDialogComplete,
      upload_start_handler : Application.uploadDialog.uploadFileStar,
      upload_progress_handler : Application.uploadDialog.uploadProgress,
      upload_error_handler : Application.uploadDialog.uploadError,
      upload_success_handler : Application.uploadDialog.uploadFileComplete,
      upload_complete_handler : Application.uploadDialog.uploadQueueComplete,
      //   file_complete_handler : Application.uploadDialog.uploadFileComplete,
      flash_url:"/swfupload.swf",
      debug: false
    })
  },
  hide:function(){
    this.dialog.hide();
  },

  uploadAction:[
  new Ext.Action({
    text:'Add',
    iconCls: 'add_gallery_btn',
    handler:function(){
    //  Application.uploadDialog.swfu.selectFiles();
    }
  }),
  new Ext.Action({
    text:'Delete',
    iconCls: 'delete_photo_btn',
    disabled:true,
    handler:function(){
      var obj=Application.uploadDialog;
      var grid=obj.uploadGrid;
      var store=grid.store;
      var selection=grid.getSelectionModel().getSelections();
      for(var i=0;i<selection.length;i++){
        var rec=store.getAt(store.indexOfId(selection[i].id));
        obj.swfu.cancelUpload(rec.data.id);
        store.remove(rec);
      }
      obj.stateInfo.getEl().innerHTML=String.format(obj.statuBarText,obj.uploadGrid.store.getCount(),Ext.util.Format.fileSize(obj.uploadGrid.store.sum('size')));
      if(obj.uploadGrid.store.getCount()==0){
        obj.uploadGrid.store.removeAll();
        obj.uploadAction[1].disable();
        obj.uploadAction[2].disable();
        obj.uploadAction[3].disable();
      }
    }
  }),
  new Ext.Action({
    text:'Reset',
    iconCls: 'reset_btn',
    disabled:true,
    handler:function(){
      var obj=Application.uploadDialog;
      var store=obj.uploadGrid.store;
      var len=store.getCount();
      for(var i=0;i<len;i++){
        var rec=store.getAt(i);
        obj.swfu.cancelUpload(rec.data.id);
      }
      store.removeAll();
      obj.swfu.setStats({successful_uploads: 0});
      //  obj.classCombo.clearValue();
      obj.stateInfo.getEl().innerHTML=String.format(obj.statuBarText,0,Ext.util.Format.fileSize(0));
      obj.uploadProgressBar.updateProgress(0,'');
      obj.uploadProgressBar.updateText("");
      obj.uploadAction[0].enable();
      obj.uploadAction[1].disable();
      obj.uploadAction[2].disable();
      obj.uploadAction[3].disable();
    }
  }),
  new Ext.Action({
    text:'Upload',
    iconCls: 'upload_btn',
    disabled:true,
    handler:function(){
      var obj=Application.uploadDialog;
      obj.uploadAction[0].disable();
      obj.uploadAction[1].disable();
      obj.uploadAction[2].disable();
      obj.uploadAction[3].disable();
      obj.uploadAction[4].disable();
      var store=obj.uploadGrid.store;
      var len=store.getCount();
      //  var userid=kk;
      // obj.swfu.setPostParams({
      // 'user_id':    //defaulte userid = 1
      //   });
      obj.swfu.startUpload();
    }
  }),
  new Ext.Action({
    text:'Close',
    iconCls: 'close_btn',
    handler:function(){
      Application.uploadDialog.hide();
    }
  })
  ],

  initDialog:function(){
    //   this.classCombo=new Ext.form.ComboBox({
    //     hiddenName:'classid',
    //     name: 'classid_name',
    //      valueField:"id",
    //      displayField:"text",
    //      mode:'local',
    //     store:this.classStore,
    //      blankText:'Select your Mygallery',
    //     emptyText:'Select your Mygallery',
    //      editable:true,
    //     anchor:'90%'
    //   })
    this.dialog=new Ext.Window({
      layout:'fit',
      width:600,
      height:500,
      title:'Upload your picture',
      closeAction:'hide',
      border:false,
      modal:true,
      plain:true,
      closable:false,
      resizable:false,
      bbar:[this.uploadProgressBar=new Ext.ProgressBar({
        width:586
      })],
      items:[
      Application.uploadDialog.uploadGrid=new Ext.grid.GridPanel({
        autoExpandColumn:2,
        enableHdMenu:false,
        tbar:[this.uploadbuttom = new Ext.Button({
          text:'Add',
          id: 'add_picture', // assign menu by instance
          iconCls: 'add_gallery_btn'
        }),Application.uploadDialog.uploadAction[1],Application.uploadDialog.uploadAction[2],
        '-',Application.uploadDialog.uploadAction[3],"-"
        ,Application.uploadDialog.uploadAction[4]],
        bbar:[Application.uploadDialog.stateInfo=new Ext.Toolbar.TextItem(String.format(Application.uploadDialog.statuBarText,0,Ext.util.Format.fileSize(0)))],
        store: new Ext.data.SimpleStore({
          fields: ["id","state", "file","size","type"],
          data:[]
        }),
        columns:[
        new Ext.grid.RowNumberer(),
        {
          id:'id',
          header: "id",
          hidden:true,
          width:150,
          dataIndex:'id',
          resizable:false,
          sortable:false
        },

        {
          header: "File name",
          width:Ext.grid.GridView.autoFill,
          dataIndex:'file',
          sortable:true
        },

        {
          header: "Size",
          width: 80,
          renderer:Ext.util.Format.fileSize,
          dataIndex:'size',
          sortable:true,
          align:'right'
        },

        {
          header: "Type",
          width: 80,
          dataIndex:'type',
          align:'center',
          sortable:true
        },

        {
          header: "Status",
          width: 100,
          dataIndex:'state',
          align:'center',
          sortable:true
        }
        ]
      })
      ]
    })
  }

}//Application.uploadDialog

分享到:
评论

相关推荐

    iOS_Dialog_Library.zip

    在这种情况下,"iOS_Dialog_Library.zip"是一个专为Android设计的第三方库,它允许开发者创建类似于iOS7风格的底部弹出对话框,通常在QQ等应用中可见。这个库可以帮助你在Android应用中实现这种独特的交互方式,从而...

    JavaScript应用实例-file_chooser_dialog.js

    JavaScript应用实例-file_chooser_dialog.js

    Web_Browser_Dialog.rar_收藏夹

    标题中的“Web_Browser_Dialog.rar_收藏夹”暗示了这是一个关于Web浏览器的项目,其中包含收藏夹功能。这个项目可能是一个小型的浏览器应用程序,专为用户提供简单的网页浏览体验,并且具备收藏网页的能力。让我们...

    MFC_Dialog.zip_Kinect Opencv_MFC opencv_mfc Kinect_opencv_zip

    标题"MFC_Dialog.zip_Kinect Opencv_MFC opencv_mfc Kinect_opencv_zip"表明这个压缩包包含了关于使用Microsoft Foundation Class (MFC)库、OpenCV框架以及Kinect设备进行开发的项目资源。描述"Kinect + OpenCV + ...

    jquery_dialog.rar

    虽然项目未结项就转交了出去,但开始对JQuery产生了好感并爱不释手,于是决定将此项目正式更名为JQueryDialog。 本次更新将代码完全基于了JQuery框架,并应用了命名空间,让JS看起来有那么一点OO的感觉,同时修改了...

    VC_dialog.rar_VC_Dialog_Vc dial_dialog

    在VC++编程环境中,开发人员经常需要创建对话框(Dialog)来与用户进行交互,而“VC_dialog.rar_VC_Dialog_Vc dial_dialog”这个资源恰好是关于如何在Visual C++(VC++)中创建和定制彩色对话框的一个教程或示例。...

    Dialog.js 最新版 绝对强大

    Dialog.js 是一个强大的JavaScript库,专门用于创建对话框功能。这个最新版本的Dialog.js 提供了先进的特性和优化,使其在各种浏览器环境下表现卓越,包括Firefox、Internet Explorer 6、7、8以及Opera等主流浏览器...

    Exercise_02_dialog.viple

    Exercise_02_dialog.viple

    html_dialog.zip_HTML Dialog

    HTML Dialog是一种在应用程序中展示网页内容的技术,常用于创建具有丰富交互性的对话框。在Visual Studio 7(可能是Visual Studio .NET 2003)环境下,开发人员可以利用这一特性来增强用户界面,实现更加动态和灵活...

    Keil.STM32F4xx_DFP.2.14.0.pack(官方STM32F4xx系列最新固件库for Keil MDK 5)

    Enable 'C99 Mode' in 'Options for Target' dialog's 'C/C++' tab. Updated Pack to include subset of STM32Cube_FW_F4 Firmware Package version V1.24.1 using HAL Drivers V1.7.6. Corrected RTE_Device.h ...

    html_dialog.rar_html_show

    "html_dialog.rar_html_show" 提供的程序旨在展示HTML的工作原理,帮助用户理解和学习如何利用HTML来构建网页。在这个压缩包中,包含了一个名为 "html_dialog" 的文件,这可能是一个HTML示例文件,用于演示对话框或...

    jQuery.dialog.js网页弹出对话框美化特效插件

    《jQuery.dialog.js:网页弹出对话框的美化与特效实现》 在网页设计中,对话框(dialog)是一种常见的交互元素,用于展示重要的信息或进行用户操作确认。jQuery.dialog.js是一个专为网页开发者设计的轻量级插件,...

    dialog-1.2-5.20130523.el7.x86_64.rpm

    dialog-1.2-5.20130523.el7.x86_64.rpm,用于CentOS 7.7.1908 系统或者RedHat 7.X 系统 for x86_64使用

    Example_Dialog.rar_symbian_symbian List

    "Example_Dialog.rar_symbian_symbian List" 提供了一个实例,帮助开发者了解如何在Symbian平台上构建这样的功能。 首先,我们需要理解Symbian操作系统的事件驱动模型。Symbian OS是基于微内核的系统,其应用程序...

    propsheet_in_dialog.zip_PropertySheet_dialog_sheet_visual c_控件

    在描述中提到的"propsheet_in_dialog.zip_PropertySheet_dialog_sheet_visual c_控件"涉及到的是如何在对话框(DialogBox)中使用PropertySheet控件,这是一个在Windows应用程序中组织多个选项卡对话框的实用工具。...

    sample_dialog.rar_visual c_对话框Visual C

    在Visual C++编程环境中,对话框(Dialog)是应用程序与用户交互的重要手段。"sample_dialog.rar_visual c_对话框Visual C"这个资源可能包含了一个示例项目,用于演示如何在两个对话框之间进行相互引用和通信。下面...

    Keil.STM32F4xx_DFP.2.14.0.rar

    Enable 'C99 Mode' in 'Options for Target' dialog's 'C/C++' tab. Updated Pack to include subset of STM32Cube_FW_F4 Firmware Package version V1.24.1 using HAL Drivers V1.7.6. Corrected RTE_Device.h ...

    jQuery对话框插件Zebra_Dialog.zip

    Zebra_Dialog 是一个小型的对话框插件,最小化后只有 4K 左右,只包含一个 js 文件,要求 jQuery 1.5.2 或者更新版本。是一个可灵活配置的对话框插件。 标签:Zebra

    dialog_read_image.zip_ dialog_read_image_IDL 影像读取_IDL读取_遥感

    这篇讨论将深入解析"dialog_read_image.zip"中的"dialog_read_image.pro" IDL程序,它用于读取遥感影像。 首先,我们需要了解IDL的基本语法。IDL是一种面向对象的、动态类型的编程语言,它的语法简洁,允许快速开发...

    alert_dialog_progress_material.xml

    alert_dialog_progress_material.xml

Global site tag (gtag.js) - Google Analytics