📄 uploaddialog.js
字号:
return tpl;
},
updateProgressInfo : function(){
this.getProgressTemplate().overwrite(this.uploadInfoPanel.body,this.formatProgress(this.progressInfo));
},
formatProgress : function(info) {
var r = {};
r.filesUploaded = String.leftPad(info.filesUploaded, 3, ' ');
r.filesTotal = info.filesTotal;
r.bytesUploaded = String.leftPad(Ext.util.Format.fileSize(info.bytesUploaded), 6, ' ');
r.bytesTotal = Ext.util.Format.fileSize(info.bytesTotal);
r.timeElapsed = this.formatTime(info.timeElapsed);
r.speedAverage = Ext.util.Format.fileSize(Math.ceil(1000 * info.bytesUploaded / info.timeElapsed)) + '/s';
r.timeLeft = this.formatTime((info.bytesUploaded === 0) ? 0 : info.timeElapsed * (info.bytesTotal - info.bytesUploaded) / info.bytesUploaded);
var caleSpeed = 1000 * info.lastBytes / info.lastElapsed;
r.speedLast = Ext.util.Format.fileSize(caleSpeed < 0 ? 0:caleSpeed) + '/s';
var p = info.bytesUploaded / info.bytesTotal;
p = p || 0;
this.progressBar.updateProgress(p, "上传中 " + Math.ceil(p * 100) + " %");
return r;
},
formatTime : function(milliseconds) {
var seconds = parseInt(milliseconds / 1000, 10);
var s = 0;
var m = 0;
var h = 0;
if (3599 < seconds) {
h = parseInt(seconds / 3600, 10);
seconds -= h * 3600;
}
if (59 < seconds) {
m = parseInt(seconds / 60, 10);
seconds -= m * 60;
}
m = String.leftPad(m, 2, '0');
h = String.leftPad(h, 2, '0');
s = String.leftPad(seconds, 2, '0');
return h + ':' + m + ':' + s;
},
formatFileSize : function(_v,celmeta,record){
return '<div id="fileSize_' + record.data.fileId + '">' + Ext.util.Format.fileSize(_v) + '</div>';
},
formatFileName : function(_v, cellmeta, record){
return '<div id="fileName_' + record.data.fileId + '">' + _v + '</div>';
},
formatIcon : function(_v, cellmeta, record){
var returnValue = '';
var extensionName = _v.substring(1);
var fileId = record.data.fileId;
if(_v){
var css = '.db-ft-' + extensionName.toLowerCase() + '-small';
if(Ext.isEmpty(Ext.util.CSS.getRule(css),true)){ //判断样式是否存在
returnValue = '<div id="fileType_' + fileId + '" class="db-ft-unknown-small" style="height: 16px;background-repeat: no-repeat;">'
+ ' ' + extensionName.toUpperCase() + '</div>';
}else{
returnValue = '<div id="fileType_' + fileId + '" class="db-ft-' + extensionName.toLowerCase()
+ '-small" style="height: 16px;background-repeat: no-repeat;"/> '
+ extensionName.toUpperCase(); + '</div>';
}
return returnValue;
}
return '<div id="fileType_' + fileId + '" class="db-ft-unknown-small" style="height: 16px;background-repeat: no-repeat;"/> '
+ extensionName.toUpperCase() + '</div>';
},
formatProgressBar : function(_v, cellmeta, record){
var returnValue = '';
switch(record.data.fileState){
case SWFUpload.FILE_STATUS.COMPLETE:
if(Ext.isIE){
returnValue =
'<div class="x-progress-wrap" style="height: 18px">' +
'<div class="x-progress-inner">' +
'<div style="width: 100%;" class="x-progress-bar x-progress-text">' + '100 %'
'</div>' +
'</div>' +
'</div>';
}else{
returnValue =
'<div class="x-progress-wrap" style="height: 18px">' +
'<div class="x-progress-inner">' +
'<div id="progressBar_' + record.data.fileId + '" style="width: 100%;" class="x-progress-bar">' +
'</div>' +
'<div id="progressText_' + record.data.fileId + '" style="width: 100%;" class="x-progress-text x-progress-text-back" />100 %</div>'
'</div>' +
'</div>';
}
break;
default :
returnValue =
'<div class="x-progress-wrap" style="height: 18px">' +
'<div class="x-progress-inner">' +
'<div id="progressBar_' + record.data.fileId + '" style="width: 0%;" class="x-progress-bar">' +
'</div>' +
'<div id="progressText_' + record.data.fileId + '" style="width: 100%;" class="x-progress-text x-progress-text-back" />0 %</div>'
'</div>' +
'</div>';
break;
}
return returnValue;
},
formatState : function(_v, cellmeta, record){
var returnValue = '';
switch(_v){
case SWFUpload.FILE_STATUS.QUEUED:
returnValue = '<span id="' + record.id + '"><div id="fileId_' + record.data.fileId + '" class="ux-cell-icon-delete"/></span>';
break;
case SWFUpload.FILE_STATUS.CANCELLED:
returnValue = '<span id="' + record.id + '"><div id="fileId_' + record.data.fileId + '" class="ux-cell-icon-clear"/></span>';
break;
case SWFUpload.FILE_STATUS.COMPLETE:
returnValue = '<span id="' + record.id + '"><div id="fileId_' + record.data.fileId + '" class="ux-cell-icon-completed"/></span>';
break;
default :
alert('没有设置图表状态');
break;
}
return returnValue;
},
onClose : function(){
this.close();
},
onCancelQueue : function(fileId){
Ext.getDom('fileName_' + fileId).className = 'ux-cell-color-gray';//设置文字颜色为灰色
Ext.getDom('fileSize_' + fileId).className = 'ux-cell-color-gray';
Ext.DomHelper.applyStyles('fileType_' + fileId,'font-style:italic;text-decoration: line-through;color:gray');
},
onFileQueued : function(file){
var thiz = this.customSettings.scope_handler;
thiz.fileList.getStore().add(new UploadDialog.FileRecord({
fileId : file.id,
fileName : file.name,
fileSize : file.size,
fileType : file.type,
fileState : file.filestatus
}));
thiz.progressInfo.filesTotal += 1;
thiz.progressInfo.bytesTotal += file.size;
thiz.updateProgressInfo();
},
onQueueError : function(file, errorCode, message){
var thiz = this.customSettings.scope_handler;
//var process_info = this.customSettings.process_info;
try {
if (errorCode != SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {
//process_info.filesTotal -= 1;
//process_info.bytesTotal -= file.size;
thiz.progressInfo.filesTotal -= 1;
thiz.progressInfo.bytesTotal -= file.size;
}
thiz.progressInfo.bytesUploaded -= fpg.getBytesCompleted();
thiz.updateProgressInfo();
// if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
// alert("你尝试添加太多的文件进入队列.\n" + (message === 0 ? "你已经超出上传限定范围." : "你只可以选择 " + (message > 1 ? "上传 " + message + " 文件." : "一个文件.")));
// return;
// }
// switch (errorCode) {
// case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
// //progress.setStatus("文件尺寸超出限制.");
// alert("错误码: 文件太大, 文件名: " + file.name + ", 文件尺寸: " + file.size + ", 消息: " + message);
// break;
// case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
// //progress.setStatus("不能上传 0 字节的文件.");
// alert("错误码: 0 字节文件, 文件名: " + file.name + ", 文件尺寸: " + file.size + ", 消息: " + message);
// break;
// case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
// //progress.setStatus("无效的文件类型.");
// alert("错误码: 无效文件类型, 文件名: " + file.name + ", 文件尺寸: " + file.size + ", 消息: " + message);
// break;
// case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
// alert("你选择文件数量太多. " + (message > 1 ? "你只能添加 " + message + " 更多的文件" : "你不能添加更多的文件."));
// break;
// default:
// if (file !== null) {
// //progress.setStatus("未经处理过的错误");
// }
// alert("错误码: " + errorCode + ", 文件名: " + file.name + ", 文件尺寸: " + file.size + ", 消息: " + message);
// break;
// }
} catch (ex) {
this.debug(ex);
}
},
onFileDialogComplete : function(selectedFilesCount, queuedFilesCount){
//alert("selectedFilesCount:" + selectedFilesCount + " queuedFilesCount:" + queuedFilesCount );
},
onUploadStart : function(file){},
onUploadProgress : function(file, completeBytes, bytesTotal){
var percent = Math.ceil((completeBytes / bytesTotal) * 100);
Ext.getDom('progressBar_' + file.id).style.width = percent + "%";
Ext.getDom('progressText_' + file.id).innerHTML = percent + " %";
var thiz = this.customSettings.scope_handler;
var bytes_added = completeBytes - thiz.progressInfo.currentCompleteBytes;
thiz.progressInfo.bytesUploaded += Math.abs(bytes_added < 0 ? 0 : bytes_added);
thiz.progressInfo.currentCompleteBytes = completeBytes;
if (thiz.progressInfo.lastUpdate) {
thiz.progressInfo.lastElapsed = thiz.progressInfo.lastUpdate.getElapsed();
thiz.progressInfo.timeElapsed += thiz.progressInfo.lastElapsed;
}
thiz.progressInfo.lastBytes = bytes_added;
thiz.progressInfo.lastUpdate = new Date();
thiz.updateProgressInfo();
},
onUploadError : function(file, errorCode, message){
var thiz = this.customSettings.scope_handler;
switch(errorCode){
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
thiz.progressInfo.filesTotal -= 1;
thiz.progressInfo.bytesTotal -= file.size;
thiz.updateProgressInfo();
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
}
//alert('onUploadError,errorCode:' + errorCode + ",message:" + message + ",file.filestatus:" + file.filestatus);
},
onUploadSuccess : function(file, serverData){
var thiz = this.customSettings.scope_handler;
if(Ext.util.JSON.decode(serverData).success){
var record = thiz.fileList.getStore().getById(Ext.getDom('fileId_' + file.id).parentNode.id);
record.set('fileState',file.filestatus);
record.commit();
}
thiz.progressInfo.filesUploaded += 1;
thiz.updateProgressInfo();
},
onUploadComplete : function(file){
if (this.getStats().files_queued > 0 && this.uploadStopped == false) {
this.startUpload();
}
}
});
UploadDialog.FileRecord = Ext.data.Record.create([
{name : 'fileId'},
{name : 'fileName'},
{name : 'fileSize'},
{name : 'fileType'},
{name : 'fileState'}
]);
/*var msg,c =0;
for(var a in cellmeta){
c ++;
msg += a + "\t";
if(c == 10){
msg += "\n";
c = 0;
}
}
alert(msg);*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -