AttachmentController.min.js 9.7 KB

1
  1. MWF.xDesktop.requireApp("File","Actions.RestActions",null,false);MWF.require("MWF.widget.AttachmentController",null,false);MWF.xApplication.File.AttachmentController=new Class({Extends:MWF.widget.AttachmentController,createTopNode:function(){this.topNode=new Element("div",{styles:this.css.topNode}).inject(this.node);this.createFolderGroupActions();this.createEditGroupActions();this.createReadGroupActions();this.createListGroupActions();this.createShareGroupActions();this.createViewGroupActions()},checkActions:function(){this.checkFolderAction();this.checkUploadAction();this.checkDeleteAction();this.checkReplaceAction();this.checkDownloadAction();this.checkSizeAction();this.checkShareAction();this.checkListStyleAction()},createFolderGroupActions:function(){this.folderActionBoxNode=new Element("div",{styles:this.css.actionsBoxNode}).inject(this.topNode);this.folderActionsGroupNode=new Element("div",{styles:this.css.actionsGroupNode}).inject(this.folderActionBoxNode);this.createFolderAction=this.createAction(this.folderActionsGroupNode,"createFolder",MWF.LP.widget.createFolder,function(){this.createFolder()}.bind(this));this.renameAction=this.createAction(this.folderActionsGroupNode,"rename",MWF.LP.widget.rename,function(){this.renameFolder()}.bind(this))},createShareGroupActions:function(){this.shareActionBoxNode=new Element("div",{styles:this.css.actionsBoxNode}).inject(this.topNode);this.shareActionsGroupNode=new Element("div",{styles:this.css.actionsGroupNode}).inject(this.shareActionBoxNode);this.shareAction=this.createAction(this.shareActionsGroupNode,"share",MWF.LP.widget.share,function(){this.shareAttachment()}.bind(this));this.sendAction=this.createAction(this.shareActionsGroupNode,"send",MWF.LP.widget.send,function(){this.sendAttachment()}.bind(this))},checkReplaceAction:function(){if(this.options.readonly){this.setActionDisabled(this.replaceAction);this.setActionDisabled(this.min_replaceAction);return false}if(!this.options.isReplace){this.setActionDisabled(this.replaceAction);this.setActionDisabled(this.min_replaceAction)}else{if(this.selectedAttachments.length&&this.selectedAttachments.length==1){if(this.selectedAttachments[0].type=="folder"){this.setActionDisabled(this.replaceAction);this.setActionDisabled(this.min_replaceAction)}else{this.setActionEnabled(this.replaceAction);this.setActionEnabled(this.min_replaceAction)}}else{this.setActionDisabled(this.replaceAction);this.setActionDisabled(this.min_replaceAction)}}},checkFolderAction:function(){if(this.selectedAttachments.length==1){this.setActionEnabled(this.renameAction)}else{this.setActionDisabled(this.renameAction)}},checkShareAction:function(){if(this.selectedAttachments.length){if(this.selectedAttachments.length==1&&this.selectedAttachments[0].type=="folder"){this.setActionDisabled(this.shareAction);this.setActionDisabled(this.sendAction)}else{this.setActionEnabled(this.shareAction);this.setActionEnabled(this.sendAction)}}else{this.setActionDisabled(this.shareAction);this.setActionDisabled(this.sendAction)}},addAttachment:function(t){if(this.options.size=="min"){this.attachments.push(new MWF.widget.AttachmentController.AttachmentMin(t,this))}else{this.attachments.push(new MWF.xApplication.File.AttachmentController.Attachment(t,this))}},addAttachmentFolder:function(t){var e=new MWF.xApplication.File.AttachmentController.Folder(t,this);this.attachments.push(e);return e},createFolder:function(t,e){if(this.module)this.module.createFolder(t,e)},renameFolder:function(t,e){if(this.module)this.module.renameFileFolder(t,e)},shareAttachment:function(){if(this.module)this.module.shareAttachment()},sendAttachment:function(){if(this.module)this.module.sendAttachment()}});MWF.xApplication.File.AttachmentController.Attachment=new Class({Extends:MWF.widget.AttachmentController.Attachment,createInforNode:function(t){var e="";var i=this.data.length/1204;if(i>1024){var s=i/1024;s=Math.round(s*100)/100;e=s+"M"}else{i=Math.round(i*100)/100;e=i+"K"}var o=this.data.shareList?this.data.shareList.map(function(t){return t.substring(0,t.indexOf("@"))}).join(","):"";var n=this.data.editorList?this.data.editorList.map(function(t){return t.substring(0,t.indexOf("@"))}).join(","):"";this.inforNode=new Element("div",{styles:this.css.attachmentInforNode});var d="<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";d+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.uploader+": </div><div style='width:120px; float:left; margin-left:10px'>"+MWF.name.cn(this.data.person)+"</div></div>";d+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.uploadTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.createTime+"</div></div>";d+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.modifyTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.lastUpdateTime+"</div></div>";d+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.size+": </div><div style='width:120px; float:left; margin-left:10px'>"+e+"</div></div>";d+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.share+": </div><div style='width:120px; float:left; margin-left:10px'>"+o+"</div></div>";d+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.send+": </div><div style='width:120px; float:left; margin-left:10px'>"+n+"</div></div>";this.inforNode.set("html",d);if(t)t()},custom_Preview:function(){var t=this.data.shareList?this.data.shareList.join(","):"";var e=this.data.editorList?this.data.editorList.join(","):"";if(t||e){var i=new Element("div",{styles:{width:"24px",height:"24px",background:"url("+"/x_component_File/$Main/default/icon/share_flag_preview.png) center center no-repeat",position:"relative",top:"-28px"}}).inject(this.iconImgAreaNode)}},custom_Icon:function(){var t=this.data.shareList?this.data.shareList.join(","):"";var e=this.data.editorList?this.data.editorList.join(","):"";if(t||e){var i=new Element("div",{styles:{width:"16px",height:"16px",background:"url("+"/x_component_File/$Main/default/icon/share_flag_icon.png) center center no-repeat",position:"relative",top:"-18px"}}).inject(this.iconImgAreaNode)}},custom_List:function(){var t=this.data.shareList?this.data.shareList.join(","):"";var e=this.data.editorList?this.data.editorList.join(","):"";if(t||e){var i=new Element("div",{styles:{width:"10px",height:"10px",background:"url("+"/x_component_File/$Main/default/icon/share_flag_list.png) center center no-repeat",position:"relative",top:"-14px"}}).inject(this.iconImgAreaNode)}}});MWF.xApplication.File.AttachmentController.Folder=new Class({Extends:MWF.widget.AttachmentController.Attachment,initialize:function(t,e){this.data=t;this.controller=e;this.css=this.controller.css;this.listStyle=this.controller.options.listStyle;this.content=this.controller.content;this.isSelected=false;this.type="folder";this.load()},getIcon:function(){return"/x_component_File/$Main/default/file/folder.png"},createInforNode:function(t){var e="";var i=this.data.size/1204;if(i>1024){var s=i/1024;s=Math.round(s*100)/100;e=s+"M"}else{i=Math.round(i*100)/100;e=i+"K"}this.inforNode=new Element("div",{styles:this.css.attachmentInforNode});var o="<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";o+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.attCount+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.attachmentCount+"</div></div>";o+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.folderCount+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.folderCount+"</div></div>";o+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.uploadTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.createTime+"</div></div>";o+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.modifyTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.updateTime+"</div></div>";o+="<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+MWF.LP.widget.size+": </div><div style='width:120px; float:left; margin-left:10px'>"+e+"</div></div>";this.inforNode.set("html",o);if(t)t()},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 t=this.getIcon();this.iconImgNode.set({src:t,border:0});this.textNode=new Element("div",{styles:this.css.attachmentPreviewTextNode}).inject(this.node);this.textNode.set("text",this.data.name)},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(t){this.selected(t)}.bind(this),dblclick:function(t){this.openFolder(t)}.bind(this)})},openFolder:function(){this.treeNode.clickNode()}});