Model.prototype.mainGridCellRender = function(event){
event.html = "<div> <a class='btn btn-link file-operation' style='padding:0px;font-weight: bold;' data-btn-type='upload'>上传</a> </div>";
if (event.colVal && event.colVal.length > 2) {
var array = JSON.parse(event.colVal);
for (var i = 0; i < array.length; i++) {
var htmlArray =[];
htmlArray.push("<div>");
htmlArray.push(" <a class='btn btn-link file-operation' style='padding:0px;color: red;' data-btn-type='del' data-file-index={3}>删除</a>");
htmlArray.push(" <a class='btn btn-link file-operation' style='padding-top:0px; padding-bottom: 0px' data-btn-type='download' data-file-id={0} data-doc-path={1}>{2}</a>");
htmlArray.push("</div>");
event.html += justep.String.format(htmlArray.join(""), array[i].fileID, array[i].docPath, array[i].docName, i);
}
event.html = "<div style='margin: -8px 0px;'>" + event.html + "</div>";
}
}
};
Model.prototype.mainGridRowClick = function(event){
var dataset = event.domEvent.target.dataset;
if (dataset.btnType === "download") {
var url = DocUtils.InnerUtils.getdocServerAction({
docPath : dataset.docPath,
urlPattern : "/repository/file/download/" + dataset.fileId + "/last/content",
isFormAction : false,
context : this.getContext(),
useCookie : false
});
window.open(url);
} else if (dataset.btnType === "upload") {
this._uploader._row = event.row;
this._uploader.inputElement.click();
} else if(dataset.btnType === "del") {
this.comp("msg").show({
type : "YesNo",
title : "系统提示",
message : "是否确认要删除这个文件?",
callback : function(param) {
if (param && param.button === "yes") {
var row =event.row;
var array = JSON.parse(row.val("file"));
array.splice(dataset.fileIndex,1);
row.val("pfile", JSON.stringify(array));
row.data.saveData();
}
}
});
}
};
Model.prototype.initUploader = function() {
var actionUrl = "/BusinessServer/business-action?" + this.getContext().getBSessionID();
var uploader = new Uploader(this.getElementByXid("btnUpload"), {
multiple : false,
actionUrl : actionUrl,
name : "in",
requestHeader : {
"Accept" : "application/json"
},
data : {
process : this.getContext().getCurrentProcess(),
activity : this.getContext().getCurrentActivity(),
action : "uploadDocFileAction",
subPath : "file"
},
});
this._uploader = uploader;
var me = this;
this._uploader.on('onSuccess', function(event) {
var files = this._row.val("file");
if (files && files.length > 0) {
files = JSON.parse(files);
} else {
files = [];
}
files.push({
"docID" : event.response.data.value.docID,
"docName" : event.file.name,
"size" : event.file.size,
"docPath" : event.response.data.value.docPath,
"fileID" : event.response.data.value.fileID,
"time" : event.file.lastModifiedDate.toISOString()
});
this._row.val("pfile", JSON.stringify(files));
this._row.data.saveData();
layer.close(me._layerIndex);
});
this._uploader.on('onStart', function(event) {
me._layerIndex = layer.load(1);
event.file.data.name = encodeURI(event.file.name);
});
};