AttachmentController.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. MWF.xDesktop.requireApp("File", "Actions.RestActions", null, false);
  2. MWF.require("MWF.widget.AttachmentController", null, false);
  3. MWF.xApplication.File.AttachmentController = new Class({
  4. Extends: MWF.widget.AttachmentController,
  5. createTopNode: function(){
  6. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  7. this.createFolderGroupActions();
  8. this.createEditGroupActions();
  9. this.createReadGroupActions();
  10. this.createListGroupActions();
  11. this.createShareGroupActions();
  12. this.createViewGroupActions();
  13. },
  14. checkActions: function(){
  15. this.checkFolderAction();
  16. this.checkUploadAction();
  17. this.checkDeleteAction();
  18. this.checkReplaceAction();
  19. this.checkDownloadAction();
  20. this.checkSizeAction();
  21. this.checkShareAction();
  22. this.checkListStyleAction();
  23. },
  24. createFolderGroupActions: function(){
  25. this.folderActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  26. this.folderActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.folderActionBoxNode);
  27. this.createFolderAction = this.createAction(this.folderActionsGroupNode, "createFolder", MWF.LP.widget.createFolder, function(){
  28. this.createFolder();
  29. }.bind(this));
  30. this.renameAction = this.createAction(this.folderActionsGroupNode, "rename", MWF.LP.widget.rename, function(){
  31. this.renameFolder();
  32. }.bind(this));
  33. },
  34. createShareGroupActions: function(){
  35. this.shareActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  36. this.shareActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.shareActionBoxNode);
  37. this.shareAction = this.createAction(this.shareActionsGroupNode, "share", MWF.LP.widget.share, function(){
  38. this.shareAttachment();
  39. }.bind(this));
  40. this.sendAction = this.createAction(this.shareActionsGroupNode, "send", MWF.LP.widget.send, function(){
  41. this.sendAttachment();
  42. }.bind(this));
  43. // this.createSeparate(this.shareActionsGroupNode);
  44. // this.propertyAction = this.createAction(this.shareActionsGroupNode, "property", MWF.LP.widget.property, function(){
  45. // this.showProperty();
  46. // }.bind(this));
  47. //property
  48. },
  49. checkReplaceAction: function(){
  50. if (this.options.readonly){
  51. this.setActionDisabled(this.replaceAction);
  52. this.setActionDisabled(this.min_replaceAction);
  53. return false;
  54. }
  55. if (!this.options.isReplace){
  56. this.setActionDisabled(this.replaceAction);
  57. this.setActionDisabled(this.min_replaceAction);
  58. }else{
  59. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  60. if (this.selectedAttachments[0].type=="folder"){
  61. this.setActionDisabled(this.replaceAction);
  62. this.setActionDisabled(this.min_replaceAction);
  63. }else{
  64. this.setActionEnabled(this.replaceAction);
  65. this.setActionEnabled(this.min_replaceAction);
  66. }
  67. }else{
  68. this.setActionDisabled(this.replaceAction);
  69. this.setActionDisabled(this.min_replaceAction);
  70. }
  71. }
  72. },
  73. checkFolderAction: function(){
  74. if (this.selectedAttachments.length==1){
  75. // if (this.selectedAttachments[0].type=="folder"){
  76. this.setActionEnabled(this.renameAction);
  77. // }else{
  78. // this.setActionDisabled(this.renameAction);
  79. // }
  80. }else{
  81. this.setActionDisabled(this.renameAction);
  82. }
  83. },
  84. checkShareAction: function(){
  85. if (this.selectedAttachments.length){
  86. if (this.selectedAttachments.length==1 && this.selectedAttachments[0].type=="folder"){
  87. this.setActionDisabled(this.shareAction);
  88. this.setActionDisabled(this.sendAction);
  89. }else{
  90. this.setActionEnabled(this.shareAction);
  91. this.setActionEnabled(this.sendAction);
  92. }
  93. // if (this.selectedAttachments.length===1){
  94. // this.setActionEnabled(this.propertyAction);
  95. // }else{
  96. // this.setActionDisabled(this.propertyAction);
  97. // }
  98. }else{
  99. this.setActionDisabled(this.shareAction);
  100. this.setActionDisabled(this.sendAction);
  101. //this.setActionDisabled(this.propertyAction);
  102. }
  103. },
  104. addAttachment: function(data){
  105. if (this.options.size=="min"){
  106. this.attachments.push(new MWF.widget.AttachmentController.AttachmentMin(data, this));
  107. }else{
  108. this.attachments.push(new MWF.xApplication.File.AttachmentController.Attachment(data, this));
  109. }
  110. },
  111. addAttachmentFolder: function(data){
  112. var folder = new MWF.xApplication.File.AttachmentController.Folder(data, this);
  113. this.attachments.push(folder);
  114. return folder;
  115. },
  116. createFolder: function(e, node){
  117. if (this.module) this.module.createFolder(e, node);
  118. },
  119. renameFolder: function(e, node){
  120. if (this.module) this.module.renameFileFolder(e, node);
  121. },
  122. shareAttachment: function(){
  123. if (this.module) this.module.shareAttachment();
  124. },
  125. sendAttachment: function(){
  126. if (this.module) this.module.sendAttachment();
  127. }
  128. });
  129. MWF.xApplication.File.AttachmentController.Attachment = new Class({
  130. Extends: MWF.widget.AttachmentController.Attachment,
  131. createInforNode: function(callback){
  132. var size = "";
  133. var k = this.data.length/1204;
  134. if (k>1024){
  135. var m = k/1024;
  136. m = Math.round(m*100)/100;
  137. size = m+"M";
  138. }else{
  139. k = Math.round(k*100)/100;
  140. size = k+"K";
  141. }
  142. var shareList = (this.data.shareList) ? this.data.shareList.map(function(item){return item.substring(0, item.indexOf("@"));}).join(",") : "";
  143. var editorList = (this.data.editorList) ? this.data.editorList.map(function(item){return item.substring(0, item.indexOf("@"));}).join(",") : "";
  144. this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
  145. var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
  146. html += "<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>";
  147. html += "<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>";
  148. html += "<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>";
  149. html += "<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'>"+size+"</div></div>";
  150. html += "<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'>"+shareList+"</div></div>";
  151. html += "<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'>"+editorList+"</div></div>";
  152. this.inforNode.set("html", html);
  153. if (callback) callback();
  154. },
  155. custom_Preview: function(){
  156. var shareList = (this.data.shareList) ? this.data.shareList.join(",") : "";
  157. var sendList = (this.data.editorList) ? this.data.editorList.join(",") : "";
  158. if (shareList || sendList){
  159. var flagNode = new Element("div", {
  160. "styles": {
  161. "width": "24px",
  162. "height": "24px",
  163. "background": "url("+"../x_component_File/$Main/default/icon/share_flag_preview.png) center center no-repeat",
  164. "position": "relative",
  165. "top": "-28px"
  166. }
  167. }).inject(this.iconImgAreaNode);
  168. }
  169. },
  170. custom_Icon: function(){
  171. var shareList = (this.data.shareList) ? this.data.shareList.join(",") : "";
  172. var sendList = (this.data.editorList) ? this.data.editorList.join(",") : "";
  173. if (shareList || sendList){
  174. var flagNode = new Element("div", {
  175. "styles": {
  176. "width": "16px",
  177. "height": "16px",
  178. "background": "url("+"../x_component_File/$Main/default/icon/share_flag_icon.png) center center no-repeat",
  179. "position": "relative",
  180. "top": "-18px"
  181. }
  182. }).inject(this.iconImgAreaNode);
  183. }
  184. },
  185. custom_List: function(){
  186. var shareList = (this.data.shareList) ? this.data.shareList.join(",") : "";
  187. var sendList = (this.data.editorList) ? this.data.editorList.join(",") : "";
  188. if (shareList || sendList){
  189. var flagNode = new Element("div", {
  190. "styles": {
  191. "width": "10px",
  192. "height": "10px",
  193. "background": "url("+"../x_component_File/$Main/default/icon/share_flag_list.png) center center no-repeat",
  194. "position": "relative",
  195. "top": "-14px"
  196. }
  197. }).inject(this.iconImgAreaNode);
  198. }
  199. }
  200. });
  201. MWF.xApplication.File.AttachmentController.Folder = new Class({
  202. Extends: MWF.widget.AttachmentController.Attachment,
  203. initialize: function(data, controller){
  204. this.data = data;
  205. this.controller = controller;
  206. this.css = this.controller.css;
  207. this.listStyle = this.controller.options.listStyle;
  208. this.content = this.controller.content;
  209. this.isSelected = false;
  210. this.type = "folder";
  211. this.load();
  212. },
  213. getIcon: function(){
  214. //if (!this.data.extension) this.data.extension="unkonw";
  215. //var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow;
  216. return "../x_component_File/$Main/default/file/folder.png";
  217. },
  218. createInforNode: function(callback){
  219. var size = "";
  220. var k = this.data.size/1204;
  221. if (k>1024){
  222. var m = k/1024;
  223. m = Math.round(m*100)/100;
  224. size = m+"M";
  225. }else{
  226. k = Math.round(k*100)/100;
  227. size = k+"K";
  228. }
  229. // this.controller.module.restActions.listComplex(function(json){
  230. // var attCount = json.data.attachmentList.length;
  231. // var folderCount = json.data.folderList.length;
  232. this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
  233. var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
  234. html += "<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>";
  235. html += "<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>";
  236. html += "<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>";
  237. html += "<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>";
  238. html += "<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'>"+size+"</div></div>";
  239. this.inforNode.set("html", html);
  240. if (callback) callback();
  241. // }.bind(this), null, this.data.id);
  242. },
  243. loadPreview: function(){
  244. this.node.setStyles(this.css.attachmentNode_preview);
  245. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_preview_selected);
  246. this.iconNode = new Element("div", {"styles": this.css.attachmentPreviewIconNode}).inject(this.node);
  247. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentPreviewIconImgAreaNode}).inject(this.iconNode);
  248. this.iconImgNode = new Element("img", {"styles": this.css.attachmentPreviewIconImgNode}).inject(this.iconImgAreaNode);
  249. var icon = this.getIcon();
  250. this.iconImgNode.set({"src": icon, "border": 0});
  251. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  252. this.textNode.set("text", this.data.name);
  253. },
  254. setEvent: function(){
  255. this.node.addEvents({
  256. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"])}.bind(this),
  257. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle])}.bind(this),
  258. "mousedown": function(e){this.selected(e);}.bind(this),
  259. "dblclick": function(e){this.openFolder(e);}.bind(this)
  260. });
  261. },
  262. openFolder: function(){
  263. this.treeNode.clickNode();
  264. }
  265. });