Main_bak.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. MWF.require("MWF.xApplication.File.Actions.RestActions", null, false);
  2. MWF.require("MWF.xApplication.File.AttachmentController", null, false);
  3. MWF.xApplication.File.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "name": "File",
  9. "icon": "icon.png",
  10. "width": "1000",
  11. "height": "600",
  12. "title": MWF.xApplication.File.LP.title
  13. },
  14. onQueryLoad: function(){
  15. this.lp = MWF.xApplication.File.LP;
  16. },
  17. loadApplication: function(callback){
  18. this.history = [];
  19. this.currentHistory = 1;
  20. this.currentFolder = null;
  21. this.restActions = new MWF.xApplication.File.Actions.RestActions();
  22. MWF.getJSON("/x_component_File/$Main/icon.json", function(json){
  23. this.icons = json;
  24. }.bind(this), false);
  25. this.createNode();
  26. this.loadApplicationContent();
  27. if (callback) callback();
  28. },
  29. createNode: function(){
  30. this.content.setStyle("overflow", "hidden");
  31. this.node = new Element("div", {
  32. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  33. }).inject(this.content);
  34. },
  35. loadApplicationContent: function(){
  36. this.loadTop();
  37. // this.loadTools();
  38. this.fileContentNode = new Element("div", {"styles": this.css.fileContentNode}).inject(this.node);
  39. this.folderContentNode = new Element("div", {"styles": this.css.folderContentNode}).inject(this.fileContentNode);
  40. this.attachmentContentNode = new Element("div", {"styles": this.css.attachmentContentNode}).inject(this.fileContentNode);
  41. this.resizeContentNode = new Element("div", {"styles": this.css.resizeContentNode}).inject(this.folderContentNode);
  42. this.folderTreeAreaNode = new Element("div", {
  43. "styles": this.css.folderTreeAreaNode
  44. }).inject(this.folderContentNode);
  45. this.folderTreeAreaScrollNode = new Element("div", {
  46. "styles": this.css.folderTreeAreaScrollNode
  47. }).inject(this.folderContentNode);
  48. this.shareTreeAreaScrollNode = new Element("div", {
  49. "styles": this.css.folderTreeAreaScrollNode
  50. }).inject(this.folderContentNode);
  51. this.loadFileContentAreaNode();
  52. this.loadFolderTreeNode();
  53. // this.loadShareTreeNode();
  54. this.treeResize = new Drag(this.resizeContentNode,{
  55. "snap": 1,
  56. "onStart": function(el, e){
  57. var x = e.event.clientX;
  58. var y = e.event.clientY;
  59. el.store("position", {"x": x, "y": y});
  60. var size = this.folderContentNode.getSize();
  61. el.store("initialWidth", size.x);
  62. }.bind(this),
  63. "onDrag": function(el, e){
  64. var x = e.event.clientX;
  65. // var y = e.event.y;
  66. var bodySize = this.content.getSize();
  67. var position = el.retrieve("position");
  68. var initialWidth = el.retrieve("initialWidth").toFloat();
  69. var dx = x.toFloat() - position.x.toFloat();
  70. var width = initialWidth+dx;
  71. if (width> bodySize.x/2) width = bodySize.x/2;
  72. if (width<160) width = 160;
  73. this.attachmentContentNode.setStyle("margin-left", width);
  74. this.folderContentNode.setStyle("width", width);
  75. }.bind(this)
  76. });
  77. MWF.require("MWF.widget.Tab", function(){
  78. this.treeTab = new MWF.widget.Tab(this.folderTreeAreaNode, {"style": "processlayout"});
  79. this.treeTab.load();
  80. this.fileTabe = this.treeTab.addTab(this.folderTreeAreaScrollNode, this.lp.myFiles, false);
  81. this.shareTab = this.treeTab.addTab(this.shareTreeAreaScrollNode, this.lp.shareFiles, false);
  82. this.fileTabe.showIm();
  83. this.setContentHeight();
  84. this.addEvent("resize", function(){this.setContentHeight();}.bind(this));
  85. }.bind(this));
  86. MWF.require("MWF.widget.ScrollBar", function(){
  87. new MWF.widget.ScrollBar(this.folderTreeAreaScrollNode, {
  88. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  89. });
  90. new MWF.widget.ScrollBar(this.shareTreeAreaScrollNode, {
  91. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  92. });
  93. //new MWF.widget.ScrollBar(this.fileContentAreaScrollNode, {
  94. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  95. //});
  96. }.bind(this));
  97. },
  98. loadTop: function(){
  99. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  100. this.leftNode = new Element("div", {"styles": this.css.leftNode}).inject(this.topNode);
  101. this.leftNode.addEvent("click", function(){
  102. this.leftPath();
  103. }.bind(this));
  104. this.rightNode = new Element("div", {"styles": this.css.rightNode}).inject(this.topNode);
  105. this.rightNode.addEvent("click", function(){
  106. this.rightPath();
  107. }.bind(this));
  108. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.topNode);
  109. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.topNode);
  110. this.pathNode = new Element("div", {"styles": this.css.pathNode}).inject(this.topNode);
  111. },
  112. loadTools: function(){
  113. this.toolsNode = new Element("div", {"styles": this.css.toolsNode}).inject(this.node);
  114. this.uploadNode = new Element("div", {"styles": this.css.toolsActionNode, "text": this.lp.upload}).inject(this.toolsNode);
  115. this.createFolderNode = new Element("div", {"styles": this.css.toolsActionNode, "text": this.lp.createFolder}).inject(this.toolsNode);
  116. this.operationNode = new Element("div", {"styles": this.css.toolsMenuActionNode}).inject(this.toolsNode);
  117. var downTextNode = new Element("div", {"styles": this.css.downTextNode, "text": this.lp.operation}).inject(this.operationNode);
  118. var downIconNode = new Element("div", {"styles": this.css.downIconNode}).inject(this.operationNode);
  119. this.uploadNode.addEvents({
  120. "mouseover": function(){this.uploadNode.setStyles(this.css.toolsActionNode_over);}.bind(this),
  121. "mouseout": function(){this.uploadNode.setStyles(this.css.toolsActionNode);}.bind(this),
  122. "click": function(){this.createUploadFile();}.bind(this)
  123. });
  124. this.createFolderNode.addEvents({
  125. "mouseover": function(){this.createFolderNode.setStyles(this.css.toolsActionNode_over);}.bind(this),
  126. "mouseout": function(){this.createFolderNode.setStyles(this.css.toolsActionNode);}.bind(this),
  127. "click": function(){this.createFolder();}.bind(this)
  128. });
  129. this.operationNode.addEvents({
  130. "mouseover": function(){this.operationNode.setStyles(this.css.toolsMenuActionNode_over);}.bind(this),
  131. "mouseout": function(){this.operationNode.setStyles(this.css.toolsMenuActionNode);}.bind(this),
  132. "click": function(){}.bind(this)
  133. });
  134. this.operationMenu = new MWF.xDesktop.Menu(this.operationNode, {
  135. "event": "click",
  136. "style": "fileOperation",
  137. "offsetX": -4,
  138. "offsetY": 4,
  139. "onQueryShow": function(){
  140. this.operationMenu.items.each(function(item){item.setDisable(true);});
  141. if (this.selectedItem){
  142. if (this.selectedItem.type=="folder"){
  143. this.operationMenu.items[0].setText(this.lp.uploadTo+" "+this.selectedItem.data.name+"...");
  144. this.operationMenu.items[0].setDisable(false);
  145. this.operationMenu.items[3].setDisable(false);
  146. this.operationMenu.items[4].setDisable(false);
  147. this.operationMenu.items[7].setDisable(false);
  148. }
  149. if (this.selectedItem.type=="file"){
  150. this.operationMenu.items[0].setText(this.lp.uploadTo);
  151. this.operationMenu.items[0].setDisable(true);
  152. this.operationMenu.items[1].setDisable(false);
  153. this.operationMenu.items[3].setDisable(false);
  154. this.operationMenu.items[4].setDisable(false);
  155. this.operationMenu.items[5].setDisable(false);
  156. this.operationMenu.items[7].setDisable(false);
  157. }
  158. }
  159. }.bind(this)
  160. });
  161. this.operationMenu.load();
  162. var img = this.path+this.options.style+"/operation/upload.png";
  163. this.operationMenu.addMenuItem(this.lp.uploadTo, "click", function(){this.createUploadFile(this.selectedItem);}.bind(this), img);
  164. var img = this.path+this.options.style+"/operation/download.png";
  165. this.operationMenu.addMenuItem(this.lp.download, "click", function(){this.downloadCurrentFile();}.bind(this), img);
  166. this.operationMenu.addMenuLine();
  167. var img = this.path+this.options.style+"/operation/move.png";
  168. this.operationMenu.addMenuItem(this.lp.move, "click", function(){this.moveFileFolder();}.bind(this), img);
  169. var img = this.path+this.options.style+"/operation/rename.png";
  170. this.operationMenu.addMenuItem(this.lp.rename, "click", function(){this.renameFileFolder();}.bind(this), img);
  171. var img = this.path+this.options.style+"/operation/share.png";
  172. this.operationMenu.addMenuItem(this.lp.share, "click", function(){this.shareFile();}.bind(this), img);
  173. this.operationMenu.addMenuLine();
  174. var img = this.path+this.options.style+"/operation/delete.png";
  175. this.operationMenu.addMenuItem(this.lp["delete"], "click", function(e){this.deleteFileFolder(e);}.bind(this), img);
  176. },
  177. downloadCurrentFile: function(){
  178. if (this.selectedItem){
  179. if (this.selectedItem.type=="file"){
  180. this.selectedItem.open();
  181. }
  182. }
  183. },
  184. moveFileFolder: function(){
  185. //move----------
  186. //move----------
  187. //move----------
  188. //move----------
  189. },
  190. renameFileFolder: function(){
  191. this.content.mask({
  192. "style": {
  193. "opacity": 0.7,
  194. "background-color": "#999"
  195. }
  196. });
  197. var renameNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  198. renameNode.position({
  199. relativeTo: this.node,
  200. position: "center"
  201. });
  202. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.rename}).inject(renameNode);
  203. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputName}).inject(renameNode);
  204. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(renameNode);
  205. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode, "value": this.selectedItem.data.name}).inject(inputAreaNode);
  206. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(renameNode);
  207. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  208. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  209. cancelButton.addEvent("click", function(){
  210. this.content.unmask();
  211. renameNode.destroy();
  212. }.bind(this));
  213. okButton.addEvent("click", function(){
  214. if (inputNode.get("value")){
  215. this.selectedItem.data.name = inputNode.get("value");
  216. if (this.selectedItem.type=="folder"){
  217. this.restActions.saveFolder(this.selectedItem.data, function(json){
  218. if (this.currentFolder){
  219. this.currentFolder.clickNode();
  220. }else{
  221. this.topTreeNode.clickNode();
  222. }
  223. this.selectedItem.treeNode.setText(this.selectedItem.data.name);
  224. }.bind(this));
  225. }else{
  226. this.restActions.updateAttachment(this.selectedItem.data, function(json){
  227. if (this.currentFolder){
  228. this.currentFolder.clickNode();
  229. }else{
  230. this.topTreeNode.clickNode();
  231. }
  232. }.bind(this));
  233. }
  234. renameNode.destroy();
  235. this.content.unmask();
  236. }else{
  237. this.notice(this.lp.nameNotEmpty, "error", renameNode);
  238. }
  239. }.bind(this));
  240. },
  241. deleteFileFolder: function(e){
  242. if (this.selectedItem){
  243. var _self = this;
  244. var title = (this.selectedItem.type=="folder") ? this.lp.deleteFolderTitle : this.lp.deleteFileTitle;
  245. var content = (this.selectedItem.type=="folder") ? this.lp.deleteFolder : this.lp.deleteFile;
  246. var size = this.node.getSize();
  247. // var position = this.operationMenu.items[7].item.getPosition(this.operationMenu.items[7].item.getOffsetParent());
  248. var ep = {"event": {"x": (size.x-300)/2, "y": (size.y-120)/2}};
  249. this.confirm("infor", ep, title, content+"("+this.selectedItem.data.name+")", 300, 120, function(){
  250. var callback = function(){
  251. if (this.currentFolder){
  252. this.currentFolder.clickNode();
  253. }else{
  254. this.topTreeNode.clickNode();
  255. }
  256. };
  257. if (_self.selectedItem.type=="folder"){
  258. _self.selectedItem.treeNode.destroy();
  259. _self.restActions.deleteFolder(_self.selectedItem.data.id, callback.bind(_self));
  260. }else{
  261. _self.restActions.deleteFile(_self.selectedItem.data.id, callback.bind(_self));
  262. }
  263. this.close();
  264. }, function(){
  265. this.close();
  266. });
  267. }
  268. },
  269. shareFile: function(){
  270. this.content.mask({
  271. "style": {
  272. "opacity": 0.7,
  273. "background-color": "#999"
  274. }
  275. });
  276. var shareNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  277. shareNode.position({
  278. relativeTo: this.node,
  279. position: "center"
  280. });
  281. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.shareFile}).inject(shareNode);
  282. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.selectShareUser}).inject(shareNode);
  283. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(shareNode);
  284. var inputNode = new Element("input", {"type": "text", "readonly": true, "styles": this.css.shareFileInputNode, "value": this.selectedItem.data.shareList.join(", ")}).inject(inputAreaNode);
  285. inputNode.addEvent("click", function(){
  286. MWF.require("MWF.xApplication.Organization.Selector.Person", function(){
  287. var selector = new MWF.xApplication.Organization.Selector.Person(this.node,{
  288. "names": this.selectedItem.data.shareList,
  289. "onComplete": function(items){
  290. var names = [];
  291. items.each(function(item){
  292. names.push(item.data.name);
  293. });
  294. inputNode.set("value", names.join(", "));
  295. }.bind(this)
  296. });
  297. selector.load();
  298. }.bind(this));
  299. }.bind(this));
  300. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(shareNode);
  301. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  302. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  303. cancelButton.addEvent("click", function(){
  304. this.content.unmask();
  305. shareNode.destroy();
  306. }.bind(this));
  307. okButton.addEvent("click", function(){
  308. this.selectedItem.data.shareList = inputNode.get("value").split(/,\s*/g);
  309. this.restActions.updateAttachment(this.selectedItem.data, function(json){
  310. if (inputNode.get("value")) this.notice(this.lp.fileShareSuccess+inputNode.get("value"), "success", this.content);
  311. }.bind(this));
  312. shareNode.destroy();
  313. this.content.unmask();
  314. }.bind(this));
  315. },
  316. createUploadFile: function(folder){
  317. if (!this.uploadFileAreaNode){
  318. this.uploadFileAreaNode = new Element("div");
  319. var html = "<input name=\"file\" multiple type=\"file\"/>";
  320. this.uploadFileAreaNode.set("html", html);
  321. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  322. this.fileUploadNode.addEvent("change", function(){
  323. var folderId = "";
  324. if (folder){
  325. folderId = folder.data.id;
  326. }else{
  327. folderId = (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "";
  328. }
  329. var files = fileNode.files;
  330. if (files.length){
  331. for (var i = 0; i < files.length; i++) {
  332. var file = files.item(i);
  333. var formData = new FormData();
  334. formData.append('file', file);
  335. formData.append('name', file.name);
  336. formData.append('folder', folderId);
  337. this.restActions.addAttachment(function(){
  338. if (this.currentFolder){
  339. this.currentFolder.clickNode();
  340. }else{
  341. this.topTreeNode.clickNode();
  342. }
  343. }.bind(this), null, formData, file);
  344. }
  345. }
  346. }.bind(this));
  347. }
  348. var fileNode = this.uploadFileAreaNode.getFirst();
  349. fileNode.click();
  350. },
  351. createFolder: function(){
  352. this.content.mask({
  353. "style": {
  354. "opacity": 0.7,
  355. "background-color": "#999"
  356. }
  357. });
  358. var createFolderNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  359. createFolderNode.position({
  360. relativeTo: this.node,
  361. position: "center"
  362. });
  363. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.createFolder}).inject(createFolderNode);
  364. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputFolderName}).inject(createFolderNode);
  365. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(createFolderNode);
  366. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode}).inject(inputAreaNode);
  367. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(createFolderNode);
  368. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  369. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  370. cancelButton.addEvent("click", function(){
  371. this.content.unmask();
  372. createFolderNode.destroy();
  373. }.bind(this));
  374. okButton.addEvent("click", function(){
  375. if (inputNode.get("value")){
  376. var data = {
  377. "name": inputNode.get("value"),
  378. "superior": (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : ""
  379. };
  380. this.restActions.saveFolder(data, function(json){
  381. data.id = json.data.id;
  382. if (this.currentFolder){
  383. var json = {"data":[data]};
  384. this.createTreeNode(json, this.currentFolder);
  385. this.currentFolder.clickNode();
  386. }else{
  387. this.topTreeNode.clickNode();
  388. }
  389. }.bind(this));
  390. createFolderNode.destroy();
  391. this.content.unmask();
  392. }else{
  393. this.notice(this.lp.folderNameNotEmpty, "error", createFolderNode);
  394. }
  395. }.bind(this));
  396. },
  397. loadFolderTreeNode: function(){
  398. this.folderTreeNode = new Element("div", {
  399. "styles": this.css.folderTreeNode
  400. }).inject(this.folderTreeAreaScrollNode);
  401. MWF.require("MWF.widget.Tree", function(){
  402. this.folderTree = new MWF.widget.Tree(this.folderTreeNode, {
  403. "style": "file",
  404. // "onQueryExpand": function(node){
  405. // this.loadFolderTree(node);
  406. // }.bind(this)
  407. });
  408. this.folderTree.load();
  409. var rootData = {
  410. "expand": false,
  411. "title": "root",
  412. "text": "root",
  413. "action": function(treeNode){
  414. this.recordHistory(treeNode);
  415. this.expand(treeNode, function(){
  416. this.loadSub(treeNode);
  417. }.bind(this));
  418. }.bind(this),
  419. "icon": "folder.png"
  420. };
  421. this.topTreeNode = this.folderTree.appendChild(rootData);
  422. this.topTreeNode.clickNode();
  423. // this.loadFolderTree();
  424. }.bind(this));
  425. },
  426. createShareTreeNode: function(json){
  427. json.data.each(function(data){
  428. var nodeData = {
  429. "expand": false,
  430. "title": data.person+"("+data.count+")",
  431. "text": data.person+"("+data.count+")",
  432. "action": function(treeNode){
  433. this.loadShareFile(treeNode);
  434. }.bind(this),
  435. "icon": "folder.png"
  436. };
  437. var treeNode = this.shareTree.appendChild(nodeData);
  438. treeNode.data = data;
  439. }.bind(this));
  440. },
  441. loadShareTreeNode: function(){
  442. this.shareTreeNode = new Element("div", {
  443. "styles": this.css.folderTreeNode
  444. }).inject(this.shareTreeAreaScrollNode);
  445. MWF.require("MWF.widget.Tree", function(){
  446. this.shareTree = new MWF.widget.Tree(this.shareTreeNode, {
  447. "style": "file"
  448. });
  449. this.shareTree.load();
  450. this.restActions.listShare(function(json){
  451. this.createShareTreeNode(json);
  452. // node.setOperateIcon();
  453. }.bind(this), null, false);
  454. // this.loadFolderTree();
  455. }.bind(this));
  456. },
  457. loadShareFile: function(treeNode){
  458. var person = treeNode.data.person;
  459. this.restActions.listShareAttachment(function(json){
  460. this.fileContentAreaNode.empty();
  461. json.data.each(function(file){
  462. new MWF.xApplication.File.ShareAttachment(file, this);
  463. }.bind(this));
  464. }.bind(this), null, person);
  465. },
  466. loadFileContentAreaNode: function(){
  467. this.controller = new MWF.xApplication.File.AttachmentController(this.attachmentContentNode, this, {
  468. "resize": false,
  469. "isSizeChange": false,
  470. })
  471. this.controller.load();
  472. //this.fileContentAreaScrollNode = new Element("div", {
  473. // "styles": this.css.fileContentAreaScrollNode
  474. //}).inject(this.attachmentContentNode);
  475. //
  476. //this.fileContentAreaScrollNode.addEvent("click", function(){
  477. // if (this.selectedItem) this.selectedItem.unSelected();
  478. //}.bind(this));
  479. //
  480. //this.fileContentAreaNode = new Element("div", {
  481. // "styles": this.css.fileContentAreaNode
  482. //}).inject(this.fileContentAreaScrollNode);
  483. //
  484. //this.initDropUpLoad();
  485. },
  486. createTreeNode: function(json, topNode){
  487. json.data.each(function(data){
  488. var nodeData = {
  489. "expand": false,
  490. "title": data.name,
  491. "text": data.name,
  492. "action": function(treeNode){
  493. this.recordHistory(treeNode);
  494. this.expand(treeNode, function(){
  495. this.loadSub(treeNode);
  496. }.bind(this));
  497. }.bind(this),
  498. "icon": "folder.png"
  499. };
  500. var treeNode = topNode.appendChild(nodeData);
  501. treeNode.data = data;
  502. }.bind(this));
  503. },
  504. loadFolderTree: function(node, callback){
  505. if (!node.loaded){
  506. if (node.data){
  507. this.restActions.listFolder(function(json){
  508. this.createTreeNode(json, node);
  509. node.setOperateIcon();
  510. if (callback) callback();
  511. }.bind(this), null, node.data.id, false);
  512. }else{
  513. this.restActions.listTopFolder(function(json){
  514. this.createTreeNode(json, node);
  515. node.setOperateIcon();
  516. if (callback) callback();
  517. }.bind(this), null, false);
  518. }
  519. node.loaded = true;
  520. }else{
  521. if (callback) callback();
  522. }
  523. },
  524. setContentHeight: function(node){
  525. var size = this.node.getSize();
  526. var tSize = this.topNode.getSize();
  527. // var toolSize = this.toolsNode.getSize();
  528. var mtt = this.topNode.getStyle("margin-top").toFloat();
  529. var mbt = this.topNode.getStyle("margin-bottom").toFloat();
  530. // var mttool = this.toolsNode.getStyle("margin-top").toFloat();
  531. // var mbtool = this.toolsNode.getStyle("margin-bottom").toFloat();
  532. var mtc = this.fileContentNode.getStyle("margin-top").toFloat();
  533. var mbc = this.fileContentNode.getStyle("margin-bottom").toFloat();
  534. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  535. this.fileContentNode.setStyle("height", height);
  536. this.attachmentContentNode.setStyle("height", height);
  537. var attTopSzie = this.controller.topNode.getSize();
  538. var y = height-attTopSzie.y;
  539. this.controller.contentScrollNode.setStyle("height", ""+y+"px");
  540. // this.fileContentAreaNode.setStyle("min-height", height);
  541. var tabSize = this.treeTab.tabNodeContainer.getSize();
  542. var height = height-tabSize.y;
  543. this.folderTreeAreaScrollNode.setStyle("height", height);
  544. this.shareTreeAreaScrollNode.setStyle("height", height);
  545. },
  546. expand: function(treeNode, callback){
  547. if (!treeNode.options.expand){
  548. this.loadFolderTree(treeNode, function(){
  549. if (callback) callback();
  550. }.bind(this));
  551. this.folderTree.expand(treeNode);
  552. treeNode.options.expand = true;
  553. treeNode.setOperateIcon();
  554. }else{
  555. if (callback) callback();
  556. }
  557. },
  558. checkHistory: function(){
  559. if (this.history.length>1){
  560. if (this.currentHistory>0){
  561. this.enabledLeftNode();
  562. }else{
  563. this.disabledLeftNode();
  564. }
  565. if (this.currentHistory<this.history.length-1){
  566. this.enabledRightNode();
  567. }else{
  568. this.disabledRightNode();
  569. }
  570. }else{
  571. this.disabledLeftNode();
  572. this.disabledRightNode();
  573. }
  574. },
  575. enabledLeftNode: function(){
  576. this.leftNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/left_enabled.png)");
  577. },
  578. enabledRightNode: function(){
  579. this.rightNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/right_enabled.png)");
  580. },
  581. disabledLeftNode: function(){
  582. this.leftNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/left.png)");
  583. },
  584. disabledRightNode: function(){
  585. this.rightNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/right.png)");
  586. },
  587. leftPath: function(){
  588. if (this.currentHistory>0){
  589. this.currentHistory--;
  590. var treeNode = this.history[this.currentHistory];
  591. if (treeNode){
  592. treeNode.selectNode();
  593. this.loadSub(treeNode);
  594. this.checkHistory();
  595. }
  596. }
  597. },
  598. rightPath: function(){
  599. if (this.currentHistory<this.history.length-1){
  600. this.currentHistory++;
  601. var treeNode = this.history[this.currentHistory];
  602. if (treeNode){
  603. treeNode.selectNode();
  604. this.loadSub(treeNode);
  605. this.checkHistory();
  606. }
  607. }
  608. },
  609. recordHistory: function(treeNode){
  610. if (!this.history.length || this.history[this.history.length-1]!=treeNode){
  611. this.history.push(treeNode);
  612. this.currentHistory = this.history.length-1;
  613. this.checkHistory();
  614. }
  615. },
  616. setPathNode: function(treeNode){
  617. this.pathNode.empty();
  618. var paths = [];
  619. var tmpNode = treeNode;
  620. while (tmpNode){
  621. paths.unshift(tmpNode);
  622. tmpNode = tmpNode.parentNode;
  623. };
  624. var _self = this;
  625. paths.each(function(node, index){
  626. this.expand(node);
  627. var pathNode = new Element("div",{
  628. "styles": this.css.pathItemNode,
  629. "text": (node.data) ? node.data.name : "root",
  630. "events": {
  631. "mouseover": function(){
  632. this.setStyles(_self.css.pathItemNode_over);
  633. },
  634. "mouseout": function(){
  635. this.setStyles(_self.css.pathItemNode);
  636. },
  637. "click": function(){
  638. node.clickNode();
  639. },
  640. }
  641. }).inject(this.pathNode);
  642. if (index<paths.length-1) new Element("div",{"styles": this.css.pathItemIconNode}).inject(this.pathNode);
  643. }.bind(this));
  644. },
  645. loadSub: function(treeNode){
  646. this.setPathNode(treeNode);
  647. //this.fileContentAreaNode.empty();
  648. this.controller.clear();
  649. treeNode.children.each(function(node){
  650. this.controller.addAttachmentFolder(node.data);
  651. //var folder = new MWF.xApplication.File.Folder(node.data, this);
  652. //folder.treeNode = node;
  653. }.bind(this));
  654. this.currentFolder = treeNode;
  655. if (treeNode.data){
  656. this.restActions.listAttachment(function(json){
  657. json.data.each(function(file){
  658. this.controller.addAttachment(file);
  659. //new MWF.xApplication.File.Attachment(file, this);
  660. }.bind(this));
  661. }.bind(this), null, treeNode.data.id);
  662. }else{
  663. this.restActions.listAttachmentTop(function(json){
  664. json.data.each(function(file){
  665. this.controller.addAttachment(file);
  666. //new MWF.xApplication.File.Attachment(file, this);
  667. }.bind(this));
  668. }.bind(this));
  669. }
  670. },
  671. uploadFiles: function(files){
  672. if (!this.uploadFileList) this.uploadFileList = [];
  673. if (!this.uploadFileTotalSize) this.uploadFileTotalSize = 0;
  674. if (!files || !files.length) return;
  675. for (var i = 0; i < files.length && i < 5; i++) {
  676. this.uploadFileList.push(files[i]);
  677. this.uploadFileTotalSize += files[i].size;
  678. }
  679. this.uploadNext();
  680. },
  681. uploadNext: function(){
  682. if (this.uploadFileList.length) {
  683. var nextFile = this.uploadFileList.shift();
  684. if (nextFile){
  685. this.uploadFile(nextFile);
  686. this.uploadNext();
  687. }
  688. }
  689. },
  690. uploadFile: function(file){
  691. var formData = new FormData();
  692. formData.append('file', file);
  693. formData.append('name', file.name);
  694. formData.append('folder', (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "");
  695. // xhr.send(formData);
  696. this.restActions.addAttachment(function(){
  697. if (!this.uploadFileList.length){
  698. if (this.currentFolder){
  699. this.currentFolder.clickNode();
  700. }else{
  701. this.topTreeNode.clickNode();
  702. }
  703. }
  704. }.bind(this), null, formData, file);
  705. },
  706. initDropUpLoad: function(){
  707. this.fileContentAreaNode.addEventListener('drop', function(e){
  708. e.stopPropagation();
  709. e.preventDefault();
  710. if (this.dropUploadInforNode){
  711. this.dropUploadInforNode.destroy();
  712. this.dropUploadInforNode = null;
  713. }
  714. if (e.dataTransfer.types.length<2){
  715. this.uploadFiles(e.dataTransfer.files);
  716. }
  717. }.bind(this), false);
  718. this.fileContentAreaNode.addEventListener('dragover', function(e){
  719. if (e.dataTransfer.types.length<2){
  720. e.stopPropagation();
  721. e.preventDefault();
  722. if (!this.dropUploadInforNode){
  723. this.dropUploadInforNode = new Element("div", {
  724. "styles": this.css.dropUploadInforNode,
  725. "text": this.lp.dropUpload
  726. }).inject(this.node);
  727. this.dropUploadInforNode.position({
  728. relativeTo: this.fileContentAreaNode,
  729. position: "centerBottom",
  730. edge: "centerBottom",
  731. offset: {"x": 0, "y": -100}
  732. });
  733. this.dropUploadInforNode.fade(0.7);
  734. }
  735. }
  736. }.bind(this), false);
  737. this.fileContentAreaNode.addEventListener('dragleave', function(e){
  738. e.stopPropagation();
  739. e.preventDefault();
  740. if (this.dropUploadInforNode) window.setTimeout(function(){
  741. if (this.dropUploadInforNode){
  742. this.dropUploadInforNode.destroy();
  743. this.dropUploadInforNode = null;
  744. }
  745. }.bind(this), 2000);
  746. }.bind(this), false);
  747. }
  748. });
  749. MWF.xApplication.File.Attachment = new Class({
  750. initialize: function(data, file){
  751. this.data = data;
  752. this.file = file;
  753. this.type = "file";
  754. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  755. this.load();
  756. },
  757. getIcon: function(){
  758. var iconName = this.file.icons[this.extension] || this.file.icons.unknow;
  759. return "/x_component_File/$Main/default/file/"+iconName;
  760. },
  761. load: function(){
  762. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  763. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  764. this.imgNode = new Element("div", {
  765. "styles": this.file.css.attachmentImgNode
  766. }).inject(this.iconNode);
  767. this.imgNode.setStyle("background-image", "url("+this.getIcon()+")");
  768. this.textNode = new Element("div", {
  769. "styles": this.file.css.attachmentTextNode,
  770. "text": this.data.name,
  771. "title": this.data.name
  772. }).inject(this.node);
  773. if (this.data.shareList){
  774. if (this.data.shareList.length){
  775. this.shareIconNode = new Element("div", {"styles": this.file.css.shareIconNode}).inject(this.node);
  776. // this.shareIconNode.position({
  777. // relativeTo: this.node,
  778. // position: "centerBottom",
  779. // edge: "centerBottom"
  780. // });
  781. }
  782. }
  783. this.node.inject(this.file.fileContentAreaNode);
  784. this.setEvents();
  785. },
  786. setEvents: function(){
  787. this.node.addEvents({
  788. "mouseover": function(){
  789. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  790. }.bind(this),
  791. "mouseout": function(){
  792. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  793. }.bind(this),
  794. "click": function(e){
  795. this.selected();
  796. e.stop();
  797. e.stopPropagation();
  798. }.bind(this),
  799. "dblclick": function(){
  800. this.open();
  801. }.bind(this),
  802. });
  803. this.node.makeLnk({
  804. "par": {
  805. "icon": this.getIcon(),
  806. "title": this.data.name,
  807. "par": "FileOpen#{\"id\": \""+this.data.id+"\", \"type\": \"file\"}"
  808. }
  809. });
  810. },
  811. selected: function(){
  812. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  813. this.isSelected = true;
  814. this.node.setStyles(this.file.css.attachmentNode_select);
  815. this.file.selectedItem = this;
  816. },
  817. unSelected: function(){
  818. this.isSelected = false;
  819. this.node.setStyles(this.file.css.attachmentNode);
  820. this.file.selectedItem = null;
  821. },
  822. open: function(){
  823. this.file.restActions.getAttachment(this.data.id);
  824. }
  825. });
  826. MWF.xApplication.File.Folder = new Class({
  827. initialize: function(data, file){
  828. this.data = data;
  829. this.file = file;
  830. this.type = "folder";
  831. this.load();
  832. },
  833. getIcon: function(){
  834. return "/x_component_File/$Main/default/file/folder.png";
  835. },
  836. load: function(){
  837. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  838. // this.node.addEvents();
  839. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  840. this.imgNode = new Element("img", {
  841. "styles": this.file.css.attachmentImgNode,
  842. "src": this.getIcon(),
  843. "border": "0"
  844. }).inject(this.iconNode);
  845. this.textNode = new Element("div", {
  846. "styles": this.file.css.attachmentTextNode,
  847. "text": this.data.name
  848. }).inject(this.node);
  849. this.node.inject(this.file.fileContentAreaNode);
  850. this.setEvents();
  851. },
  852. setEvents: function(){
  853. this.node.addEvents({
  854. "mouseover": function(){
  855. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  856. }.bind(this),
  857. "mouseout": function(){
  858. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  859. }.bind(this),
  860. "click": function(e){
  861. this.selected();
  862. e.stop();
  863. e.stopPropagation();
  864. }.bind(this),
  865. "dblclick": function(){
  866. this.open();
  867. }.bind(this),
  868. });
  869. },
  870. selected: function(){
  871. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  872. this.isSelected = true;
  873. this.node.setStyles(this.file.css.attachmentNode_select);
  874. this.file.selectedItem = this;
  875. },
  876. unSelected: function(){
  877. this.isSelected = false;
  878. this.node.setStyles(this.file.css.attachmentNode);
  879. this.file.selectedItem = null;
  880. },
  881. open: function(){
  882. this.treeNode.clickNode();
  883. }
  884. });
  885. MWF.xApplication.File.ShareAttachment = new Class({
  886. Extends: MWF.xApplication.File.Attachment,
  887. initialize: function(data, file){
  888. this.data = data;
  889. this.file = file;
  890. this.type = "share";
  891. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  892. this.load();
  893. }
  894. });