o2.widget = o2.widget || {}; if( !o2.widget.UUID )o2.require("o2.widget.UUID", null, false); o2.widget.AttachmentController = o2.widget.ATTER = new Class({ Extends: o2.widget.Common, Implements: [Options, Events], options: { "style": "default", "listStyle": "icon", "size": "max", "resize": true, "attachmentCount": 0, "isUpload": true, "isDelete": true, "isReplace": true, "isDownload": true, "isPreviewAtt": true, "isSizeChange": true, "isConfig": true, "isOrder": true, "readonly": false, "availableListStyles" : ["list","seq","icon","preview"], "toolbarGroupHidden" : [], //edit read list view "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"], "audios": ["mp3", "wav", "wma", "wmv"], "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"], "actionShowText" : false }, initialize: function(container, module, options){ this.setOptions(options); this.pages = []; this.path = o2.session.path+"/widget/$AttachmentController/"; this.cssPath = o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/css.wcss"; this._loadCss(); var iconUrl = this.options.iconConfigUrl ? this.options.iconConfigUrl : "../x_component_File/$Main/icon.json"; o2.getJSON(iconUrl, function(json){ this.icons = json; }.bind(this), false); this.module = module; this.actions = []; this.attachments = []; this.selectedAttachments = []; this.container = $(container); }, load: function(){ // if (!layout.mobile){ if (this.options.size==="min"){ this.loadMin(); }else{ this.loadMax(); } // }else{ // this.loadMobile(); // } }, reloadAttachments: function(){ if (this.options.size==="min"){ this.minContent.empty(); var atts = this.attachments; this.attachments = []; while (atts.length){ var att = atts.shift(); this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this)); } }else{ this.content.empty(); var atts = this.attachments; this.attachments = []; while (atts.length){ var att = atts.shift(); this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this)); } } this.checkActions(); }, getAttachmentById: function(attId){ for( var i=0; i0){ var pos_decimal = str.indexOf('.'); if (pos_decimal < 0){ pos_decimal = str.length; str += '.'; } var decimalStr = (str).substr(pos_decimal+1, (str).length); while (decimalStr.length < decimals){ str += '0'; decimalStr += 0; } } return str; }, getOffsetX : function(node){ return (node.getStyle("margin-left").toInt() || 0 ) + (node.getStyle("margin-right").toInt() || 0 ) + (node.getStyle("padding-left").toInt() || 0 ) + (node.getStyle("padding-right").toInt() || 0 )+ (node.getStyle("border-left-width").toInt() || 0 ) + (node.getStyle("border-right-width").toInt() || 0 ); }, reloadTopNode : function(){ this.createTopNode(); }, createEditGroupActions: function(){ if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode); if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode); this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function(e, node){ this.uploadAttachment(e, node); }.bind(this)); this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function(e, node){ this.deleteAttachment(e, node); }.bind(this)); if( !this.options.isReplaceHidden ){ this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function(e, node){ this.replaceAttachment(e, node); }.bind(this)); } // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){ // this.openInOfficeControl(e, node); // }.bind(this)); if( !this.options.toolbarGroupHidden.contains("read") )this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode); }, createReadGroupActions: function(){ //this.readActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode); //this.readActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.readActionBoxNode); if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode); if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode); this.downloadAction = this.createAction(this.editActionsGroupNode, "download", o2.LP.widget.download, function(){ this.downloadAttachment(); }.bind(this)); //this.createAction(this.readActionsGroupNode, "share", o2.LP.widget.share, function(){ // this.transAttachment(); //}.bind(this)); //this.downloadAllAction = this.createAction(this.editActionsGroupNode, "downloadAll", o2.LP.widget.downloadAll, function(){ // this.downloadAllAttachment(); //}.bind(this)); }, createListGroupActions: function(){ var availableListStyles = this.options.availableListStyles; if( availableListStyles && availableListStyles.length > 0 ){ this.listActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode); this.listActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.listActionBoxNode); if( availableListStyles.contains("list") ){ this.listAction = this.createAction(this.listActionsGroupNode, "list", o2.LP.widget.list, function(){ this.changeListStyle("list"); }.bind(this)); } if( availableListStyles.contains("seq") ) { this.sequenceAction = this.createAction(this.listActionsGroupNode, "seq", o2.LP.widget.sequence, function () { this.changeListStyle("sequence"); }.bind(this)); } if( availableListStyles.contains("icon") ) { this.iconAction = this.createAction(this.listActionsGroupNode, "icon", o2.LP.widget.icon, function () { this.changeListStyle("icon"); }.bind(this)); } if( availableListStyles.contains("preview") ) { this.previewAction = this.createAction(this.listActionsGroupNode, "preview", o2.LP.widget.preview, function () { this.changeListStyle("preview"); }.bind(this)); } } }, createViewGroupActions: function(){ if (this.options.isSizeChange){ this.viewActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode); this.viewActionBoxNode.setStyles({"float": "right", "margin-right": "7px"}); this.viewActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.viewActionBoxNode); this.sizeAction = this.createAction(this.viewActionsGroupNode, "min", o2.LP.widget.min, function(){ this.changeControllerSize(); }.bind(this)); } }, createSeparate: function(groupNode){ var separateNode = new Element("div.separateNode", {"styles": this.css.separateNode}).inject(groupNode); return separateNode; }, createAction: function(groupNode, img, title, click){ var actionNode = new Element("div", {"styles": this.css.actionNode, "title": title}).inject(groupNode); var actionIconNode = new Element("div", {"styles": this.css.actionIconNode}).inject(actionNode); actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/icon/"+img+".png)"); var _self = this; actionNode.addEvents({ "mouseover": function(){ if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.options.style+"/overbg.png)"); }, "mouseout": function(){ if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "transparent"); }, "click": function(e){ if (!this.retrieve("disabled")) _self.doAction(e, this, click); e.stopPropagation(); } }); this.actions.push(actionNode); return actionNode; }, checkActions: function(){ // if (this.options.readonly){ // this.setReadonly(); // }else{ this.checkUploadAction(); this.checkDeleteAction(); this.checkReplaceAction(); //this.checkOfficeAction(); this.checkDownloadAction(); this.checkSizeAction(); this.checkListStyleAction(); if( this.options.size === "max" ){ this.checkEditActionBox(); } }, checkEditActionBox: function(){ var isShowEdit = false; ["isUpload", "isDelete", "isReplace"].each(function( key ){ if( key === "isReplace" && this.options.isReplaceHidden )return; if( this.options[key] !== "hidden" )isShowEdit = true; }.bind(this)); var isShowRead = false; ["isDownload"].each(function( key ){ if( this.options[key] !== "hidden" )isShowRead = true; }.bind(this)); if(this.editActionSeparateNode)this.editActionSeparateNode.setStyle( "display", isShowEdit && isShowRead ? "" : "none" ); if(this.editActionBoxNode )this.editActionBoxNode.setStyle( "display", isShowEdit || isShowRead ? "" : "none" ); }, checkUploadAction: function(){ if (this.options.readonly) { if (this.options.isUpload === "hidden") { this.setActionHidden(this.uploadAction); this.setActionHidden(this.min_uploadAction); } else { this.setActionDisabled(this.uploadAction); this.setActionDisabled(this.min_uploadAction); } return false; } if (this.options.isUpload === "hidden" ){ this.setActionHidden(this.uploadAction); this.setActionHidden(this.min_uploadAction); }else if (!this.options.isUpload){ this.setActionDisabled(this.uploadAction); this.setActionDisabled(this.min_uploadAction); }else{ if (this.options.attachmentCount.toInt() > 0){ if (this.attachments.length>=this.options.attachmentCount.toInt()){ this.setActionDisabled(this.uploadAction); this.setActionDisabled(this.min_uploadAction); }else{ this.setActionEnabled(this.uploadAction); this.setActionEnabled(this.min_uploadAction); } }else{ this.setActionEnabled(this.uploadAction); this.setActionEnabled(this.min_uploadAction); } } }, checkDeleteAction: function(){ if (this.options.readonly){ if (this.options.isDelete === "hidden") { this.setActionHidden(this.deleteAction); this.setActionHidden(this.min_deleteAction); } else { this.setActionDisabled(this.deleteAction); this.setActionDisabled(this.min_deleteAction); } this.setAttachmentsAction("delete", false ); return false; } if (this.options.isDelete === "hidden") { this.setActionHidden(this.deleteAction); this.setActionHidden(this.min_deleteAction); this.setAttachmentsAction("delete", false ); } else if (!this.options.isDelete){ this.setActionDisabled(this.deleteAction); this.setActionDisabled(this.min_deleteAction); this.setAttachmentsAction("delete", false ); }else{ if (this.selectedAttachments.length){ this.setActionEnabled(this.deleteAction); this.setActionEnabled(this.min_deleteAction); }else{ this.setActionDisabled(this.deleteAction); this.setActionDisabled(this.min_deleteAction); } this.setAttachmentsAction("delete", true ); } }, isAttDeleteAvailable : function( att ){ if (this.options.readonly)return false; if( this.options.toolbarGroupHidden.contains("edit") )return false; return this.options.isDelete && this.options.isDelete !== "hidden"; }, isAttEditAvailable : function( att ){ if (this.options.readonly)return false; if( this.options.toolbarGroupHidden.contains("edit") )return false; return this.options.isEditAtt && this.options.isEditAtt !== "hidden"; }, // checkOfficeAction: function(){ // if (this.officeAction) this.officeAction.setStyle("display", "none"); // if (this.min_officeAction) this.min_officeAction.setStyle("display", "none"); // }, checkReplaceAction: function(){ if( this.options.isReplaceHidden )return; if (this.options.readonly){ if( this.options.isReplace === "hidden" ){ this.setActionHidden(this.replaceAction); this.setActionHidden(this.min_replaceAction); }else{ this.setActionDisabled(this.replaceAction); this.setActionDisabled(this.min_replaceAction); } this.setAttachmentsAction("replace", false ); return false; } if( this.options.isReplace === "hidden" ){ this.setActionHidden(this.replaceAction); this.setActionHidden(this.min_replaceAction); this.setAttachmentsAction("replace", false ); }else if (!this.options.isReplace){ this.setActionDisabled(this.replaceAction); this.setActionDisabled(this.min_replaceAction); this.setAttachmentsAction("replace", false ); }else{ if (this.selectedAttachments.length && this.selectedAttachments.length==1){ this.setActionEnabled(this.replaceAction); this.setActionEnabled(this.min_replaceAction); }else{ this.setActionDisabled(this.replaceAction); this.setActionDisabled(this.min_replaceAction); } this.setAttachmentsAction("replace", true ); } }, isAttReplaceAvailable : function( att ){ if (this.options.readonly)return false; if( this.options.toolbarGroupHidden.contains("edit") )return false; return this.options.isReplace && this.options.isReplace !== "hidden"; }, checkDownloadAction: function(){ if( this.options.isDownload === "hidden" ){ this.setActionHidden(this.downloadAction); this.setActionHidden(this.min_downloadAction); this.setActionHidden(this.downloadAllAction); this.setAttachmentsAction("download", false ); }else if (!this.options.isDownload){ this.setActionDisabled(this.downloadAction); this.setActionDisabled(this.min_downloadAction); this.setActionDisabled(this.downloadAllAction); this.setAttachmentsAction("download", false ); }else{ if (this.selectedAttachments.length){ this.setActionEnabled(this.downloadAction); this.setActionEnabled(this.min_downloadAction); }else{ this.setActionDisabled(this.downloadAction); this.setActionDisabled(this.min_downloadAction); } this.setActionEnabled(this.downloadAllAction); this.setAttachmentsAction("download", true ); } }, isAttDblclickAvailable : function( att ){ return this.options.dblclick && this.options.dblclick !== "hidden"; }, isAttDownloadAvailable : function( att ){ if( this.options.toolbarGroupHidden.contains("read") )return false; return this.options.isDownload && this.options.isDownload !== "hidden"; }, checkSizeAction: function(){ if( this.sizeAction ){ if (this.options.isSizeChange){ this.setActionEnabled(this.sizeAction); }else{ this.setActionDisabled(this.sizeAction); } } }, checkListStyleAction: function(){ switch (this.options.listStyle){ case "list": this.setActionSelcted(this.listAction); this.setActionUnSelcted(this.iconAction); this.setActionUnSelcted(this.previewAction); this.setActionUnSelcted(this.sequenceAction); break; case "icon": this.setActionUnSelcted(this.listAction); this.setActionSelcted(this.iconAction); this.setActionUnSelcted(this.previewAction); this.setActionUnSelcted(this.sequenceAction); break; case "preview": this.setActionUnSelcted(this.listAction); this.setActionUnSelcted(this.iconAction); this.setActionSelcted(this.previewAction); this.setActionUnSelcted(this.sequenceAction); break; case "sequence": this.setActionUnSelcted(this.listAction); this.setActionUnSelcted(this.iconAction); this.setActionUnSelcted(this.previewAction); this.setActionSelcted(this.sequenceAction); break; } }, setActionSelcted: function(action){ if (action){ if (!action.retrieve("selected")){ action.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/selectedbg.png)"); action.store("selected", true); } } }, setActionUnSelcted: function(action){ if (action){ if (action.retrieve("selected")){ action.setStyle("background", ""); action.store("selected", false); } } }, setActionEnabled: function(action){ if (action){ action.show(); if (action.retrieve("disabled")){ var iconNode = action.getFirst(); var icon = iconNode.getStyle("background-image"); var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length); icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext; iconNode.setStyle("background-image", icon); action.store("disabled", false); } } }, setActionDisabled: function(action){ if (action){ if (!action.retrieve("disabled")){ var iconNode = action.getFirst(); var icon = iconNode.getStyle("background-image"); var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length); icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext; iconNode.setStyle("background-image", icon); action.store("disabled", true); } } }, setActionHidden: function(action){ if (action)action.hide(); }, setReadonly: function() { this.actions.each(function(action){ this.setActionDisabled(action); this.setAttachmentsAction("all", false ); }.bind(this)); }, setAttachmentsAction : function(type, enable){ this.attachments.each( function( att ){ this.setAttachmentAction( att, type, enable ) }.bind(this)) }, setAttachmentAction : function(att, type, enable){ var action; if( type === "all" ){ ( att.actions || [] ).each( function(action){ att[ enable ? "setActionEnabled" : "setActionDisabled" ](action); }) }else{ switch( type ){ case "download" : action = att.downloadAction; break; case "config" : action = att.configAction; break; case "delete" : action = att.deleteAction; break; case "replace" : action = att.replaceAction; break; } if( !action )return; if( type === "config" ){ var flag = enable; if( flag ){ var user = layout.session.user.distinguishedName; if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid; if ((!att.data.control.allowControl ) && att.data.person!==user){ //|| !att.data.control.allowEdit flag = false; } } att[ flag ? "setActionEnabled" : "setActionDisabled" ](action); }else{ att[ enable ? "setActionEnabled" : "setActionDisabled" ](action); } } }, doAction: function(e, node, action){ if (action){ action.apply(this, [e, node]); } }, uploadAttachment: function(e, node, files){ debugger; if (this.module) this.module.uploadAttachment(e, node, files); }, doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){ if (this.options.isUpload && this.options.isUpload !== "hidden" ){ if (FormData.expiredIE){ this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery); }else{ this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files); } }else{ var text = o2.LP.widget.notUploadNotice; if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node); } }, addUploadMessage: function(fileName){ var contentHTML = ""; contentHTML = "
" + "
" + "
"+o2.LP.desktop.action.uploadTitle+"
" + "" ; var msg = { "subject": o2.LP.desktop.action.uploadTitle, "content": fileName+"
"+contentHTML }; if (layout.desktop.message){ var messageItem = layout.desktop.message.addMessage(msg); messageItem.close = function(callback, e){ if (!messageItem.completed){ }else{ messageItem.closeItem(callback, e); } }; } window.setTimeout(function(){ if (layout.desktop.message) if (!layout.desktop.message.isShow) layout.desktop.message.show(); }.bind(this), 300); return messageItem; }, setMessageTitle: function(messageItem, text){ if (messageItem) messageItem.subjectNode.set("text", text); }, setMessageText: function(messageItem, text){ if (messageItem){ var progressNode = messageItem.contentNode.getFirst("div").getFirst("div"); var progressPercentNode = progressNode.getFirst("div"); var progressInforNode = messageItem.contentNode.getFirst("div").getLast("div"); progressInforNode.set("text", text); messageItem.dateNode.set("text", (new Date()).format("db")); } }, doInputUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, failureEvery){ var restActions = action; if (typeOf(action)=="string"){ restActions = o2.Actions.get(action).action; } restActions.getActions(function(){ var url = restActions.actions[invokeUrl]; url = restActions.address+url.uri; Object.each(parameter, function(v, k){ url = url.replace("{"+k+"}", v); }); var maskNode = this.module.content; if (!maskNode){ if (this.module.form){ maskNode = this.module.form.app.content; } } if (!maskNode) maskNode = this.node; //var maskNode = this.module.content || this.module.node; if (maskNode){ maskNode.mask({ "style": { "opacity": 0.7, "background-color": "#999" } }); } this.inputUploadAreaNode = new Element("div", {"styles": this.css.inputUploadAreaNode}).inject(this.container); this.inputUploadAreaNode.position({ relativeTo: this.module.content, position: "center" }); var messageItem = null; document.O2UploadCallbackFun = function(str){ var json = JSON.decode(str); messageItem.completed = true; if (json.type==="success"){ if (every) every(json.data); this.setMessageTitle(messageItem, o2.LP.desktop.action.uploadComplete); this.setMessageText(messageItem, o2.LP.desktop.action.uploadComplete); if(finish) finish(); }else{ //formNode.unmask(); // if(failureEvery)failureEvery(json); this.setMessageTitle(messageItem, o2.LP.desktop.action.sendError); this.setMessageText(messageItem, o2.LP.desktop.action.sendError+": "+json.message); o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message); } }.bind(this); var formNode = new Element("form", { "method": "POST", "action": url+"/callback/window.frameElement.ownerDocument.O2UploadCallbackFun", //"action": url, "enctype": "multipart/form-data", "target": "o2_upload_iframe" }).inject(this.inputUploadAreaNode); var titleNode = new Element("div", {"styles": this.css.inputUploadAreaTitleNode, "text": o2.LP.widget.uploadTitle}).inject(formNode); var inforNode = new Element("div", {"styles": this.css.inputUploadAreaInforNode, "text": o2.LP.widget.uploadInfor}).inject(formNode); var inputAreaNode = new Element("div", {"styles": this.css.inputUploadAreaInputAreaNode}).inject(formNode); var inputNode = new Element("input", {"name":"file", "type": "file", "styles": this.css.inputUploadAreaInputNode}).inject(inputAreaNode); var inputNameNode = new Element("input", {"type": "hidden", "name": "fileName"}).inject(inputAreaNode); Object.each(obj, function(v, k){ new Element("input", {"type": "hidden", "name": k, "value": v}).inject(inputAreaNode); }); var actionNode = new Element("div", {"styles": this.css.inputUploadActionNode}).inject(formNode); var cancelButton = new Element("button", {"styles": this.css.inputUploadCancelButton, "text": o2.LP.widget.cancel}).inject(actionNode); var okButton = new Element("input", {"type": "button", "styles": this.css.inputUploadOkButton, "value": o2.LP.widget.ok}).inject(actionNode); inputNode.addEvent("change", function(){ var fileName = inputNode.get("value"); if (fileName){ var tmpv = fileName.replace(/\\/g, "/"); var i = tmpv.lastIndexOf("/"); var fname = (i===-1) ? tmpv : tmpv.substr(i+1, tmpv.length-i); inputNameNode.set("value", fname); } }.bind(this)); cancelButton.addEvent("click", function(){ if (maskNode) maskNode.unmask(); this.inputUploadAreaNode.destroy(); }.bind(this)); okButton.addEvent("click", function(){ formNode.mask({ "style": { "opacity": 0.7, "background-color": "#999" } }); var isContinue = true; if (beforeUpload) isContinue = beforeUpload([inputNameNode.get("value")]); if (isContinue){ messageItem = this.addUploadMessage(inputNameNode.get("value")); formNode.submit(); if (maskNode) maskNode.unmask(); if (this.inputUploadAreaNode) this.inputUploadAreaNode.destroy(); } }.bind(this)); }.bind(this)); }, doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){ var uploadChange = function(uploadfiles){ var files = uploadfiles || this.fileUploadNode.files; if (files.length){ var count = files.length; var current = 0; var hasFailUpload = false; var restActions = action; if (typeOf(action)=="string"){ restActions = o2.Actions.get(action).action; } //var url = restActions.action.actions[invokeUri]; var callback = function(){ if (current == count){ if(finish) finish( hasFailUpload ); } }; var isContinue = true; if (beforeUpload) isContinue = beforeUpload(files); if (isContinue){ var accepts = (accept) ? accept.split(o2.splitStr) : null; for (var i = 0; i < files.length; i++) { var file = files.item(i); var ext = file.name.substr(file.name.lastIndexOf("."), file.name.length); ext = ext.toLowerCase(); if (accepts && (accepts.indexOf(ext)===-1 && accepts.indexOf("*")===-1 && accepts.indexOf("*/*")===-1)){ var msg = { "subject": o2.LP.widget.refuseUpload, "content": o2.LP.widget.refuseUploadHTML.replace("{filename}", file.name) }; if (layout.desktop.message) layout.desktop.message.addTooltip(msg); if (layout.desktop.message) layout.desktop.message.addMessage(msg); var text = o2.LP.widget.refuseUploadNotice.replace("{filename}", file.name); if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node); }else if (size && file.size> size*1024*1024){ var msg = { "subject": o2.LP.widget.refuseUpload, "content": o2.LP.widget.refuseUploadHTML_size.replace("{filename}", file.name).replace("{size}", size) }; if (layout.desktop.message) layout.desktop.message.addTooltip(msg); if (layout.desktop.message) layout.desktop.message.addMessage(msg); var text = o2.LP.widget.refuseUploadNotice_size.replace("{filename}", file.name).replace("{size}", size); if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node); }else{ var formData = new FormData(); Object.each(obj, function(v, k){ formData.append(k, v) }); formData.append('file', file); if(parameter.fileMd5){ o2.load("../o2_lib/CryptoJS/components/spark-md5-min.js", function(){ var fileReader = new FileReader(), box = document.getElementById('box'); var blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice; var chunkSize = 20971520; // read in chunks of 20MB var chunks = Math.ceil(file.size / chunkSize), currentChunk = 0, spark = new SparkMD5(); fileReader.onload = function(e) { console.log("read chunk nr", currentChunk + 1, "of", chunks); spark.appendBinary(e.target.result); currentChunk++; if (currentChunk < chunks) { loadNext(); } else { console.log("finished loading"); var fileMd5 = spark.end(); restActions.invoke({ "name": "checkFileExist", "async": true, "parameter": {"fileMd5":fileMd5}, "success": function(json){ if(json.data.value){ var formData2 = new FormData(); formData2.append("fileMd5",fileMd5); formData2.append("fileName",file.name); restActions.invoke({ "name": "addAttachmentMd5", "async": true, "data": formData2, "parameter": parameter, "success": function(json){ current++; if (every) every(json, current, count); callback(); }, "failure": function (xhr) { var json = JSON.decode(xhr.responseText); if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message); current++; hasFailUpload = true; if (failureEvery) failureEvery(xhr, current, count); callback(); } }); }else{ restActions.invoke({ "name": invokeUrl, "async": true, "data": formData, "file": file, "parameter": parameter, "success": function(json){ current++; if (every) every(json, current, count); callback(); }, "failure": function (xhr) { var json = JSON.decode(xhr.responseText); if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message); current++; hasFailUpload = true; if (failureEvery) failureEvery(xhr, current, count); callback(); } }); } } }); // compute hash } }; function loadNext() { var start = currentChunk * chunkSize, end = start + chunkSize >= file.size ? file.size : start + chunkSize; fileReader.readAsBinaryString(blobSlice.call(file, start, end)); } loadNext(); }.bind(this),null,false); }else{ restActions.targetModule = {"module": this, "file": file}; restActions.invoke({ "name": invokeUrl, "async": true, "data": formData, "file": file, "parameter": parameter, "success": function(json){ current++; if (every) every(json, current, count); callback(); }, "failure": function (xhr) { var json = JSON.decode(xhr.responseText); if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message); current++; hasFailUpload = true; if (failureEvery) failureEvery(xhr, current, count); callback(); } }); } } } } this.uploadFileAreaNode.destroy(); this.uploadFileAreaNode = null; } }.bind(this); if (!this.uploadFileAreaNode){ this.uploadFileAreaNode = new Element("div"); var html = ""; this.uploadFileAreaNode.set("html", html); this.fileUploadNode = this.uploadFileAreaNode.getFirst(); this.fileUploadNode.addEvent("change", function(){ uploadChange(); }); } this.fileUploadNode.set("accept", accept || "*/*"); this.fileUploadNode.set("multiple", (multiple!==false)); if (!files || !files.length){ this.fileUploadNode.click(); }else{ uploadChange(files) } }, addFormDataMessage: function(file){ return this.addAttachmentMessage(file); }, addAttachmentMessage: function(file){ var messageItem; if (this.options.size=="min"){ messageItem = new o2.widget.AttachmentController.AttachmentMessageMin(file, this); }else{ messageItem = new o2.widget.AttachmentController.AttachmentMessage(file, this); } if (!this.messageItemList) this.messageItemList = {}; this.messageItemList[messageItem.data.id] = messageItem; return messageItem; }, openInOfficeControl: function(e, node){}, deleteAttachment: function(e, node){ if (this.selectedAttachments.length){ if (this.module) this.module.deleteAttachments(e, node, this.selectedAttachments); } }, replaceAttachment: function(e, node){ if (this.selectedAttachments.length && this.selectedAttachments.length==1){ if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]); } }, doReplaceAttachment: function(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size){ if (FormData.expiredIE){ this.doInputUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size); }else{ this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size); } }, previewAttachment: function(e, node){ if (this.selectedAttachments.length){ if (this.module) this.module.previewAttachment(this.selectedAttachments); } }, editAttachment: function(e, node){ if (this.selectedAttachments.length){ if (this.module) this.module.editAttachment(this.selectedAttachments); } }, downloadAttachment: function(e, node){ if (this.selectedAttachments.length){ if (this.module) this.module.downloadAttachment(e, node, this.selectedAttachments); } }, openAttachment: function(e, node, attachment){ if( !this.options.dblclick ){ if( !this.options.isDownload || this.options.isDownload === "hidden" )return; //兼容以前的配置 } if (attachment){ if (this.module) this.module.openAttachment(e, node, attachment); } }, dblclickAttachment: function(e, node, attachment){ if( !attachment || !this.module || this.options.dblclick === "disable" ){ return; }else if( this.options.dblclick === "preview" ){ if( this.checkPreviewAttachment ){ this.checkPreviewAttachment(e, node, attachment); }else{ this.module.openAttachment(e, node, attachment); } }else{ this.module.openAttachment(e, node, attachment); } }, downloadAllAttachment: function(e, node){ if (this.module) this.module.downloadAttachment(e, node, this.attachments); }, changeListStyle: function(style){ this.options.listStyle = style; this.listStyle = style; this.attachments.each(function(attachment){ attachment.changeListStyle(style); }.bind(this)); this.checkListStyleAction(); }, changeControllerSize: function(e, node){ if (this.options.size=="max"){ this.changeControllerSizeToMin(); }else{ this.changeControllerSizeToMax(); } }, changeControllerSizeToMin: function(){ if (this.options.size!="min"){ if (this.contentScrollNode) this.contentScrollNode.setStyle("display", "none"); if (this.bottomNode) this.bottomNode.setStyle("display", "none"); if (this.topNode) this.topNode.setStyle("display", "none"); if (this.titleNode) this.titleNode.setStyle("display", "none"); if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100}); this.nodeMorph.start(this.css.container_min).chain(function(){ this.options.size = "min"; this.loadMin(); }.bind(this)); } }, changeControllerSizeToMax: function(){ if (this.options.size!="max") { if (this.minActionAreaNode) this.minActionAreaNode.setStyle("display", "none"); if (this.minContent) this.minContent.setStyle("display", "none"); if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100}); this.nodeMorph.start(this.css.container).chain(function () { this.options.size = "max"; this.loadMax(); }.bind(this)); } }, getAttachmentNames: function(){ var names = []; this.attachments.each(function(attachment){ names.push(attachment.data.name); }); return names; }, addAttachment: function(data, messageId, isCheckPosition){ if (this.options.size=="min"){ this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(data, this, messageId, isCheckPosition)); }else{ this.attachments.push(new o2.widget.AttachmentController.Attachment(data, this, messageId, isCheckPosition)); } this.checkActions(); }, removeAttachment: function(attachment){ this.attachments.erase(attachment); this.selectedAttachments.erase(attachment); attachment.node.destroy(); delete attachment; }, unSelectedAttachments: function(){ while (this.selectedAttachments.length){ var attachment = this.selectedAttachments.shift(); attachment.unSelected(); } this.checkActions(); }, clear: function(){ this.selectedAttachments = []; this.attachments.each(function(att){ att.node.destroy(); o2.release(att); }); this.attachments = []; var content = (this.minContent || this.content); if (content) content.empty(); } }); o2.widget.AttachmentController.Attachment = new Class({ Implements: [Events], initialize: function(data, controller, messageId, isCheckPosition){ this.data = data; if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid; this.controller = controller; this.css = this.controller.css; this.listStyle = this.controller.options.listStyle; this.content = this.controller.content; this.isSelected = false; this.seq = this.controller.attachments.length+1; this.isCheckPosition = isCheckPosition; this.actions = []; if (messageId && this.controller.messageItemList) { this.message = this.controller.messageItemList[messageId]; } this.load(); }, _getLnkPar: function(url){ return { "icon": this.getIcon(), "title": this.data.name, "par": "@url#"+url }; }, isNumber : function( d ){ return parseFloat(d).toString() !== "NaN" }, load: function(){ if( this.controller.module && this.controller.module.fireEvent ){ this.controller.module.fireEvent("beforeLoadAttachment", [this]); } if (this.message){ this.node = new Element("div").inject(this.message.node, "after"); this.message.node.destroy(); delete this.controller.messageItemList[this.message.data.id]; }else{ this.node = new Element("div").inject(this.content); } if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){ var attList = this.controller.attachments; for( var i=0; i1024){ var m = k/1024; m = Math.round(m*100)/100; size = m+"M"; }else{ k = Math.round(k*100)/100; size = k+"K"; } this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode}); var html = "
"+this.data.name+"
"; html += "
"+o2.LP.widget.uploader+":
"+( this.data.person || this.data.creatorUid )+"
"; html += "
"+o2.LP.widget.uploadTime+":
"+this.data.createTime+"
"; html += "
"+o2.LP.widget.modifyTime+":
"+this.data.lastUpdateTime+"
"; if(this.data.activityName)html += "
"+o2.LP.widget.uploadActivity+":
"+(this.data.activityName || o2.LP.widget.unknow)+"
"; html += "
"+o2.LP.widget.size+":
"+size+"
"; this.inforNode.set("html", html); if (callback) callback(); }, getIcon: function(){ if (!this.data.extension) this.data.extension="unkonw"; var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow; var iconFolderUrl = this.controller.options.iconFolderUrl ? this.controller.options.iconFolderUrl : "../x_component_File/$Main/default/file/"; return iconFolderUrl+iconName; }, loadList: function(){ this.node.setStyles(this.css.attachmentNode_list); if (this.isSelected) this.node.setStyles(this.css.attachmentNode_list_selected); this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node); this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode); this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode); this.iconImgNode.set({"src": this.getIcon(), "border": 0}); this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_list}).inject(this.node); this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode); // this.textTitleNode.set("text", this.data.name); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textTitleNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textTitleNode.set("text", this.data.name); } var size = ""; var k = this.data.length/1024; if (k>1024){ var m = k/1024; m = Math.round(m*100)/100; size = m+"M"; }else{ k = Math.round(k*100)/100; size = k+"K"; } this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode); this.textSizeNode.set("text", size); this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode); this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid )); this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode); this.textTimeNode.set("text", this.data.lastUpdateTime); if(this.data.activityName){ this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode); this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow); } this.custom_List(); }, custom_List: function(){}, loadSequence: function(){ this.node.setStyles(this.css.attachmentNode_sequence); if (this.isSelected) this.node.setStyles(this.css.attachmentNode_sequence_selected); this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node); this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node); this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode); this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode); this.iconImgNode.set({"src": this.getIcon(), "border": 0}); this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_sequence}).inject(this.node); this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode); // this.textTitleNode.set("text", this.data.name); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textTitleNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textTitleNode.set("text", this.data.name); } var size = ""; var k = this.data.length/1024; if (k>1024){ var m = k/1024; m = Math.round(m*100)/100; size = m+"M"; }else{ k = Math.round(k*100)/100; size = k+"K"; } this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode); this.textSizeNode.set("text", size); this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode); this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid)); this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode); this.textTimeNode.set("text", this.data.lastUpdateTime); if(this.data.activityName){ this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode); this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow); } this.custom_Sequence(); }, custom_Sequence: function(){}, loadIcon: function(){ this.node.setStyles(this.css.attachmentNode_icon); if (this.isSelected) this.node.setStyles(this.css.attachmentNode_icon_selected); this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode}).inject(this.node); this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode}).inject(this.iconNode); this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode}).inject(this.iconImgAreaNode); this.iconImgNode.set({"src": this.getIcon(), "border": 0}); this.textNode = new Element("div", {"styles": this.css.attachmentTextNode}).inject(this.node); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textNode.set("text", this.data.name); } this.custom_Icon(); }, custom_Icon: function(){}, loadPreview: function(){ this.node.setStyles(this.css.attachmentNode_preview); if (this.isSelected) this.node.setStyles(this.css.attachmentNode_preview_selected); this.iconNode = new Element("div", {"styles": this.css.attachmentPreviewIconNode}).inject(this.node); this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentPreviewIconImgAreaNode}).inject(this.iconNode); this.iconImgNode = new Element("img", {"styles": this.css.attachmentPreviewIconImgNode}).inject(this.iconImgAreaNode); var icon = this.getIcon(); if (this.controller.options.images.indexOf(this.data.extension.toLowerCase())!==-1){ if (this.type!=="message") this.controller.module.getAttachmentUrl(this, function(url){ this.iconImgAreaNode.hide(); this.iconImgNode.hide(); this.iconNode.setStyles({ "background-image": "url("+url+")", }); }.bind(this)); this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textNode.set("text", this.data.name); } // this.textNode.set("text", this.data.name); }else if (this.controller.options.audios.indexOf(this.data.extension.toLowerCase())!==-1){ this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textNode.set("text", this.data.name); } // this.textNode.set("text", this.data.name); this.controller.module.getAttachmentUrl(this, function(url){ this.iconImgNode.set({"src": icon, "border": 0}); this.iconAudioNode = new Element("div", { "styles": this.css.attachmentPreviewAudioNode, "html": "" //"html": "" }).inject(this.textNode, "after"); this.iconAudioNode.addEvent("dblclick", function(e){e.stopPropagation();}); }.bind(this)); }else if (this.controller.options.videos.indexOf(this.data.extension.toLowerCase())!==-1){ this.controller.module.getAttachmentUrl(this, function(url){ this.iconNode.empty(); this.iconVideoNode = new Element("div", { "styles": this.css.attachmentPreviewVideoNode, //"html": "" "html": "" }).inject(this.iconNode); this.iconVideoNode.addEvent("dblclick", function(e){e.stopPropagation();}); this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textNode.set("text", this.data.name); } // this.textNode.set("text", this.data.name); }.bind(this)); }else{ this.iconImgNode.set({"src": icon, "border": 0}); this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textNode.set("text", this.data.name); } // this.textNode.set("text", this.data.name); } this.custom_Preview(); }, custom_Preview: function(){}, getPreviewImgSize: function(icon, callback){ var areaSize = this.iconNode.getSize(); var img = new Element("img", {"src": icon}).inject($(document.body)); img.set("src", icon); var size = img.getSize(); img.destroy(); var x, y; var zoom = areaSize.x/size.x; var y = size.y*zoom; if (y<=areaSize.y){ x = areaSize.x; }else{ zoom = areaSize.y/size.y; x = size.x*zoom; y = areaSize.y; } var size = {"x": x, "y": y, "top": (areaSize.y-y)/2}; if (callback) callback(size); }, setEvent: function(){ this.node.addEvents({ "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"])}.bind(this), "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle])}.bind(this), "mousedown": function(e){this.selected(e); e.stopPropagation();}.bind(this), "click": function(e){e.stopPropagation();}.bind(this), "dblclick": function(e){ if( this.controller.options.dblclick ){ this.controller.dblclickAttachment(e, null, [this]); }else{ this.openAttachment(e); } }.bind(this) }); if (this.iconImgNode){ this.iconImgNode.set("draggable", false); } }, selected: function(e){ if (!e.event.ctrlKey) this.controller.unSelectedAttachments(); //if (!this.isSelected){ this.controller.selectedAttachments.push(this); this.isSelected = true; this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]); //} if( this.controller.module && this.controller.module.fireEvent ){ this.controller.module.fireEvent("select", [this]); } if (e) e.stopPropagation(); this.controller.checkActions(); }, unSelected: function(){ this.isSelected = false; this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]); this.controller.selectedAttachments.erase(this); if( this.controller.module && this.controller.module.fireEvent ){ this.controller.module.fireEvent("unselect", [this]); } }, changeListStyle: function(style){ if (this.listStyle!=style){ this.node.empty(); switch (style){ case "list": this.loadList(); break; case "icon": this.loadIcon(); break; case "preview": this.loadPreview(); break; case "sequence": this.loadSequence(); break; } this.listStyle = style; } }, reload: function(){ var node = new Element("div").inject(this.node, "after"); this.inforNode.destroy(); this.inforNode = null; if (this.tooltip) this.tooltip.destroy(); this.tooltip = null; this.node.destroy(); delete this.node; this.node = node; switch (this.listStyle){ case "list": this.loadList(); break; case "icon": this.loadIcon(); break; case "preview": this.loadPreview(); break; case "sequence": this.loadSequence(); break; } this.createInforNode(); if (!Browser.Platform.ios){ this.tooltip = new mBox.Tooltip({ content: this.inforNode, setStyles: {content: {padding: 15, lineHeight: 20}}, attach: this.node, transition: 'flyin' }); } this.setEvent(); }, openAttachment: function(e){ if( !this.controller.options.dblclick ){ if (!this.controller.options.isDownload || this.controller.options.isDownload === "hidden") return; //兼容以前的配置 } if (this.controller.module) this.controller.module.openAttachment(e, null, [this]); }, setActionEnabled: function(action){ if (action){ action.setStyle("display",""); action.store("disabled", false); //if (action.retrieve("disabled")){ // var iconNode = action.getFirst(); // var icon = iconNode.getStyle("background-image"); // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length); // icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext; // iconNode.setStyle("background-image", icon); // action.store("disabled", false); //} } }, setActionDisabled: function(action){ if (action){ action.setStyle("display","none"); action.store("disabled", true); //if (!action.retrieve("disabled")){ // var iconNode = action.getFirst(); // var icon = iconNode.getStyle("background-image"); // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length); // icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext; // iconNode.setStyle("background-image", icon); // action.store("disabled", true); //} } }, createAction: function(node, img, img_over, title, click, text){ var actionNode; if( this.controller.options.actionShowText ){ actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "text": text || title, "title" : title }).inject(node); var _self = this; actionNode.addEvents({ "mouseover": function( e ){ if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over){ actionNode.setStyles( _self.controller.css.minActionNode_over ); } }.bind( { actionNode : actionNode } ), "mouseout": function(){ if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over ){ actionNode.setStyles( _self.controller.css.minActionNode ); } }.bind( { actionNode : actionNode } ), "click": function(e){ if (!this.retrieve("disabled")){ click.apply(_self.controller, [e, this]); e.stopPropagation(); } } }); }else{ actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "title": title}).inject(node); var actionIconNode = new Element("div", {"styles": this.controller.css.minActionIconNode}).inject(actionNode); actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.controller.options.style+"/icon/"+img+".png)"); var _self = this; actionNode.addEvents({ "mouseover": function( e ){ if (!this.actionNode.retrieve("disabled")){ this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)"); } }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img_over } ), "mouseout": function(){ if (!this.actionNode.retrieve("disabled")){ this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)"); } }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img } ), "click": function(e){ if (!this.retrieve("disabled")){ click.apply(_self.controller, [e, this]); e.stopPropagation(); } } }); } if( !this.actions )this.actions = []; this.actions.push(actionNode); return actionNode; } }); o2.widget.AttachmentController.AttachmentMin = new Class({ Extends: o2.widget.AttachmentController.Attachment, initialize: function(data, controller, messageId, isCheckPosition){ this.data = data; if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid; this.controller = controller; this.css = this.controller.css; this.listStyle = this.controller.options.listStyle; this.content = this.controller.minContent; this.isSelected = false; this.isCheckPosition = isCheckPosition; this.seq = this.controller.attachments.length+1; if (messageId && this.controller.messageItemList) { this.message = this.controller.messageItemList[messageId]; } this.load(); }, load: function(){ if( this.controller.module && this.controller.module.fireEvent ){ this.controller.module.fireEvent("beforeLoadAttachment", [this]); } if (this.message){ this.node = new Element("div").inject(this.message.node, "after"); this.message.node.destroy(); delete this.controller.messageItemList[this.message.data.id]; }else{ this.node = new Element("div").inject(this.content); } if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){ var attList = this.controller.attachments; for( var i=0; i1024){ var m = k/1024; m = Math.round(m*100)/100; size = m+"M"; }else{ k = Math.round(k*100)/100; size = k+"K"; } this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode); this.textSizeNode.set("text", "("+size+")"); this.node.set("title",this.data.name + "("+size+")"); }, loadSequence: function(){ this.node.setStyles(this.css.minAttachmentNode_sequence); this.actionAreaNode = new Element("div", {"styles":this.css.minAttachmentActionAreaNode}).inject(this.node); if( this.controller.isAttDblclickAvailable(this) ){ this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) { this.controller.dblclickAttachment(e, node, [this]); }.bind(this)); } if ( this.controller.isAttDownloadAvailable(this) ) { this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) { this.controller.downloadAttachment(e, node); }.bind(this)); } //this.actions.push( this.downloadAction ); if ( this.controller.isAttDeleteAvailable(this) ) { this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) { this.controller.deleteAttachment(e, node); }.bind(this)); } if ( this.controller.isAttEditAvailable(this) ) { this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) { this.controller.editAttachment(e, node); }.bind(this)); } //this.actions.push( this.deleteAction ); if (this.controller.configAttachment) { if ( this.controller.isAttConfigAvailable(this) ) { this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", MWF.LP.widget.configAttachment, function (e, node) { this.controller.configAttachment(e, node); }.bind(this)); //this.actions.push( this.configAction ); } } if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected); this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node); this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node); this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode); this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode); this.iconImgNode.set({"src": this.getIcon(), "border": 0}); this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node); if (this.data.objectSecurityPromise){ this.data.objectSecurityPromise.then(function(label){ this.textNode.set("text", "("+label+") " + this.data.name); }.bind(this)); }else{ this.textNode.set("text", this.data.name); } // this.textNode.set("text", this.data.name); var size = ""; var k = this.data.length/1024; if (k>1024){ var m = k/1024; m = Math.round(m*100)/100; size = m+"M"; }else{ k = Math.round(k*100)/100; size = k+"K"; } this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode); this.textSizeNode.set("text", "("+size+")"); }, setEvent: function(){ this.node.addEvents({ "mouseover": function(){ if (!this.isSelected){ if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){ this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_over"]); }else{ this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"]); } } }.bind(this), "mouseout": function(){ if (!this.isSelected){ if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){ var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" ); this.node.setStyles(this.css[cssKey]); }else{ this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]); } } }.bind(this), "mousedown": function(e){this.selected(e);e.stopPropagation();}.bind(this), "click": function(e){e.stopPropagation();}.bind(this), "dblclick": function(e){ if( this.controller.options.dblclick ){ this.controller.dblclickAttachment(e, null, [this]); }else{ this.openAttachment(e); } }.bind(this) }); if (this.iconImgNode){ this.iconImgNode.set("draggable", false); } }, selected: function(e){ if (!e.event.ctrlKey) this.controller.unSelectedAttachments(); //if (!this.isSelected){ this.controller.selectedAttachments.push(this); this.isSelected = true; if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){ //this.node.setStyles(this.css["minAttachmentNode_list_selected"]); this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_selected"]); }else{ this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]); //this.node.setStyles(this.css["minAttachmentNode_list_selected"]); } if( this.controller.module && this.controller.module.fireEvent ){ this.controller.module.fireEvent("select", [this]); } //} if (e) e.stopPropagation(); this.controller.checkActions(); }, reload: function(){ var node = new Element("div").inject(this.node, "after"); this.inforNode.destroy(); this.inforNode = null; if (this.tooltip) this.tooltip.destroy(); this.tooltip = null; this.node.destroy(); delete this.node; this.node = node; debugger; switch (this.listStyle){ case "list": this.loadList(); break; case "icon": this.loadIcon(); break; case "preview": this.loadPreview(); break; case "sequence": this.loadSequence(); break; } this.createInforNode(); if (!Browser.Platform.ios){ this.tooltip = new mBox.Tooltip({ content: this.inforNode, setStyles: {content: {padding: 15, lineHeight: 20}}, attach: this.node, transition: 'flyin' }); } this.setEvent(); }, unSelected: function(){ this.isSelected = false; //this.node.setStyles(this.css["minAttachmentNode_list"]); if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){ var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" ); this.node.setStyles(this.css[cssKey]); }else{ this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]); } if( this.controller.module && this.controller.module.fireEvent ){ this.controller.module.fireEvent("unselect", [this]); } this.controller.selectedAttachments.erase(this); } }); o2.widget.AttachmentController.AttachmentMessage = new Class({ Extends: o2.widget.AttachmentController.Attachment, Implements: [Events], initialize: function(file, controller){ var d = (new Date).format("db"); var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length); this.file = file; this.type = "message"; this.data = { activity: "", activityName: "", activityToken: "", activityType: "manual", application: "", completed: false, control: {allowRead:true, allowEdit:false, allowControl:false}, controllerIdentityList: [], controllerUnitList: [], createTime: d, deepPath: false, divisionList: [], editIdentityList: [], editUnitList: [], extension: extension, id: (new o2.widget.UUID()).toString(), job: "", lastUpdatePerson: (layout) ? layout.session.user.name : "", lastUpdateTime: d, length: file.size, name: file.name, person: (layout) ? layout.session.user.name : "", process: "", readIdentityList: [], readUnitList: [], site: "$doc", storage: file.size, type: "", updateTime: d, workCreateTime: "" } if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid; this.controller = controller; this.css = this.controller.css; this.listStyle = this.controller.options.listStyle; this.content = this.controller.content; this.isSelected = false; this.seq = this.controller.attachments.length+1; this.actions = []; this.load(); }, load: function(){ this.node = new Element("div").inject(this.content); switch (this.controller.options.listStyle){ case "list": this.loadList(); break; case "icon": this.loadIcon(); break; case "preview": this.loadPreview(); break; case "sequence": this.loadSequence(); break; } this.setEvent(); this.loadMessage(); }, loadMessage: function(){ var size = this.node.getSize(); this.node.setStyle("position", "relative"); this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node); this.messageMaskNode.setStyles({ "width": ""+size.x+"px", "height": ""+size.y+"px" }); this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node); switch (this.controller.options.listStyle){ case "list": case "sequence": this.messageNode.setStyles({ "width": "0px", "height": ""+size.y+"px" }); break; case "icon": case "preview": this.messageNode.setStyles({ "width": ""+size.x+"px", "height": ""+size.y+"px" }); break; } this.messageText = new Element("div", { "styles": this.css.messageText, "text": "0%" }).inject(this.node); this.messageText.setStyles({ "width": ""+size.x+"px", "height": ""+size.y+"px", "line-height": ""+size.y+"px" }); }, updateProgress: function(percent){ var size = this.node.getSize(); switch (this.controller.options.listStyle){ case "list": case "sequence": var w = size.x*(percent/100); this.messageNode.setStyles({ "width":""+w+"px" }); break; case "icon": case "preview": var h = size.y*(1-percent/100); this.messageNode.setStyle("height", ""+h+"px"); break; } var p = (percent*100).toInt()/100; this.messageText.set("text", ""+p+"%") }, transferComplete: function(){ this.messageText.set("text", "loading...") } }); o2.widget.AttachmentController.AttachmentMessageMin = new Class({ Extends: o2.widget.AttachmentController.AttachmentMin, Implements: [Events], initialize: function(file, controller){ var d = (new Date).format("db"); var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length); this.file = file; this.data = { activity: "", activityName: "", activityToken: "", activityType: "manual", application: "", completed: false, control: {allowRead:true, allowEdit:false, allowControl:false}, controllerIdentityList: [], controllerUnitList: [], createTime: d, deepPath: false, divisionList: [], editIdentityList: [], editUnitList: [], extension: extension, id: (new o2.widget.UUID()).toString(), job: "", lastUpdatePerson: (layout) ? layout.session.user.name : "", lastUpdateTime: d, length: file.size, name: file.name, person: (layout) ? layout.session.user.name : "", process: "", readIdentityList: [], readUnitList: [], site: "$doc", storage: file.size, type: "", updateTime: d, workCreateTime: "" } if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid; this.controller = controller; this.css = this.controller.css; this.listStyle = this.controller.options.listStyle; this.content = this.controller.minContent; this.isSelected = false; this.seq = this.controller.attachments.length+1; this.actions = []; this.load(); }, load: function(){ this.node = new Element("div").inject(this.content); switch (this.controller.options.listStyle){ case "list": this.loadList(); break; case "icon": this.loadIcon(); break; case "preview": this.loadPreview(); break; case "sequence": this.loadSequence(); break; } this.setEvent(); this.loadMessage(); }, loadMessage: function(){ var size = this.node.getSize(); this.node.setStyle("position", "relative"); this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node); this.messageMaskNode.setStyles({ "width": ""+size.x+"px", "height": ""+size.y+"px" }); this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node); switch (this.controller.options.listStyle){ case "list": case "sequence": this.messageNode.setStyles({ "width": "0px", "height": ""+size.y+"px" }); break; case "icon": case "preview": this.messageNode.setStyles({ "width": ""+size.x+"px", "height": ""+size.y+"px" }); break; } this.messageText = new Element("div", { "styles": this.css.messageText, "text": "0%" }).inject(this.node); this.messageText.setStyles({ "width": ""+size.x+"px", "height": ""+size.y+"px", "line-height": ""+size.y+"px" }); }, updateProgress: function(percent){ var size = this.node.getSize(); switch (this.controller.options.listStyle){ case "list": case "sequence": var w = size.x*(percent/100); this.messageNode.setStyles({ "width":""+w+"px" }); break; case "icon": case "preview": var h = size.y*(1-percent/100); this.messageNode.setStyle("height", ""+h+"px"); break; } var p = (percent*100).toInt()/100; this.messageText.set("text", ""+p+"%") }, transferComplete: function(){ this.messageText.set("text", "loading...") } });