📄 ext.ux.fileuploader.js
字号:
} // multipleUpload - each file uploaded in it's own form else { if(error && 'object' === Ext.type(error)) { record.set('error', error.errors && error.errors[record.id] ? error.errors[record.id] : this.unknownErrorText); } else if(error) { record.set('error', error); } else if(response && response.responseText) { record.set('error', response.responseText); } else { record.set('error', this.unknownErrorText); } record.set('state', 'failed'); record.commit(); } } // eof processFailure // }}} // {{{ /** * Delayed task callback */ ,requestProgress:function() { var records, p; var o = { url:this.progressUrl ,method:'post' ,params:{} ,scope:this ,callback:function(options, success, response) { var o; if(true !== success) { return; } try { o = Ext.decode(response.responseText); } catch(e) { return; } if('object' !== Ext.type(o) || true !== o.success) { return; } if(this.singleUpload) { this.progress = {}; for(p in o) { if(this.progressMap[p]) { this.progress[this.progressMap[p]] = parseInt(o[p], 10); } } if(true !== this.eventsSuspended) { this.fireEvent('progress', this, this.progress); } } else { for(p in o) { if(this.progressMap[p] && options.record) { options.record.set(this.progressMap[p], parseInt(o[p], 10)); } } if(options.record) { options.record.commit(); if(true !== this.eventsSuspended) { this.fireEvent('progress', this, options.record.data, options.record); } } } this.progressTask.delay(this.progressInterval); } }; if(this.singleUpload) { o.params[this.progressIdName] = this.progressId; o.params.APC_UPLOAD_PROGRESS = this.progressId; Ext.Ajax.request(o); } else { records = this.store.query('state', 'uploading'); records.each(function(r) { o.params[this.progressIdName] = r.get('progressId'); o.params.APC_UPLOAD_PROGRESS = o.params[this.progressIdName]; o.record = r; (function() { Ext.Ajax.request(o); }).defer(250); }, this); } } // eo function requestProgress // }}} // {{{ /** * path setter * @private */ ,setPath:function(path) { this.path = path; } // eo setPath // }}} // {{{ /** * url setter * @private */ ,setUrl:function(url) { this.url = url; } // eo setUrl // }}} // {{{ /** * Starts progress fetching from server * @private */ ,startProgress:function() { if(!this.progressTask) { this.progressTask = new Ext.util.DelayedTask(this.requestProgress, this); } this.progressTask.delay.defer(this.progressInterval / 2, this.progressTask, [this.progressInterval]); } // eo function startProgress // }}} // {{{ /** * Stops progress fetching from server * @private */ ,stopProgress:function() { if(this.progressTask) { this.progressTask.cancel(); } } // eo function stopProgress // }}} // {{{ /** * Stops all currently running uploads */ ,stopAll:function() { var records = this.store.query('state', 'uploading'); records.each(this.stopUpload, this); } // eo function stopAll // }}} // {{{ /** * Stops currently running upload * @param {Ext.data.Record} record Optional, if not set singleUpload = true is assumed * and the global stop is initiated */ ,stopUpload:function(record) { // single abord var iframe = false; if(record) { iframe = this.getIframe(record); this.stopIframe(iframe); this.upCount--; this.upCount = 0 > this.upCount ? 0 : this.upCount; record.set('state', 'stopped'); this.fireFinishEvents({record:record}); } // all abort else if(this.form) { iframe = Ext.fly(this.form.dom.target); this.stopIframe(iframe); this.upCount = 0; this.fireFinishEvents(); } } // eo function abortUpload // }}} // {{{ /** * Stops uploading in hidden iframe * @private * @param {Ext.Element} iframe */ ,stopIframe:function(iframe) { if(iframe) { try { iframe.dom.contentWindow.stop(); iframe.remove.defer(250, iframe); } catch(e){} } } // eo function stopIframe // }}} // {{{ /** * Main public interface function. Preforms the upload */ ,upload:function() { var records = this.store.queryBy(function(r){return 'done' !== r.get('state');}); if(!records.getCount()) { return; } // fire beforeallstart event if(true !== this.eventsSuspended && false === this.fireEvent('beforeallstart', this)) { return; } if(this.singleUpload) { this.uploadSingle(); } else { records.each(this.uploadFile, this); } if(true === this.enableProgress) { this.startProgress(); } } // eo function upload // }}} // {{{ /** * called for both success and failure. Does nearly nothing * @private * but dispatches processing to processSuccess and processFailure functions */ ,uploadCallback:function(options, success, response) { var o; this.upCount--; this.form = false; // process ajax success if(true === success) { try { o = Ext.decode(response.responseText); } catch(e) { this.processFailure(options, response, this.jsonErrorText); this.fireFinishEvents(options); return; } // process command success if(true === o.success) { this.processSuccess(options, response, o); } // process command failure else { this.processFailure(options, response, o); } } // process ajax failure else { this.processFailure(options, response); } this.fireFinishEvents(options); } // eo function uploadCallback // }}} // {{{ /** * Uploads one file * @param {Ext.data.Record} record * @param {Object} params Optional. Additional params to use in request. */ ,uploadFile:function(record, params) { // fire beforestart event if(true !== this.eventsSuspended && false === this.fireEvent('beforefilestart', this, record)) { return; } // create form for upload var form = this.createForm(record); // append input to the form var inp = record.get('input'); inp.set({name:inp.id}); form.appendChild(inp); // get params for request var o = this.getOptions(record, params); o.form = form; // set state record.set('state', 'uploading'); record.set('pctComplete', 0); // increment active uploads count this.upCount++; // request upload Ext.Ajax.request(o); // todo:delete after devel this.getIframe.defer(100, this, [record]); } // eo function uploadFile // }}} // {{{ /** * Uploads all files in single request */ ,uploadSingle:function() { // get records to upload var records = this.store.queryBy(function(r){return 'done' !== r.get('state');}); if(!records.getCount()) { return; } // create form and append inputs to it var form = this.createForm(); records.each(function(record) { var inp = record.get('input'); inp.set({name:inp.id}); form.appendChild(inp); record.set('state', 'uploading'); }, this); // create options for request var o = this.getOptions(); o.form = form; // save form for stop this.form = form; // increment active uploads counter this.upCount++; // request upload Ext.Ajax.request(o); } // eo function uploadSingle // }}}}); // eo extend// register xtypeExt.reg('fileuploader', Ext.ux.FileUploader); // eof
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -