TaskAttachmentList.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. MWF.xApplication.TeamWork = MWF.xApplication.TeamWork || {};
  2. MWF.xDesktop.requireApp("TeamWork", "Common", null, false);
  3. MWF.xApplication.TeamWork.TaskAttachmentList = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function (explorer, container, data, options) {
  10. this.setOptions(options);
  11. this.container = container;
  12. this.explorer = explorer;
  13. this.app = explorer.app;
  14. this.lp = this.app.lp.taskAttachmentList;
  15. this.rootActions = this.app.rootActions;
  16. this.actions = this.rootActions.AttachmentAction;
  17. this.path = "/x_component_TeamWork/$TaskAttachmentList/";
  18. this.cssPath = this.path+this.options.style+"/css.wcss";
  19. this._loadCss();
  20. this.data = data;
  21. },
  22. load: function () {
  23. this.container.empty();
  24. this.titleContent = new Element("div.titleContent",{styles:this.css.titleContent}).inject(this.container);
  25. this.titleIcon = new Element("div.titleIcon",{styles:this.css.titleIcon}).inject(this.titleContent);
  26. this.titleText = new Element("div.titleText",{styles:this.css.titleText,text:this.lp.attachment}).inject(this.titleContent);
  27. this.valueContent = new Element("div.valueContent",{styles:this.css.valueContent}).inject(this.container);
  28. this.attachmentListContainer = new Element("div.attachmentListContainer",{styles:this.css.attachmentListContainer}).inject(this.valueContent);
  29. this.listAttachment( function( json ){
  30. json.data.each(function (att) {
  31. this.loadAttachmentItem(att);
  32. }.bind(this));
  33. }.bind(this));
  34. this.addContainer = new Element("div.addContainer",{styles:this.css.addContainer}).inject(this.valueContent);
  35. this.addIcon = new Element("div.addIcon",{styles:this.css.addIcon}).inject(this.addContainer);
  36. this.addText = new Element("div.addText",{styles:this.css.addText,text:this.lp.attachmentAdd}).inject(this.addContainer);
  37. this.addContainer.addEvents({
  38. click:function(){
  39. this.uploadAttachment()
  40. }.bind(this)
  41. });
  42. },
  43. loadAttachmentItem:function(att){
  44. var attachmentItem = new Element("div.attachmentItem",{styles:this.css.attachmentItem}).inject(this.attachmentListContainer);
  45. attachmentItem.set("id",att.id);
  46. attachmentItem.addEvents({
  47. mouseover:function(){
  48. this.setStyles({"background-color":"#f5f5f5","cursor":"pointer"});
  49. },
  50. mouseout:function(){
  51. this.setStyles({"background-color":"","cursor":"default"});
  52. },
  53. click:function(){
  54. this.downloadAttachment(att)
  55. }.bind(this)
  56. });
  57. var attachmentIcon = new Element("div.attachmentIcon",{styles:this.css.attachmentIcon}).inject(attachmentItem);
  58. var bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_unknow.png)";
  59. var ex = att.extension.toLowerCase();
  60. if(ex == "zip" || ex == "rar" || ex == "7z"){
  61. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_zip.png)"
  62. }else if(ex == "xls" || ex == "xlsx"){
  63. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_excel.png)"
  64. }else if(ex == "doc" || ex == "docx"){
  65. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_word.png)"
  66. }else if(ex == "ppt" || ex == "pptx"){
  67. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_ppt.png)"
  68. }else if(ex == "pdf"){
  69. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_pdf.png)"
  70. }else if(ex == "png" || ex == "jpg" || ex == "jpeg" || ex == "bmp" || ex == "gif"){
  71. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_image.png)"
  72. }else if(ex == "mp3"){
  73. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_mp3.png)"
  74. }else if(ex == "mp4"){
  75. bgicon = "url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_mp4.png)"
  76. }
  77. attachmentIcon.setStyles({"background-image":bgicon});
  78. var attachmentName = new Element("div.attachmentName",{styles:this.css.attachmentName,text:att.name}).inject(attachmentItem);
  79. var attachmentSize = new Element("div.attachmentSize",{styles:this.css.attachmentSize}).inject(attachmentItem);
  80. var size = att.length.toFloat();
  81. if(size<1024) size = "1k";
  82. else if(size<1024*1024) size = Math.floor(size/1024) + "K";
  83. else if(size<1024*1024*1024) size = Math.floor(size/1024/1024) + "MB";
  84. attachmentSize.set("text",size);
  85. var attachmentMore = new Element("div.attachmentMore",{styles:this.css.attachmentMore}).inject(attachmentItem);
  86. attachmentMore.addEvents({
  87. mouseover:function(){
  88. this.setStyles({"background-color":"#ecf6fe","background-image":"url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_down_click.png)"})
  89. },
  90. mouseout:function(){
  91. this.setStyles({"background-color":"","background-image":"url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_down.png)"})
  92. },
  93. click:function(e){
  94. var data = {
  95. explorer:this
  96. };
  97. data.data = att;
  98. var tm = new MWF.xApplication.TeamWork.TaskAttachmentList.More(this.app.content, attachmentMore, this.app, data, {
  99. css:this.css, lp:this.lp, axis : "y",
  100. position : { //node 固定的位置
  101. x : "auto",
  102. y : "middle"
  103. },
  104. nodeStyles : {
  105. "min-width":"150px",
  106. "padding":"2px",
  107. "border-radius":"5px",
  108. "box-shadow":"0px 0px 4px 0px #999999",
  109. "z-index" : "201"
  110. },
  111. onPostLoad:function(){
  112. tm.node.setStyles({"opacity":"0","top":(tm.node.getStyle("top").toInt()+4)+"px"});
  113. var fx = new Fx.Tween(tm.node,{duration:400});
  114. fx.start(["opacity"] ,"0", "1");
  115. },
  116. onClose:function(rd){
  117. if(!rd) return;
  118. if(rd.act == "remove"){
  119. this.close(rd);
  120. if(this.data.projectObj){ //reload project
  121. this.data.projectObj.createTaskGroup()
  122. }
  123. }
  124. }.bind(this)
  125. },null,this);
  126. tm.load();
  127. e.stopPropagation()
  128. }.bind(this)
  129. })
  130. },
  131. createUploadFileNode: function () {
  132. this.uploadFileAreaNode = new Element("div");
  133. var html = "<input name=\"file\" type=\"file\" multiple/>";
  134. this.uploadFileAreaNode.set("html", html);
  135. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  136. this.fileUploadNode.addEvent("change", function () {
  137. this.isQueryUploadSuccess = true;
  138. this.fireEvent( "queryUploadAttachment" );
  139. if( this.isQueryUploadSuccess ){
  140. var files = this.fileUploadNode.files;
  141. if (files.length) {
  142. for (var i = 0; i < files.length; i++) {
  143. var file = files.item(i);
  144. var formData = new FormData();
  145. formData.append('file', file);
  146. formData.append('site', this.data.id);
  147. this.actions.taskAttachmentUpload(this.data.id,this.data.id,formData,file,function(json){
  148. if(json.type=="success"){
  149. if(json.id){
  150. this.actions.get(json.id, function (json) {
  151. json = this.transportData(json);
  152. if (json.data) {
  153. //this.load();
  154. this.getAttachment(json.data.id,function(json){
  155. //alert(JSON.stringify(json))
  156. this.loadAttachmentItem(json)
  157. }.bind(this))
  158. }
  159. this.fireEvent("upload", [json.data]);
  160. }.bind(this))
  161. }
  162. if(json.data.dynamics){
  163. json.data.dynamics.each(function(dd){
  164. this.explorer.loadDynamicItem(dd,"bottom");
  165. }.bind(this));
  166. this.explorer.dynamicContent.scrollTo(0,this.explorer.dynamicContent.getScrollSize().y);
  167. }
  168. }
  169. this.uploadFileAreaNode.destroy();
  170. this.uploadFileAreaNode = false;
  171. }.bind(this))
  172. // this.actions.attachmentTaskUpload(this.data.id, function (json) {
  173. // if(json.type=="success"){
  174. // if(json.id){
  175. // this.actions.attachmentGet(json.id, function (json) {
  176. // json = this.transportData(json);
  177. // if (json.data) {
  178. // //this.load();
  179. // this.getAttachment(json.data.id,function(json){
  180. // //alert(JSON.stringify(json))
  181. // this.loadAttachmentItem(json)
  182. // }.bind(this))
  183. // }
  184. //
  185. // this.fireEvent("upload", [json.data]);
  186. // }.bind(this))
  187. // }
  188. // if(json.data.dynamics){
  189. // json.data.dynamics.each(function(dd){
  190. // this.explorer.loadDynamicItem(dd,"bottom");
  191. // }.bind(this));
  192. // this.explorer.dynamicContent.scrollTo(0,this.explorer.dynamicContent.getScrollSize().y);
  193. // }
  194. // }
  195. // this.uploadFileAreaNode.destroy();
  196. // this.uploadFileAreaNode = false;
  197. // //this.attachmentController.checkActions();
  198. // }.bind(this), function(){alert("err")}, formData, file,this.data.id);
  199. }
  200. }
  201. }else{
  202. this.uploadFileAreaNode.destroy();
  203. this.uploadFileAreaNode = false;
  204. }
  205. }.bind(this));
  206. },
  207. uploadAttachment: function (e, node) {
  208. if (!this.uploadFileAreaNode) {
  209. this.createUploadFileNode();
  210. }
  211. this.fileUploadNode.click();
  212. },
  213. transportData : function( json ){
  214. if( typeOf(json.data) == "array" ){
  215. json.data.each(function(d){
  216. d.person = d.creatorUid;
  217. d.lastUpdateTime = d.updateTime;
  218. })
  219. }else if( typeOf(json.data) == "object" ){
  220. var d = json.data;
  221. d.person = d.creatorUid;
  222. d.lastUpdateTime = d.updateTime;
  223. }else{
  224. json.each(function(d){
  225. d.person = d.creatorUid;
  226. d.lastUpdateTime = d.updateTime;
  227. })
  228. }
  229. return json;
  230. },
  231. listAttachment: function( callback ){
  232. this.actions.listByTaskId(this.data.id, function(json){
  233. if(callback)callback(this.transportData(json));
  234. }.bind(this))
  235. },
  236. replaceAttachmentFile: function (attachment) {
  237. if (!this.replaceFileAreaNode) {
  238. this.createReplaceFileNode(attachment);
  239. }
  240. this.fileReplaceNode.click();
  241. },
  242. downloadAttachments: function (e, node, attachments) {
  243. attachments.each(function (att) {
  244. this.actions.attachmentDownloadStream(att.data.id, this.data.id);
  245. }.bind(this));
  246. },
  247. downloadAttachment: function (attachment) {
  248. this.actions.attachmentDownloadStream(attachment.id, this.data.id);
  249. },
  250. openAttachment: function (e, node, attachments) {
  251. attachments.each(function (att) {
  252. this.actions.attachmentDownloadStream(att.data.id, this.data.id);
  253. }.bind(this));
  254. },
  255. getAttachmentUrl: function (attachment, callback) {
  256. this.actions.attachmentDownloadUrl(attachment.id, this.data.id, callback);
  257. },
  258. getAttachment:function(id,callback){
  259. this.actions.get(id,function(json){
  260. if(json.type == "success"){
  261. if(callback)callback(json.data)
  262. }
  263. }.bind(this))
  264. },
  265. reload:function(){
  266. },
  267. test:function(){
  268. }
  269. });
  270. MWF.xApplication.TeamWork.TaskAttachmentList.More = new Class({
  271. Extends: MWF.xApplication.TeamWork.Common.ToolTips,
  272. options : {
  273. // displayDelay : 300,
  274. hasArrow:false,
  275. event:"click"
  276. },
  277. _loadCustom : function( callback ){
  278. var _self = this;
  279. this.css = this.options.css;
  280. this.lp = this.options.lp;
  281. this.explorer = this.data.explorer;
  282. this.data = this.data.data;
  283. this.rootActions = this.app.rootActions;
  284. //this.data
  285. //this.contentNode
  286. var topMoreTitle = new Element("div.topMoreTitle",{styles:this.css.topMoreTitle,text:this.lp.attachmentMenu}).inject(this.contentNode);
  287. // var details = new Element("div.details",{styles:this.css.topMoreItem}).inject(this.contentNode);
  288. // details.addEvents({
  289. // mouseenter:function(){this.setStyles({"background-color":"#F7F7F7"})},
  290. // mouseleave:function(){this.setStyles({"background-color":""})}
  291. // });
  292. // var detailsIcon = new Element("div.detailsIcon",{styles:this.css.topMoreItemIcon}).inject(details);
  293. // detailsIcon.setStyles({"background":"url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_details.png) no-repeat center"});
  294. // var detailsText = new Element("div.detailsText",{styles:this.css.topMoreItemText,text:this.lp.attachmentDetails}).inject(details);
  295. var download = new Element("div.download",{styles:this.css.topMoreItem}).inject(this.contentNode);
  296. download.addEvents({
  297. mouseenter:function(){this.setStyles({"background-color":"#F7F7F7"})},
  298. mouseleave:function(){this.setStyles({"background-color":""})},
  299. click:function(){
  300. this.downloadAttachment(this.data)
  301. }.bind(this)
  302. });
  303. var downloadIcon = new Element("div.downloadIcon",{styles:this.css.topMoreItemIcon}).inject(download);
  304. downloadIcon.setStyles({"background":"url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_download.png) no-repeat center"});
  305. var downloadText = new Element("div.downloadText",{styles:this.css.topMoreItemText,text:this.lp.attachmentDownload}).inject(download);
  306. var remove = new Element("div.remove",{styles:this.css.topMoreItem}).inject(this.contentNode);
  307. remove.addEvents({
  308. mouseenter:function(){this.setStyles({"background-color":"#F7F7F7"})},
  309. mouseleave:function(){this.setStyles({"background-color":""})},
  310. click:function(e){
  311. this.app.confirm("warn",e,_self.app.lp.common.confirm.removeTitle,_self.app.lp.common.confirm.removeContent,300,120,function(){
  312. _self.deleteAttachment(_self.data);
  313. this.close();
  314. },function(){
  315. this.close();
  316. });
  317. }.bind(this)
  318. });
  319. var removeIcon = new Element("div.removeIcon",{styles:this.css.topMoreItemIcon}).inject(remove);
  320. removeIcon.setStyles({"background":"url(/x_component_TeamWork/$TaskAttachmentList/default/icon/icon_remove.png) no-repeat center"});
  321. var removeText = new Element("div.removeText",{styles:this.css.topMoreItemText,text:this.lp.attachmentRemove}).inject(remove);
  322. if(callback)callback();
  323. },
  324. downloadAttachment: function (attachment) {debugger;
  325. var address = this.rootActions.AttachmentAction.action.address;
  326. var url = this.rootActions.AttachmentAction.action.actions.downLoad.uri;
  327. url = url.replace("{id}", encodeURIComponent(attachment.id));debugger;
  328. window.open(address+url)
  329. },
  330. deleteAttachment: function (attachment) {
  331. //this.actions.attachmentRemove(attachment.id, function (json) {
  332. this.rootActions.AttachmentAction.delete(attachment.id, function (json) {
  333. if(json.type == "success"){
  334. var dom = this.explorer.container.getElementById(json.data.id);
  335. if(dom) dom.destroy();
  336. }
  337. if(json.data.dynamics){
  338. json.data.dynamics.each(function(data){
  339. this.explorer.explorer.loadDynamicItem(data,"bottom");
  340. this.explorer.explorer.dynamicContent.scrollTo(0,this.explorer.explorer.dynamicContent.getScrollSize().y);
  341. }.bind(this))
  342. }
  343. this.close();
  344. }.bind(this));
  345. }
  346. });