AttachmentController.js 13 KB

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