📄 ext.ux.uploadpanel.js
字号:
// vim: ts=4:sw=4:nu:fdc=4:nospell/** * Ext.ux.form.UploadPanel * * @author Ing. Jozef Sakáloš * @version $Id: Ext.ux.UploadPanel.js 94 2008-03-24 01:04:27Z jozo $ * @date 13. March 2008 * * @license Ext.ux.form.UploadPanel is licensed under the terms of * the Open Source LGPL 3.0 license. Commercial use is permitted to the extent * that the code/component(s) do NOT become part of another Open Source or Commercially * licensed development library or toolkit without explicit permission. * * License details: http://www.gnu.org/licenses/lgpl.html *//*global Ext *//** * @class Ext.ux.UploadPanel * @extends Ext.Panel */Ext.ux.UploadPanel = Ext.extend(Ext.Panel, { // configuration options overridable from outside // {{{ /** * @cfg {String} addIconCls icon class for add (file browse) button */ addIconCls:'icon-plus' /** * @cfg {String} addText Text on Add button */ ,addText:'Add' /** * @cfg {Object} baseParams This object is not used directly by FileTreePanel but it is * propagated to lower level objects instead. Included here for convenience. */ /** * @cfg {String} bodyStyle style to use for panel body */ ,bodyStyle:'padding:2px' /** * @cfg {String} buttonsAt Where buttons are placed. Valid values are tbar, bbar, body (defaults to 'tbar') */ ,buttonsAt:'tbar' /** * @cfg {String} clickRemoveText */ ,clickRemoveText:'Click to remove' /** * @cfg {String} clickStopText */ ,clickStopText:'Click to stop' /** * @cfg {String} emptyText empty text for dataview */ ,emptyText:'No files' /** * @cfg {Boolean} enableProgress true to enable querying server for progress information * Passed to underlying uploader. Included here for convenience. */ ,enableProgress:true /** * @cfg {String} errorText */ ,errorText:'Error' /** * @cfg {String} fileCls class prefix to use for file type classes */ ,fileCls:'file' /** * @cfg {String} fileQueuedText File upload status text */ ,fileQueuedText:'File <b>{0}</b> is queued for upload' /** * @cfg {String} fileDoneText File upload status text */ ,fileDoneText:'File <b>{0}</b> has been successfully uploaded' /** * @cfg {String} fileFailedText File upload status text */ ,fileFailedText:'File <b>{0}</b> failed to upload' /** * @cfg {String} fileStoppedText File upload status text */ ,fileStoppedText:'File <b>{0}</b> stopped by user' /** * @cfg {String} fileUploadingText File upload status text */ ,fileUploadingText:'Uploading file <b>{0}</b>' /** * @cfg {Number} maxFileSize Maximum upload file size in bytes * This config property is propagated down to uploader for convenience */ ,maxFileSize:524288 /** * @cfg {Number} Maximum file name length for short file names */ ,maxLength:18 /** * @cfg {String} removeAllIconCls iconClass to use for Remove All button (defaults to 'icon-cross' */ ,removeAllIconCls:'icon-cross' /** * @cfg {String} removeAllText text to use for Remove All button tooltip */ ,removeAllText:'Remove All' /** * @cfg {String} removeIconCls icon class to use for remove file icon */ ,removeIconCls:'icon-minus' /** * @cfg {String} removeText Remove text */ ,removeText:'Remove' /** * @cfg {String} selectedClass class for selected item of DataView */ ,selectedClass:'ux-up-item-selected' /** * @cfg {Boolean} singleUpload true to upload files in one form, false to upload one by one * This config property is propagated down to uploader for convenience */ ,singleUpload:false /** * @cfg {String} stopAllText */ ,stopAllText:'Stop All' /** * @cfg {String} stopIconCls icon class to use for stop */ ,stopIconCls:'icon-stop' /** * @cfg {String/Ext.XTemplate} tpl Template for DataView. */ /** * @cfg {String} uploadText Upload text */ ,uploadText:'Upload' /** * @cfg {String} uploadIconCls icon class to use for upload button */ ,uploadIconCls:'icon-upload' /** * @cfg {String} workingIconCls iconClass to use for busy indicator */ ,workingIconCls:'icon-working' // }}} // overrides // {{{ ,initComponent:function() { // {{{ // create buttons // add (file browse button) configuration var addCfg = { xtype:'browsebutton' ,text:this.addText + '...' ,iconCls:this.addIconCls ,scope:this ,handler:this.onAddFile }; // upload button configuration var upCfg = { xtype:'button' ,iconCls:this.uploadIconCls ,text:this.uploadText ,scope:this ,handler:this.onUpload ,disabled:true }; // remove all button configuration var removeAllCfg = { xtype:'button' ,iconCls:this.removeAllIconCls ,tooltip:this.removeAllText ,scope:this ,handler:this.onRemoveAllClick ,disabled:true }; // todo: either to cancel buttons in body or implement it if('body' !== this.buttonsAt) { this[this.buttonsAt] = [addCfg, upCfg, '->', removeAllCfg]; } // }}} // {{{ // create store // fields for record var fields = [ {name:'id', type:'text', system:true} ,{name:'shortName', type:'text', system:true} ,{name:'fileName', type:'text', system:true} ,{name:'filePath', type:'text', system:true} ,{name:'fileCls', type:'text', system:true} ,{name:'input', system:true} ,{name:'form', system:true} ,{name:'state', type:'text', system:true} ,{name:'error', type:'text', system:true} ,{name:'progressId', type:'int', system:true} ,{name:'bytesTotal', type:'int', system:true} ,{name:'bytesUploaded', type:'int', system:true} ,{name:'estSec', type:'int', system:true} ,{name:'filesUploaded', type:'int', system:true} ,{name:'speedAverage', type:'int', system:true} ,{name:'speedLast', type:'int', system:true} ,{name:'timeLast', type:'int', system:true} ,{name:'timeStart', type:'int', system:true} ,{name:'pctComplete', type:'int', system:true} ]; // add custom fields if passed if(Ext.isArray(this.customFields)) { fields.push(this.customFields); } // create store this.store = new Ext.data.SimpleStore({ id:0 ,fields:fields ,data:[] }); // }}} // {{{ // create view Ext.apply(this, { items:[{ xtype:'dataview' ,itemSelector:'div.ux-up-item' ,store:this.store ,selectedClass:this.selectedClass ,singleSelect:true ,emptyText:this.emptyText ,tpl: this.tpl || new Ext.XTemplate( '<tpl for=".">' + '<div class="ux-up-item">'// + '<div class="ux-up-indicator"> </div>' + '<div class="ux-up-icon-file {fileCls}"> </div>' + '<div class="ux-up-text x-unselectable" qtip="{fileName}">{shortName}</div>' + '<div id="remove-{[values.input.id]}" class="ux-up-icon-state ux-up-icon-{state}"' + 'qtip="{[this.scope.getQtip(values)]}"> </div>' + '</div>' + '</tpl>' , {scope:this} ) ,listeners:{click:{scope:this, fn:this.onViewClick}} }] }); // }}} // call parent Ext.ux.UploadPanel.superclass.initComponent.apply(this, arguments); // save useful references this.view = this.items.itemAt(0); // {{{ // add events this.addEvents( /** * Fires before the file is added to store. Return false to cancel the add * @event beforefileadd * @param {Ext.ux.UploadPanel} this * @param {Ext.Element} input (type=file) being added */ 'beforefileadd' /** * Fires after the file is added to the store * @event fileadd * @param {Ext.ux.UploadPanel} this * @param {Ext.data.Store} store * @param {Ext.data.Record} Record (containing the input) that has been added to the store */ ,'fileadd' /** * Fires before the file is removed from the store. Return false to cancel the remove * @event beforefileremove * @param {Ext.ux.UploadPanel} this * @param {Ext.data.Store} store * @param {Ext.data.Record} Record (containing the input) that is being removed from the store */ ,'beforefileremove' /** * Fires after the record (file) has been removed from the store * @event fileremove * @param {Ext.ux.UploadPanel} this * @param {Ext.data.Store} store */ ,'fileremove' /** * Fires before all files are removed from the store (queue). Return false to cancel the clear. * Events for individual files being removed are suspended while clearing the queue. * @event beforequeueclear * @param {Ext.ux.UploadPanel} this * @param {Ext.data.Store} store */ ,'beforequeueclear' /** * Fires after the store (queue) has been cleared * Events for individual files being removed are suspended while clearing the queue. * @event queueclear * @param {Ext.ux.UploadPanel} this * @param {Ext.data.Store} store */ ,'queueclear' /** * Fires after the upload button is clicked but before any upload is started * Return false to cancel the event * @param {Ext.ux.UploadPanel} this */ ,'beforeupload' ); // }}} // {{{ // relay view events this.relayEvents(this.view, [ 'beforeclick' ,'beforeselect' ,'click' ,'containerclick' ,'contextmenu' ,'dblclick' ,'selectionchange' ]); // }}} // create uploader var config = { store:this.store ,singleUpload:this.singleUpload ,maxFileSize:this.maxFileSize ,enableProgress:this.enableProgress ,url:this.url ,path:this.path }; if(this.baseParams) { config.baseParams = this.baseParams; } this.uploader = new Ext.ux.FileUploader(config);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -