Main.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. //MWF.xDesktop.requireApp("File", "Actions.RestActions", null, false);
  2. MWF.xDesktop.requireApp("File", "AttachmentController", null, false);
  3. MWF.require("MWF.widget.Tree", null, false);
  4. MWF.xApplication.File.Main = new Class({
  5. Extends: MWF.xApplication.Common.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "File",
  10. "icon": "icon.png",
  11. "width": "1000",
  12. "height": "600",
  13. "title": MWF.xApplication.File.LP.title
  14. },
  15. onQueryLoad: function(){
  16. this.lp = MWF.xApplication.File.LP;
  17. this.restActions = MWF.Actions.get("x_file_assemble_control");
  18. },
  19. loadApplication: function(callback){
  20. this.history = [];
  21. this.currentHistory = 1;
  22. this.currentFolder = null;
  23. //this.restActions = new MWF.xApplication.File.Actions.RestActions();
  24. MWF.getJSON("../x_component_File/$Main/icon.json", function(json){
  25. this.icons = json;
  26. }.bind(this), false, false);
  27. this.createNode();
  28. this.loadApplicationContent();
  29. if (callback) callback();
  30. },
  31. createNode: function(){
  32. this.content.setStyle("overflow", "hidden");
  33. this.node = new Element("div", {
  34. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  35. }).inject(this.content);
  36. },
  37. loadApplicationContent: function(){
  38. this.loadTop();
  39. // this.loadTools();
  40. this.fileContentNode = new Element("div", {"styles": this.css.fileContentNode}).inject(this.node);
  41. this.folderContentNode = new Element("div", {"styles": this.css.folderContentNode}).inject(this.fileContentNode);
  42. this.attachmentContentNode = new Element("div", {"styles": this.css.attachmentContentNode}).inject(this.fileContentNode);
  43. this.resizeContentNode = new Element("div", {"styles": this.css.resizeContentNode}).inject(this.folderContentNode);
  44. this.folderTreeAreaNode = new Element("div", {
  45. "styles": this.css.folderTreeAreaNode
  46. }).inject(this.folderContentNode);
  47. this.folderTreeAreaScrollNode = new Element("div", {
  48. "styles": this.css.folderTreeAreaScrollNode
  49. }).inject(this.folderContentNode);
  50. this.shareTreeAreaScrollNode = new Element("div", {
  51. "styles": this.css.folderTreeAreaScrollNode
  52. }).inject(this.folderContentNode);
  53. this.editorTreeAreaScrollNode = new Element("div", {
  54. "styles": this.css.folderTreeAreaScrollNode
  55. }).inject(this.folderContentNode);
  56. this.loadFileContentAreaNode();
  57. this.loadFolderTreeNode();
  58. this.loadShareTreeNode();
  59. this.loadEditorTreeNode();
  60. this.shareTree.loadCallback = function(){
  61. if (this.shareTab.isShow){
  62. if (this.status){
  63. if (this.status.node){
  64. var found = false;
  65. for (var i=0; i<this.shareTree.children.length; i++){
  66. if (this.shareTree.children[i].data.name == this.status.node){
  67. this.shareTree.children[i].clickNode();
  68. found = true;
  69. break;
  70. }
  71. }
  72. if (!found) this.shareTree.firstChild.clickNode();
  73. }else{
  74. this.shareTree.firstChild.clickNode();
  75. }
  76. }else{
  77. this.shareTree.firstChild.clickNode();
  78. }
  79. }
  80. };
  81. this.editorTree.loadCallback = function(){
  82. if (this.editorTab.isShow){
  83. if (this.status){
  84. if (this.status.node){
  85. var found = false;
  86. for (var i=0; i<this.editorTree.children.length; i++){
  87. if (this.editorTree.children[i].data.name == this.status.node){
  88. this.editorTree.children[i].clickNode();
  89. found = true;
  90. break;
  91. }
  92. }
  93. if (!found) this.editorTree.firstChild.clickNode();
  94. }else{
  95. this.editorTree.firstChild.clickNode();
  96. }
  97. }else{
  98. this.editorTree.firstChild.clickNode();
  99. }
  100. }
  101. }
  102. this.treeResize = new Drag(this.resizeContentNode,{
  103. "snap": 1,
  104. "onStart": function(el, e){
  105. //alert(e.event.clientX);
  106. var x = e.event.clientX;
  107. var y = e.event.clientY;
  108. el.store("position", {"x": x, "y": y});
  109. var size = this.folderContentNode.getSize();
  110. el.store("initialWidth", size.x);
  111. }.bind(this),
  112. "onDrag": function(el, e){
  113. var x = e.event.clientX;
  114. // var y = e.event.y;
  115. var bodySize = this.content.getSize();
  116. var position = el.retrieve("position");
  117. var initialWidth = el.retrieve("initialWidth").toFloat();
  118. var dx = x.toFloat() - position.x.toFloat();
  119. var width = initialWidth+dx;
  120. if (width> bodySize.x/2) width = bodySize.x/2;
  121. if (width<200) width = 200;
  122. this.attachmentContentNode.setStyle("margin-left", width);
  123. this.folderContentNode.setStyle("width", width);
  124. }.bind(this)
  125. });
  126. MWF.require("MWF.widget.Tab", function(){
  127. this.treeTab = new MWF.widget.Tab(this.folderTreeAreaNode, {"style": "processlayout"});
  128. this.treeTab.load();
  129. this.fileTabe = this.treeTab.addTab(this.folderTreeAreaScrollNode, this.lp.myFiles, false);
  130. this.shareTab = this.treeTab.addTab(this.shareTreeAreaScrollNode, this.lp.shareFiles, false);
  131. this.editorTab = this.treeTab.addTab(this.editorTreeAreaScrollNode, this.lp.editorFiles, false);
  132. this.fileTabe.addEvent("show", function(){
  133. if (this.folderTree.currentNode){
  134. this.folderTree.currentNode.clickNode();
  135. }else{
  136. if (this.folderTree.firstChild){
  137. this.folderTree.firstChild.clickNode();
  138. }else{
  139. if (this.controller) this.controller.clear();
  140. }
  141. }
  142. this.checkControllerActionsFile();
  143. }.bind(this));
  144. this.shareTab.addEvent("show", function(){
  145. if (this.shareTree.currentNode){
  146. this.shareTree.currentNode.clickNode();
  147. }else{
  148. if (this.shareTree.firstChild){
  149. this.shareTree.firstChild.clickNode();
  150. }else{
  151. if (this.controller) this.controller.clear();
  152. }
  153. }
  154. this.checkControllerActionsShare();
  155. }.bind(this));
  156. this.editorTab.addEvent("show", function(){
  157. if (this.editorTree.currentNode){
  158. this.editorTree.currentNode.clickNode();
  159. }else{
  160. if (this.editorTree.firstChild){
  161. this.editorTree.firstChild.clickNode();
  162. }else{
  163. if (this.controller) this.controller.clear();
  164. }
  165. }
  166. this.checkControllerActionsEditor();
  167. }.bind(this));
  168. var tabName = "file";
  169. if (this.status){
  170. if (this.status.tab){
  171. tabName = this.status.tab;
  172. }
  173. }
  174. if (tabName == "file") this.fileTabe.showIm();
  175. if (tabName == "share") this.shareTab.showIm();
  176. if (tabName == "editor") this.editorTab.showIm();
  177. this.setContentHeight();
  178. this.addEvent("resize", function(){this.setContentHeight();}.bind(this));
  179. }.bind(this));
  180. MWF.require("MWF.widget.ScrollBar", function(){
  181. new MWF.widget.ScrollBar(this.folderTreeAreaScrollNode, {
  182. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  183. });
  184. new MWF.widget.ScrollBar(this.shareTreeAreaScrollNode, {
  185. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  186. });
  187. new MWF.widget.ScrollBar(this.editorTreeAreaScrollNode, {
  188. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  189. });
  190. //new MWF.widget.ScrollBar(this.fileContentAreaScrollNode, {
  191. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  192. //});
  193. }.bind(this));
  194. },
  195. checkControllerActionsFile: function(){
  196. this.controller.folderActionBoxNode.setStyle("display", "block");
  197. //this.controller.editActionBoxNode.setStyle("display", "block");
  198. this.controller.uploadAction.setStyle("display", "block");
  199. this.controller.deleteAction.setStyle("display", "block");
  200. this.controller.replaceAction.setStyle("display", "block");
  201. this.controller.editActionSeparateNode.setStyle("display", "block");
  202. this.controller.shareActionBoxNode.setStyle("display", "block");
  203. },
  204. checkControllerActionsShare: function(){
  205. this.controller.folderActionBoxNode.setStyle("display", "none");
  206. this.controller.uploadAction.setStyle("display", "none");
  207. this.controller.deleteAction.setStyle("display", "none");
  208. this.controller.replaceAction.setStyle("display", "none");
  209. this.controller.editActionSeparateNode.setStyle("display", "none");
  210. // this.controller.editActionBoxNode.setStyle("display", "none");
  211. this.controller.shareActionBoxNode.setStyle("display", "none");
  212. },
  213. checkControllerActionsEditor: function(){
  214. this.controller.folderActionBoxNode.setStyle("display", "none");
  215. this.controller.uploadAction.setStyle("display", "none");
  216. this.controller.deleteAction.setStyle("display", "none");
  217. this.controller.replaceAction.setStyle("display", "block");
  218. this.controller.editActionSeparateNode.setStyle("display", "block");
  219. // this.controller.editActionBoxNode.setStyle("display", "none");
  220. this.controller.shareActionBoxNode.setStyle("display", "none");
  221. },
  222. loadTop: function(){
  223. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  224. this.leftNode = new Element("div", {"styles": this.css.leftNode}).inject(this.topNode);
  225. this.leftNode.addEvent("click", function(){
  226. this.leftPath();
  227. }.bind(this));
  228. this.rightNode = new Element("div", {"styles": this.css.rightNode}).inject(this.topNode);
  229. this.rightNode.addEvent("click", function(){
  230. this.rightPath();
  231. }.bind(this));
  232. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.topNode);
  233. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.topNode);
  234. this.pathNode = new Element("div", {"styles": this.css.pathNode}).inject(this.topNode);
  235. },
  236. //loadTools: function(){
  237. // this.toolsNode = new Element("div", {"styles": this.css.toolsNode}).inject(this.node);
  238. // this.uploadNode = new Element("div", {"styles": this.css.toolsActionNode, "text": this.lp.upload}).inject(this.toolsNode);
  239. // this.createFolderNode = new Element("div", {"styles": this.css.toolsActionNode, "text": this.lp.createFolder}).inject(this.toolsNode);
  240. // this.operationNode = new Element("div", {"styles": this.css.toolsMenuActionNode}).inject(this.toolsNode);
  241. // var downTextNode = new Element("div", {"styles": this.css.downTextNode, "text": this.lp.operation}).inject(this.operationNode);
  242. // var downIconNode = new Element("div", {"styles": this.css.downIconNode}).inject(this.operationNode);
  243. //
  244. // this.uploadNode.addEvents({
  245. // "mouseover": function(){this.uploadNode.setStyles(this.css.toolsActionNode_over);}.bind(this),
  246. // "mouseout": function(){this.uploadNode.setStyles(this.css.toolsActionNode);}.bind(this),
  247. // "click": function(){this.createUploadFile();}.bind(this)
  248. // });
  249. // this.createFolderNode.addEvents({
  250. // "mouseover": function(){this.createFolderNode.setStyles(this.css.toolsActionNode_over);}.bind(this),
  251. // "mouseout": funtion(){this.createFolderNode.setStyles(this.css.toolsActionNode);}.bind(this),
  252. // "click": function(){this.createFolder();}.bind(this)
  253. // });
  254. // this.operationNode.addEvents({
  255. // "mouseover": function(){this.operationNode.setStyles(this.css.toolsMenuActionNode_over);}.bind(this),
  256. // "mouseout": function(){this.operationNode.setStyles(this.css.toolsMenuActionNode);}.bind(this),
  257. // "click": function(){}.bind(this)
  258. // });
  259. // this.operationMenu = new MWF.xDesktop.Menu(this.operationNode, {
  260. // "event": "click",
  261. // "style": "fileOperation",
  262. // "offsetX": -4,
  263. // "offsetY": 4,
  264. // "onQueryShow": function(){
  265. // this.operationMenu.items.each(function(item){item.setDisable(true);});
  266. // if (this.selectedItem){
  267. // if (this.selectedItem.type=="folder"){
  268. // this.operationMenu.items[0].setText(this.lp.uploadTo+" "+this.selectedItem.data.name+"...");
  269. // this.operationMenu.items[0].setDisable(false);
  270. // this.operationMenu.items[3].setDisable(false);
  271. // this.operationMenu.items[4].setDisable(false);
  272. // this.operationMenu.items[7].setDisable(false);
  273. // }
  274. // if (this.selectedItem.type=="file"){
  275. // this.operationMenu.items[0].setText(this.lp.uploadTo);
  276. // this.operationMenu.items[0].setDisable(true);
  277. // this.operationMenu.items[1].setDisable(false);
  278. // this.operationMenu.items[3].setDisable(false);
  279. // this.operationMenu.items[4].setDisable(false);
  280. // this.operationMenu.items[5].setDisable(false);
  281. // this.operationMenu.items[7].setDisable(false);
  282. // }
  283. // }
  284. // }.bind(this)
  285. // });
  286. // this.operationMenu.load();
  287. //
  288. // var img = this.path+this.options.style+"/operation/upload.png";
  289. // this.operationMenu.addMenuItem(this.lp.uploadTo, "click", function(){this.createUploadFile(this.selectedItem);}.bind(this), img);
  290. // var img = this.path+this.options.style+"/operation/download.png";
  291. // this.operationMenu.addMenuItem(this.lp.download, "click", function(){this.downloadCurrentFile();}.bind(this), img);
  292. //
  293. // this.operationMenu.addMenuLine();
  294. //
  295. // var img = this.path+this.options.style+"/operation/move.png";
  296. // this.operationMenu.addMenuItem(this.lp.move, "click", function(){this.moveFileFolder();}.bind(this), img);
  297. // var img = this.path+this.options.style+"/operation/rename.png";
  298. // this.operationMenu.addMenuItem(this.lp.rename, "click", function(){this.renameFileFolder();}.bind(this), img);
  299. // var img = this.path+this.options.style+"/operation/share.png";
  300. // this.operationMenu.addMenuItem(this.lp.share, "click", function(){this.shareFile();}.bind(this), img);
  301. //
  302. // this.operationMenu.addMenuLine();
  303. //
  304. // var img = this.path+this.options.style+"/operation/delete.png";
  305. // this.operationMenu.addMenuItem(this.lp["delete"], "click", function(e){this.deleteFileFolder(e);}.bind(this), img);
  306. //},
  307. openAttachment: function(e, node, attachment){
  308. this.restActions.getFileUrl(attachment[0].data.id, function(url){
  309. window.open(o2.filterUrl(url));
  310. });
  311. },
  312. downloadAttachment: function(e, node, attachments){
  313. attachments.each(function(attachment){
  314. this.restActions.getFileDownloadUrl(attachment.data.id, function(url){
  315. window.open(o2.filterUrl(url));
  316. });
  317. }.bind(this));
  318. },
  319. getAttachmentLinkUrl: function(attachment){
  320. debugger;
  321. var url = o2.Actions.get("x_file_assemble_control").action.actions.getAttachmentData.uri;
  322. return url.replace("{id}", encodeURIComponent(attachment.data.id));
  323. },
  324. downloadCurrentFile: function(){
  325. if (this.selectedItem){
  326. if (this.selectedItem.type=="file"){
  327. this.selectedItem.open();
  328. }
  329. }
  330. },
  331. moveFileFolder: function(){
  332. //move----------
  333. //move----------
  334. //move----------
  335. //move----------
  336. },
  337. renameFileFolder: function(){
  338. this.content.mask({
  339. "style": {
  340. "opacity": 0.7,
  341. "background-color": "#999"
  342. }
  343. });
  344. var renameNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  345. renameNode.position({
  346. relativeTo: this.node,
  347. position: "center"
  348. });
  349. var item = this.controller.selectedAttachments[0];
  350. var treeNode = item.treeNode;
  351. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.rename}).inject(renameNode);
  352. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputName}).inject(renameNode);
  353. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(renameNode);
  354. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode, "value": item.data.name}).inject(inputAreaNode);
  355. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(renameNode);
  356. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  357. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  358. cancelButton.addEvent("click", function(){
  359. this.content.unmask();
  360. renameNode.destroy();
  361. }.bind(this));
  362. okButton.addEvent("click", function(){
  363. if (inputNode.get("value")){
  364. item.data.name = inputNode.get("value");
  365. if (item.type=="folder"){
  366. this.restActions.saveFolder(item.data, function(json){
  367. if (this.currentFolder){
  368. this.currentFolder.clickNode();
  369. }else{
  370. this.topTreeNode.clickNode();
  371. }
  372. treeNode.setText(inputNode.get("value"));
  373. }.bind(this));
  374. }else{
  375. this.restActions.updateAttachment(this.controller.selectedAttachments[0].data.id, this.controller.selectedAttachments[0].data, function(json){
  376. if (this.currentFolder){
  377. this.currentFolder.clickNode();
  378. }else{
  379. this.topTreeNode.clickNode();
  380. }
  381. }.bind(this));
  382. }
  383. renameNode.destroy();
  384. this.content.unmask();
  385. }else{
  386. this.notice(this.lp.nameNotEmpty, "error", renameNode);
  387. }
  388. }.bind(this));
  389. },
  390. deleteAttachments: function(e, node, attachments){
  391. this.deleteFileFolder(e, attachments);
  392. },
  393. deleteFileFolder: function(e, attachments){
  394. if (attachments.length){
  395. var _self = this;
  396. var title = this.lp.deleteFolderFilesTitle;
  397. var content = this.lp.deleteFolderFiles;
  398. if (attachments.length==1){
  399. var title = (attachments[0].type=="folder") ? this.lp.deleteFolderTitle : this.lp.deleteFileTitle;
  400. var content = (attachments[0].type=="folder") ? this.lp.deleteFolder : this.lp.deleteFile;
  401. content = content+"("+attachments[0].data.name+")";
  402. }
  403. var size = this.node.getSize();
  404. // var position = this.operationMenu.items[7].item.getPosition(this.operationMenu.items[7].item.getOffsetParent());
  405. var ep = {"event": {"x": (size.x-300)/2, "y": (size.y-120)/2}};
  406. this.confirm("infor", ep, title, content, 300, 120, function(){
  407. var count = attachments.length;
  408. var current = 0;
  409. var callback = function(){
  410. if (current == count){
  411. if (this.currentFolder){
  412. this.currentFolder.loaded = false;
  413. this.currentFolder.clickNode();
  414. }else{
  415. this.topTreeNode.loaded = false;
  416. this.topTreeNode.clickNode();
  417. }
  418. }
  419. };
  420. attachments.each(function(att){
  421. if (att.type=="folder"){
  422. att.treeNode.destroy();
  423. _self.restActions.deleteFolder(att.data.id, function(){
  424. current++;
  425. callback.apply(_self);
  426. });
  427. }else{
  428. _self.restActions.deleteFile(att.data.id, function(){
  429. current++;
  430. callback.apply(_self);
  431. });
  432. }
  433. });
  434. this.close();
  435. }, function(){
  436. this.close();
  437. });
  438. }
  439. },
  440. shareAttachment: function(){
  441. this.shareFile();
  442. },
  443. shareFile: function(){
  444. this.content.mask({
  445. "style": {
  446. "opacity": 0.7,
  447. "background-color": "#999"
  448. }
  449. });
  450. var shareNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  451. shareNode.position({
  452. relativeTo: this.node,
  453. position: "center"
  454. });
  455. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.shareFile}).inject(shareNode);
  456. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.selectShareUser}).inject(shareNode);
  457. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(shareNode);
  458. var inputNode = new Element("div", {"type": "text", "readonly": true, "styles": this.css.shareFileInputNode}).inject(inputAreaNode);
  459. // if (this.controller.selectedAttachments.length==1) inputNode.set("value", this.controller.selectedAttachments[0].data.shareList.join(", "));
  460. inputNode.addEvent("click", function(){
  461. MWF.xDesktop.requireApp("Selector", "Person", function(){
  462. var selector = new MWF.xApplication.Selector.Person(this.node,{
  463. //"values": this.selectedItem.data.shareList,
  464. "onComplete": function(items){
  465. MWF.require("MWF.widget.O2Identity", function(){
  466. var names = [];
  467. var texts = [];
  468. inputNode.empty();
  469. items.each(function(item){
  470. names.push(item.data.distinguishedName);
  471. texts.push(item.data.name);
  472. new MWF.widget.O2Person({"name": item.data.distinguishedName}, inputNode, {"style": "xform"})
  473. });
  474. inputNode.store("texts", texts);
  475. inputNode.set("value", names.join(", "));
  476. }.bind(this));
  477. }.bind(this)
  478. });
  479. selector.load();
  480. }.bind(this));
  481. }.bind(this));
  482. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(shareNode);
  483. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  484. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  485. cancelButton.addEvent("click", function(){
  486. this.content.unmask();
  487. shareNode.destroy();
  488. }.bind(this));
  489. okButton.addEvent("click", function(){
  490. var count = this.controller.selectedAttachments.length;
  491. var current = 0;
  492. var callback = function(){
  493. if (current === count){
  494. if (inputNode.get("value")) this.notice(this.lp.fileShareSuccess+inputNode.retrieve("texts", []).join(","), "success", this.content);
  495. shareNode.destroy();
  496. this.content.unmask();
  497. }
  498. };
  499. this.controller.selectedAttachments.each(function(att){
  500. if (att.type!="folder"){
  501. att.data.shareList = inputNode.get("value").split(/,\s*/g);
  502. this.restActions.updateAttachment(att.data.id, att.data, function(json){
  503. current++;
  504. callback.apply(this);
  505. }.bind(this));
  506. }else{
  507. current++;
  508. callback.apply(this);
  509. }
  510. }.bind(this));
  511. }.bind(this));
  512. },
  513. sendAttachment: function(){
  514. this.sendFile();
  515. },
  516. sendFile: function(){
  517. this.content.mask({
  518. "style": {
  519. "opacity": 0.7,
  520. "background-color": "#999"
  521. }
  522. });
  523. var shareNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  524. shareNode.position({
  525. relativeTo: this.node,
  526. position: "center"
  527. });
  528. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.sendFile}).inject(shareNode);
  529. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.selectSendUser}).inject(shareNode);
  530. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(shareNode);
  531. var inputNode = new Element("div", {"type": "text", "readonly": true, "styles": this.css.shareFileInputNode}).inject(inputAreaNode);
  532. // if (this.controller.selectedAttachments.length==1) inputNode.set("value", this.controller.selectedAttachments[0].data.shareList.join(", "));
  533. inputNode.addEvent("click", function(){
  534. MWF.xDesktop.requireApp("Selector", "Person", function(){
  535. var selector = new MWF.xApplication.Selector.Person(this.node,{
  536. //"values": this.selectedItem.data.shareList,
  537. "onComplete": function(items){
  538. MWF.require("MWF.widget.O2Identity", function(){
  539. var names = [];
  540. var texts = [];
  541. inputNode.empty();
  542. items.each(function(item){
  543. names.push(item.data.distinguishedName);
  544. texts.push(item.data.name);
  545. new MWF.widget.O2Person({"name": item.data.distinguishedName}, inputNode, {"style": "xform"})
  546. });
  547. //inputNode.set("text", texts.join(", "));
  548. inputNode.store("texts", texts);
  549. inputNode.set("value", names.join(", "));
  550. }.bind(this));
  551. // var names = [];
  552. // items.each(function(item){
  553. // names.push(item.data.distinguishedName);
  554. // });
  555. // inputNode.set("value", names.join(", "));
  556. }.bind(this)
  557. });
  558. selector.load();
  559. }.bind(this));
  560. }.bind(this));
  561. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(shareNode);
  562. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  563. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  564. cancelButton.addEvent("click", function(){
  565. this.content.unmask();
  566. shareNode.destroy();
  567. }.bind(this));
  568. okButton.addEvent("click", function(){
  569. var count = this.controller.selectedAttachments.length;
  570. var current = 0;
  571. var callback = function(){
  572. if (current == count){
  573. if (inputNode.get("value")) this.notice(this.lp.fileSendSuccess+inputNode.retrieve("texts", []).join(","), "success", this.content);
  574. shareNode.destroy();
  575. this.content.unmask();
  576. }
  577. };
  578. this.controller.selectedAttachments.each(function(att){
  579. if (att.type!="folder"){
  580. att.data.editorList = inputNode.get("value").split(/,\s*/g);
  581. this.restActions.updateAttachment(att.data.id, att.data, function(json){
  582. current++;
  583. callback.apply(this);
  584. }.bind(this));
  585. }else{
  586. current++;
  587. callback.apply(this);
  588. }
  589. }.bind(this));
  590. }.bind(this));
  591. },
  592. uploadAttachment: function(e, node){
  593. folderId = (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "";
  594. this.controller.doUploadAttachment(null, this.restActions.action, "addAttachment", {"folder": folderId || "(0)"}, function(){
  595. if (this.currentFolder){
  596. this.currentFolder.clickNode();
  597. }else{
  598. this.topTreeNode.clickNode();
  599. }
  600. }.bind(this));
  601. },
  602. replaceAttachment: function(e, node, attachment){
  603. var fileId = attachment.data.id;
  604. this.controller.doReplaceAttachment(null, this.restActions.action, "updateAttachmentData", {"id": fileId}, function(){
  605. if (this.currentFolder){
  606. this.currentFolder.clickNode();
  607. }else{
  608. this.topTreeNode.clickNode();
  609. }
  610. }.bind(this));
  611. //this.replaceUploadFile(attachment);
  612. },
  613. // replaceUploadFile: function(attachment){
  614. // if (!this.replaceFileAreaNode){
  615. // this.replaceFileAreaNode = new Element("div");
  616. // var html = "<input name=\"file\" multiple type=\"file\"/>";
  617. // this.replaceFileAreaNode.set("html", html);
  618. //
  619. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  620. // this.fileReplaceNode.addEvent("change", function(){
  621. // var fileId = attachment.data.id;
  622. //
  623. // var files = fileNode.files;
  624. // if (files.length){
  625. // var count = files.length;
  626. // var current = 0;
  627. // var callback = function(){
  628. // if (current == count){
  629. // if (this.currentFolder){
  630. // this.currentFolder.clickNode();
  631. // }else{
  632. // this.topTreeNode.clickNode();
  633. // }
  634. // }
  635. // };
  636. // for (var i = 0; i < files.length; i++) {
  637. // var file = files.item(i);
  638. //
  639. // var formData = new FormData();
  640. // formData.append('file', file);
  641. //
  642. // this.restActions.updateAttachmentData(fileId, formData, file, function(){
  643. // current++;
  644. // callback.apply(this);
  645. // }.bind(this));
  646. // }
  647. // }
  648. //
  649. // }.bind(this));
  650. // }
  651. // this.fileReplaceNode.set("accept", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
  652. // this.fileReplaceNode.set("multiple", false);
  653. //
  654. // var fileNode = this.replaceFileAreaNode.getFirst();
  655. // fileNode.set("accept", "*/*");
  656. // fileNode.click();
  657. // },
  658. createFolder: function(){
  659. this.content.mask({
  660. "style": {
  661. "opacity": 0.7,
  662. "background-color": "#999"
  663. }
  664. });
  665. var createFolderNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  666. createFolderNode.position({
  667. relativeTo: this.node,
  668. position: "center"
  669. });
  670. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.createFolder}).inject(createFolderNode);
  671. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputFolderName}).inject(createFolderNode);
  672. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(createFolderNode);
  673. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode}).inject(inputAreaNode);
  674. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(createFolderNode);
  675. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  676. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  677. cancelButton.addEvent("click", function(){
  678. this.content.unmask();
  679. createFolderNode.destroy();
  680. }.bind(this));
  681. okButton.addEvent("click", function(){
  682. if (inputNode.get("value")){
  683. var data = {
  684. "name": inputNode.get("value"),
  685. "superior": (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : ""
  686. };
  687. this.restActions.saveFolder(data, function(json){
  688. data.id = json.data.id;
  689. this.restActions.getFolder(data.id, function(folderJson){
  690. if (this.currentFolder){
  691. var json = {"data":[folderJson.data]};
  692. this.createTreeNode(json, this.currentFolder);
  693. this.currentFolder.clickNode();
  694. }else{
  695. this.topTreeNode.clickNode();
  696. }
  697. }.bind(this));
  698. }.bind(this));
  699. createFolderNode.destroy();
  700. this.content.unmask();
  701. }else{
  702. this.notice(this.lp.folderNameNotEmpty, "error", createFolderNode);
  703. }
  704. }.bind(this));
  705. },
  706. getAttachmentUrl: function(attachment, callback){
  707. this.restActions.getFileUrl(attachment.data.id, callback);
  708. },
  709. loadFolderTreeNode: function(){
  710. this.folderTreeNode = new Element("div", {
  711. "styles": this.css.folderTreeNode
  712. }).inject(this.folderTreeAreaScrollNode);
  713. // MWF.require("MWF.widget.Tree", function(){
  714. this.folderTree = new MWF.widget.Tree(this.folderTreeNode, {
  715. "style": "file"
  716. // "onQueryExpand": function(node){
  717. // this.loadFolderTree(node);
  718. // }.bind(this)
  719. });
  720. this.folderTree.load();
  721. var rootData = {
  722. "expand": false,
  723. "title": "root",
  724. "text": "root",
  725. "action": function(treeNode){
  726. this.recordHistory(treeNode);
  727. this.expand(treeNode, function(){
  728. this.loadSub(treeNode);
  729. }.bind(this));
  730. }.bind(this),
  731. "icon": "folder.png"
  732. };
  733. this.topTreeNode = this.folderTree.appendChild(rootData);
  734. //this.topTreeNode.clickNode();
  735. // this.loadFolderTree();
  736. // }.bind(this));
  737. },
  738. createShareTreeNode: function(json){
  739. json.data.each(function(data){
  740. var name = data.name.substring(0, data.name.indexOf("@"));
  741. var nodeData = {
  742. "expand": false,
  743. "title": name+"("+data.count+")",
  744. "text": name+"("+data.count+")",
  745. "action": function(treeNode){
  746. this.loadShareFile(treeNode);
  747. }.bind(this),
  748. "icon": "folder.png"
  749. };
  750. var treeNode = this.shareTree.appendChild(nodeData);
  751. treeNode.data = data;
  752. }.bind(this));
  753. },
  754. loadShareTreeNode: function(){
  755. this.shareTreeNode = new Element("div", {
  756. "styles": this.css.folderTreeNode
  757. }).inject(this.shareTreeAreaScrollNode);
  758. // MWF.require("MWF.widget.Tree", function(){
  759. this.shareTree = new MWF.widget.Tree(this.shareTreeNode, {
  760. "style": "file"
  761. });
  762. this.shareTree.load();
  763. this.restActions.listShare(function(json){
  764. this.createShareTreeNode(json);
  765. // node.setOperateIcon();
  766. if (this.shareTree.loadCallback) this.shareTree.loadCallback.apply(this);
  767. }.bind(this), null, false);
  768. // this.loadFolderTree();
  769. // }.bind(this));
  770. },
  771. loadShareFile: function(treeNode){
  772. var person = treeNode.data.name;
  773. this.restActions.listShareAttachment(person, function(json){
  774. //this.fileContentAreaNode.empty();
  775. this.controller.clear();
  776. json.data.each(function(file){
  777. this.controller.addAttachment(file);
  778. //new MWF.xApplication.File.ShareAttachment(file, this);
  779. }.bind(this));
  780. }.bind(this));
  781. },
  782. createEditorTreeNode: function(json){
  783. json.data.each(function(data){
  784. var name = MWF.name.cn(data.name);
  785. var nodeData = {
  786. "expand": false,
  787. "title": name+"("+data.count+")",
  788. "text": name+"("+data.count+")",
  789. "action": function(treeNode){
  790. this.loadEditorFile(treeNode);
  791. }.bind(this),
  792. "icon": "folder.png"
  793. };
  794. var treeNode = this.editorTree.appendChild(nodeData);
  795. treeNode.data = data;
  796. }.bind(this));
  797. },
  798. loadEditorTreeNode: function(){
  799. this.editorTreeNode = new Element("div", {
  800. "styles": this.css.folderTreeNode
  801. }).inject(this.editorTreeAreaScrollNode);
  802. // MWF.require("MWF.widget.Tree", function(){
  803. this.editorTree = new MWF.widget.Tree(this.editorTreeNode, {
  804. "style": "file"
  805. });
  806. this.editorTree.load();
  807. this.restActions.listEditor(function(json){
  808. this.createEditorTreeNode(json);
  809. // node.setOperateIcon();
  810. if (this.editorTree.loadCallback) this.editorTree.loadCallback.apply(this);
  811. }.bind(this), null, false);
  812. // this.loadFolderTree();
  813. // }.bind(this));
  814. },
  815. loadEditorFile: function(treeNode){
  816. var person = treeNode.data.name;
  817. this.restActions.listEditorAttachment(person, function(json){
  818. //this.fileContentAreaNode.empty();
  819. this.controller.clear();
  820. json.data.each(function(file){
  821. this.controller.addAttachment(file);
  822. //new MWF.xApplication.File.ShareAttachment(file, this);
  823. }.bind(this));
  824. }.bind(this));
  825. },
  826. loadFileContentAreaNode: function(){
  827. this.controller = new MWF.xApplication.File.AttachmentController(this.attachmentContentNode, this, {
  828. "resize": false,
  829. "isSizeChange": false,
  830. })
  831. this.controller.load();
  832. //this.fileContentAreaScrollNode = new Element("div", {
  833. // "styles": this.css.fileContentAreaScrollNode
  834. //}).inject(this.attachmentContentNode);
  835. //
  836. //this.fileContentAreaScrollNode.addEvent("click", function(){
  837. // if (this.selectedItem) this.selectedItem.unSelected();
  838. //}.bind(this));
  839. //
  840. //this.fileContentAreaNode = new Element("div", {
  841. // "styles": this.css.fileContentAreaNode
  842. //}).inject(this.fileContentAreaScrollNode);
  843. //
  844. //this.initDropUpLoad();
  845. },
  846. createTreeNode: function(json, topNode){
  847. json.data.each(function(data){
  848. var nodeData = {
  849. "expand": false,
  850. "title": data.name,
  851. "text": data.name,
  852. "action": function(treeNode){
  853. this.recordHistory(treeNode);
  854. this.expand(treeNode, function(){
  855. this.loadSub(treeNode);
  856. }.bind(this));
  857. }.bind(this),
  858. "icon": "folder.png"
  859. };
  860. var treeNode = topNode.appendChild(nodeData);
  861. treeNode.data = data;
  862. }.bind(this));
  863. },
  864. loadFolderTree: function(node, callback){
  865. if (!node.loaded){
  866. node.loaded = true;
  867. if (node.data){
  868. this.restActions.listFolder(node.data.id, function(json){
  869. this.createTreeNode(json, node);
  870. node.setOperateIcon();
  871. if (callback) callback();
  872. }.bind(this), null, false);
  873. }else{
  874. this.restActions.listTopFolder(function(json){
  875. this.createTreeNode(json, node);
  876. node.setOperateIcon();
  877. if (callback) callback();
  878. }.bind(this), null, false);
  879. }
  880. }else{
  881. if (callback) callback();
  882. }
  883. },
  884. setContentHeight: function(node){
  885. var size = this.node.getSize();
  886. var tSize = this.topNode.getSize();
  887. // var toolSize = this.toolsNode.getSize();
  888. var mtt = this.topNode.getStyle("margin-top").toFloat();
  889. var mbt = this.topNode.getStyle("margin-bottom").toFloat();
  890. // var mttool = this.toolsNode.getStyle("margin-top").toFloat();
  891. // var mbtool = this.toolsNode.getStyle("margin-bottom").toFloat();
  892. var mtc = this.fileContentNode.getStyle("margin-top").toFloat();
  893. var mbc = this.fileContentNode.getStyle("margin-bottom").toFloat();
  894. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  895. this.fileContentNode.setStyle("height", height);
  896. this.attachmentContentNode.setStyle("height", height);
  897. var attTopSzie = this.controller.topNode.getSize();
  898. var y = height-attTopSzie.y;
  899. this.controller.contentScrollNode.setStyle("height", ""+y+"px");
  900. // this.fileContentAreaNode.setStyle("min-height", height);
  901. var tabSize = this.treeTab.tabNodeContainer.getSize();
  902. var height = height-tabSize.y;
  903. this.folderTreeAreaScrollNode.setStyle("height", height);
  904. this.shareTreeAreaScrollNode.setStyle("height", height);
  905. this.editorTreeAreaScrollNode.setStyle("height", height);
  906. },
  907. expand: function(treeNode, callback){
  908. if (!treeNode.options.expand){
  909. this.loadFolderTree(treeNode, function(){
  910. if (callback) callback();
  911. }.bind(this));
  912. this.folderTree.expand(treeNode);
  913. treeNode.options.expand = true;
  914. treeNode.setOperateIcon();
  915. }else{
  916. if (callback) callback();
  917. }
  918. },
  919. checkHistory: function(){
  920. if (this.history.length>1){
  921. if (this.currentHistory>0){
  922. this.enabledLeftNode();
  923. }else{
  924. this.disabledLeftNode();
  925. }
  926. if (this.currentHistory<this.history.length-1){
  927. this.enabledRightNode();
  928. }else{
  929. this.disabledRightNode();
  930. }
  931. }else{
  932. this.disabledLeftNode();
  933. this.disabledRightNode();
  934. }
  935. },
  936. enabledLeftNode: function(){
  937. this.leftNode.setStyle("background-image", "url("+"../x_component_File/$Main/default/icon/left_enabled.png)");
  938. },
  939. enabledRightNode: function(){
  940. this.rightNode.setStyle("background-image", "url("+"../x_component_File/$Main/default/icon/right_enabled.png)");
  941. },
  942. disabledLeftNode: function(){
  943. this.leftNode.setStyle("background-image", "url("+"../x_component_File/$Main/default/icon/left.png)");
  944. },
  945. disabledRightNode: function(){
  946. this.rightNode.setStyle("background-image", "url("+"../x_component_File/$Main/default/icon/right.png)");
  947. },
  948. leftPath: function(){
  949. if (this.currentHistory>0){
  950. this.currentHistory--;
  951. var treeNode = this.history[this.currentHistory];
  952. if (treeNode){
  953. treeNode.selectNode();
  954. this.loadSub(treeNode);
  955. this.checkHistory();
  956. }
  957. }
  958. },
  959. rightPath: function(){
  960. if (this.currentHistory<this.history.length-1){
  961. this.currentHistory++;
  962. var treeNode = this.history[this.currentHistory];
  963. if (treeNode){
  964. treeNode.selectNode();
  965. this.loadSub(treeNode);
  966. this.checkHistory();
  967. }
  968. }
  969. },
  970. recordHistory: function(treeNode){
  971. if (!this.history.length || this.history[this.history.length-1]!=treeNode){
  972. this.history.push(treeNode);
  973. this.currentHistory = this.history.length-1;
  974. this.checkHistory();
  975. }
  976. },
  977. setPathNode: function(treeNode){
  978. this.pathNode.empty();
  979. var paths = [];
  980. var tmpNode = treeNode;
  981. while (tmpNode){
  982. paths.unshift(tmpNode);
  983. tmpNode = tmpNode.parentNode;
  984. };
  985. var _self = this;
  986. paths.each(function(node, index){
  987. this.expand(node);
  988. var pathNode = new Element("div",{
  989. "styles": this.css.pathItemNode,
  990. "text": (node.data) ? node.data.name : "root",
  991. "events": {
  992. "mouseover": function(){
  993. this.setStyles(_self.css.pathItemNode_over);
  994. },
  995. "mouseout": function(){
  996. this.setStyles(_self.css.pathItemNode);
  997. },
  998. "click": function(){
  999. node.clickNode();
  1000. }
  1001. }
  1002. }).inject(this.pathNode);
  1003. if (index<paths.length-1) new Element("div",{"styles": this.css.pathItemIconNode}).inject(this.pathNode);
  1004. }.bind(this));
  1005. },
  1006. loadSub: function(treeNode){
  1007. this.setPathNode(treeNode);
  1008. //this.fileContentAreaNode.empty();
  1009. this.controller.clear();
  1010. treeNode.children.each(function(node){
  1011. var folder = this.controller.addAttachmentFolder(node.data);
  1012. folder.treeNode = node;
  1013. //var folder = new MWF.xApplication.File.Folder(node.data, this);
  1014. //folder.treeNode = node;
  1015. }.bind(this));
  1016. this.currentFolder = treeNode;
  1017. if (treeNode.data){
  1018. this.restActions.listAttachment(treeNode.data.id, function(json){
  1019. json.data.each(function(file){
  1020. this.controller.addAttachment(file);
  1021. //new MWF.xApplication.File.Attachment(file, this);
  1022. }.bind(this));
  1023. }.bind(this));
  1024. }else{
  1025. this.restActions.listAttachmentTop(function(json){
  1026. json.data.each(function(file){
  1027. this.controller.addAttachment(file);
  1028. //new MWF.xApplication.File.Attachment(file, this);
  1029. }.bind(this));
  1030. }.bind(this));
  1031. }
  1032. },
  1033. uploadFiles: function(files){
  1034. if (!this.uploadFileList) this.uploadFileList = [];
  1035. if (!this.uploadFileTotalSize) this.uploadFileTotalSize = 0;
  1036. if (!files || !files.length) return;
  1037. for (var i = 0; i < files.length && i < 5; i++) {
  1038. this.uploadFileList.push(files[i]);
  1039. this.uploadFileTotalSize += files[i].size;
  1040. }
  1041. this.uploadNext();
  1042. },
  1043. uploadNext: function(){
  1044. if (this.uploadFileList.length) {
  1045. var nextFile = this.uploadFileList.shift();
  1046. if (nextFile){
  1047. this.uploadFile(nextFile);
  1048. this.uploadNext();
  1049. }
  1050. }
  1051. },
  1052. uploadFile: function(file){
  1053. var formData = new FormData();
  1054. formData.append('file', file);
  1055. formData.append('name', file.name);
  1056. formData.append('folder', (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "");
  1057. // xhr.send(formData);
  1058. this.restActions.addAttachment((this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "(0)", formData, file, function(){
  1059. if (!this.uploadFileList.length){
  1060. if (this.currentFolder){
  1061. this.currentFolder.clickNode();
  1062. }else{
  1063. this.topTreeNode.clickNode();
  1064. }
  1065. }
  1066. }.bind(this));
  1067. },
  1068. initDropUpLoad: function(){
  1069. this.fileContentAreaNode.addEventListener('drop', function(e){
  1070. e.stopPropagation();
  1071. e.preventDefault();
  1072. if (this.dropUploadInforNode){
  1073. this.dropUploadInforNode.destroy();
  1074. this.dropUploadInforNode = null;
  1075. }
  1076. if (e.dataTransfer.types.length<2){
  1077. this.uploadFiles(e.dataTransfer.files);
  1078. }
  1079. }.bind(this), false);
  1080. this.fileContentAreaNode.addEventListener('dragover', function(e){
  1081. if (e.dataTransfer.types.length<2){
  1082. e.stopPropagation();
  1083. e.preventDefault();
  1084. if (!this.dropUploadInforNode){
  1085. this.dropUploadInforNode = new Element("div", {
  1086. "styles": this.css.dropUploadInforNode,
  1087. "text": this.lp.dropUpload
  1088. }).inject(this.node);
  1089. this.dropUploadInforNode.position({
  1090. relativeTo: this.fileContentAreaNode,
  1091. position: "centerBottom",
  1092. edge: "centerBottom",
  1093. offset: {"x": 0, "y": -100}
  1094. });
  1095. this.dropUploadInforNode.fade(0.7);
  1096. }
  1097. }
  1098. }.bind(this), false);
  1099. this.fileContentAreaNode.addEventListener('dragleave', function(e){
  1100. e.stopPropagation();
  1101. e.preventDefault();
  1102. if (this.dropUploadInforNode) window.setTimeout(function(){
  1103. if (this.dropUploadInforNode){
  1104. this.dropUploadInforNode.destroy();
  1105. this.dropUploadInforNode = null;
  1106. }
  1107. }.bind(this), 2000);
  1108. }.bind(this), false);
  1109. }
  1110. });
  1111. MWF.xApplication.File.Attachment = new Class({
  1112. initialize: function(data, file){
  1113. this.data = data;
  1114. this.file = file;
  1115. this.type = "file";
  1116. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  1117. this.load();
  1118. },
  1119. getIcon: function(){
  1120. var iconName = this.file.icons[this.extension] || this.file.icons.unknow;
  1121. return "../x_component_File/$Main/default/file/"+iconName;
  1122. },
  1123. load: function(){
  1124. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  1125. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  1126. this.imgNode = new Element("div", {
  1127. "styles": this.file.css.attachmentImgNode
  1128. }).inject(this.iconNode);
  1129. this.imgNode.setStyle("background-image", "url("+this.getIcon()+")");
  1130. this.textNode = new Element("div", {
  1131. "styles": this.file.css.attachmentTextNode,
  1132. "text": this.data.name,
  1133. "title": this.data.name
  1134. }).inject(this.node);
  1135. if (this.data.shareList){
  1136. if (this.data.shareList.length){
  1137. this.shareIconNode = new Element("div", {"styles": this.file.css.shareIconNode}).inject(this.node);
  1138. // this.shareIconNode.position({
  1139. // relativeTo: this.node,
  1140. // position: "centerBottom",
  1141. // edge: "centerBottom"
  1142. // });
  1143. }
  1144. }
  1145. this.node.inject(this.file.fileContentAreaNode);
  1146. this.setEvents();
  1147. },
  1148. setEvents: function(){
  1149. this.node.addEvents({
  1150. "mouseover": function(){
  1151. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  1152. }.bind(this),
  1153. "mouseout": function(){
  1154. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  1155. }.bind(this),
  1156. "click": function(e){
  1157. this.selected();
  1158. e.stop();
  1159. e.stopPropagation();
  1160. }.bind(this),
  1161. "dblclick": function(){
  1162. this.open();
  1163. }.bind(this)
  1164. });
  1165. this.node.makeLnk({
  1166. "par": {
  1167. "icon": this.getIcon(),
  1168. "title": this.data.name,
  1169. "par": "FileOpen#{\"id\": \""+this.data.id+"\", \"type\": \"file\"}"
  1170. }
  1171. });
  1172. },
  1173. selected: function(){
  1174. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  1175. this.isSelected = true;
  1176. this.node.setStyles(this.file.css.attachmentNode_select);
  1177. this.file.selectedItem = this;
  1178. },
  1179. unSelected: function(){
  1180. this.isSelected = false;
  1181. this.node.setStyles(this.file.css.attachmentNode);
  1182. this.file.selectedItem = null;
  1183. },
  1184. open: function(){
  1185. this.file.restActions.getAttachment(this.data.id);
  1186. }
  1187. });
  1188. MWF.xApplication.File.Folder = new Class({
  1189. initialize: function(data, file){
  1190. this.data = data;
  1191. this.file = file;
  1192. this.type = "folder";
  1193. this.load();
  1194. },
  1195. getIcon: function(){
  1196. return "../x_component_File/$Main/default/file/folder.png";
  1197. },
  1198. load: function(){
  1199. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  1200. // this.node.addEvents();
  1201. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  1202. this.imgNode = new Element("img", {
  1203. "styles": this.file.css.attachmentImgNode,
  1204. "src": this.getIcon(),
  1205. "border": "0"
  1206. }).inject(this.iconNode);
  1207. this.textNode = new Element("div", {
  1208. "styles": this.file.css.attachmentTextNode,
  1209. "text": this.data.name
  1210. }).inject(this.node);
  1211. this.node.inject(this.file.fileContentAreaNode);
  1212. this.setEvents();
  1213. },
  1214. setEvents: function(){
  1215. this.node.addEvents({
  1216. "mouseover": function(){
  1217. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  1218. }.bind(this),
  1219. "mouseout": function(){
  1220. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  1221. }.bind(this),
  1222. "click": function(e){
  1223. this.selected();
  1224. e.stop();
  1225. e.stopPropagation();
  1226. }.bind(this),
  1227. "dblclick": function(){
  1228. this.open();
  1229. }.bind(this)
  1230. });
  1231. },
  1232. selected: function(){
  1233. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  1234. this.isSelected = true;
  1235. this.node.setStyles(this.file.css.attachmentNode_select);
  1236. this.file.selectedItem = this;
  1237. },
  1238. unSelected: function(){
  1239. this.isSelected = false;
  1240. this.node.setStyles(this.file.css.attachmentNode);
  1241. this.file.selectedItem = null;
  1242. },
  1243. open: function(){
  1244. this.treeNode.clickNode();
  1245. }
  1246. });
  1247. MWF.xApplication.File.ShareAttachment = new Class({
  1248. Extends: MWF.xApplication.File.Attachment,
  1249. initialize: function(data, file){
  1250. this.data = data;
  1251. this.file = file;
  1252. this.type = "share";
  1253. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  1254. this.load();
  1255. }
  1256. });