AttachmentController.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. loadList: function(){
  132. this.node.setStyles(this.css.attachmentNode_list);
  133. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_list_selected);
  134. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
  135. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
  136. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  137. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  138. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_list}).inject(this.node);
  139. this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
  140. this.textTitleNode.set("text", this.data.name);
  141. var size = "";
  142. var k = this.data.length/1024;
  143. if (k>1024){
  144. var m = k/1024;
  145. m = Math.round(m*100)/100;
  146. size = m+"M";
  147. }else{
  148. k = Math.round(k*100)/100;
  149. size = k+"K";
  150. }
  151. this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
  152. this.textSizeNode.set("text", size);
  153. this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
  154. this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid ));
  155. this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
  156. this.textTimeNode.set("text", this.data.lastUpdateTime);
  157. // this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  158. // this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
  159. this.extensionNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  160. this.extensionNode.set("text", this.data.extension || o2.LP.widget.unknow);
  161. this.custom_List();
  162. },
  163. loadSequence: function(){
  164. this.node.setStyles(this.css.attachmentNode_sequence);
  165. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_sequence_selected);
  166. this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
  167. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
  168. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
  169. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  170. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  171. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_sequence}).inject(this.node);
  172. this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
  173. this.textTitleNode.set("text", this.data.name);
  174. var size = "";
  175. var k = this.data.length/1024;
  176. if (k>1024){
  177. var m = k/1024;
  178. m = Math.round(m*100)/100;
  179. size = m+"M";
  180. }else{
  181. k = Math.round(k*100)/100;
  182. size = k+"K";
  183. }
  184. this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
  185. this.textSizeNode.set("text", size);
  186. this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
  187. this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid));
  188. this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
  189. this.textTimeNode.set("text", this.data.lastUpdateTime);
  190. // this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  191. // this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
  192. this.extensionNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  193. this.extensionNode.set("text", this.data.extension || o2.LP.widget.unknow);
  194. this.custom_Sequence();
  195. },
  196. createInforNode: function(callback){
  197. var size = "";
  198. var k = this.data.length/1024;
  199. if (k>1024){
  200. var m = k/1024;
  201. m = Math.round(m*100)/100;
  202. size = m+"M";
  203. }else{
  204. k = Math.round(k*100)/100;
  205. size = k+"K";
  206. }
  207. var shareList = (this.data.shareList) ? this.data.shareList.map(function(item){return item.substring(0, item.indexOf("@"));}).join(",") : "";
  208. var editorList = (this.data.editorList) ? this.data.editorList.map(function(item){return item.substring(0, item.indexOf("@"));}).join(",") : "";
  209. this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
  210. var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
  211. 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>";
  212. 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>";
  213. 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>";
  214. 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>";
  215. 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>";
  216. 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>";
  217. this.inforNode.set("html", html);
  218. if (callback) callback();
  219. },
  220. custom_Preview: function(){
  221. var shareList = (this.data.shareList) ? this.data.shareList.join(",") : "";
  222. var sendList = (this.data.editorList) ? this.data.editorList.join(",") : "";
  223. if (shareList || sendList){
  224. var flagNode = new Element("div", {
  225. "styles": {
  226. "width": "24px",
  227. "height": "24px",
  228. "background": "url("+"../x_component_File/$Main/default/icon/share_flag_preview.png) center center no-repeat",
  229. "position": "relative",
  230. "top": "-28px"
  231. }
  232. }).inject(this.iconImgAreaNode);
  233. }
  234. },
  235. custom_Icon: function(){
  236. var shareList = (this.data.shareList) ? this.data.shareList.join(",") : "";
  237. var sendList = (this.data.editorList) ? this.data.editorList.join(",") : "";
  238. if (shareList || sendList){
  239. var flagNode = new Element("div", {
  240. "styles": {
  241. "width": "16px",
  242. "height": "16px",
  243. "background": "url("+"../x_component_File/$Main/default/icon/share_flag_icon.png) center center no-repeat",
  244. "position": "relative",
  245. "top": "-18px"
  246. }
  247. }).inject(this.iconImgAreaNode);
  248. }
  249. },
  250. custom_List: function(){
  251. var shareList = (this.data.shareList) ? this.data.shareList.join(",") : "";
  252. var sendList = (this.data.editorList) ? this.data.editorList.join(",") : "";
  253. if (shareList || sendList){
  254. var flagNode = new Element("div", {
  255. "styles": {
  256. "width": "10px",
  257. "height": "10px",
  258. "background": "url("+"../x_component_File/$Main/default/icon/share_flag_list.png) center center no-repeat",
  259. "position": "relative",
  260. "top": "-14px"
  261. }
  262. }).inject(this.iconImgAreaNode);
  263. }
  264. }
  265. });
  266. MWF.xApplication.File.AttachmentController.Folder = new Class({
  267. Extends: MWF.widget.AttachmentController.Attachment,
  268. initialize: function(data, controller){
  269. this.data = data;
  270. this.controller = controller;
  271. this.css = this.controller.css;
  272. this.listStyle = this.controller.options.listStyle;
  273. this.content = this.controller.content;
  274. this.isSelected = false;
  275. this.type = "folder";
  276. this.load();
  277. },
  278. getIcon: function(){
  279. //if (!this.data.extension) this.data.extension="unkonw";
  280. //var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow;
  281. return "../x_component_File/$Main/default/file/folder.png";
  282. },
  283. createInforNode: function(callback){
  284. var size = "";
  285. var k = this.data.size/1024;
  286. if (k>1024){
  287. var m = k/1024;
  288. m = Math.round(m*100)/100;
  289. size = m+"M";
  290. }else{
  291. k = Math.round(k*100)/100;
  292. size = k+"K";
  293. }
  294. // this.controller.module.restActions.listComplex(function(json){
  295. // var attCount = json.data.attachmentList.length;
  296. // var folderCount = json.data.folderList.length;
  297. this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
  298. var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
  299. 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>";
  300. 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>";
  301. 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>";
  302. 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>";
  303. 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>";
  304. this.inforNode.set("html", html);
  305. if (callback) callback();
  306. // }.bind(this), null, this.data.id);
  307. },
  308. loadPreview: function(){
  309. this.node.setStyles(this.css.attachmentNode_preview);
  310. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_preview_selected);
  311. this.iconNode = new Element("div", {"styles": this.css.attachmentPreviewIconNode}).inject(this.node);
  312. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentPreviewIconImgAreaNode}).inject(this.iconNode);
  313. this.iconImgNode = new Element("img", {"styles": this.css.attachmentPreviewIconImgNode}).inject(this.iconImgAreaNode);
  314. var icon = this.getIcon();
  315. this.iconImgNode.set({"src": icon, "border": 0});
  316. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  317. this.textNode.set("text", this.data.name);
  318. },
  319. setEvent: function(){
  320. this.node.addEvents({
  321. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"])}.bind(this),
  322. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle])}.bind(this),
  323. "mousedown": function(e){this.selected(e);}.bind(this),
  324. "dblclick": function(e){this.openFolder(e);}.bind(this)
  325. });
  326. },
  327. openFolder: function(){
  328. this.treeNode.clickNode();
  329. }
  330. });