TaskAttachmentList.js 16 KB

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