TaskAttachmentList.js 18 KB

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