Main.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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(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(url);
  316. });
  317. }.bind(this));
  318. },
  319. downloadCurrentFile: function(){
  320. if (this.selectedItem){
  321. if (this.selectedItem.type=="file"){
  322. this.selectedItem.open();
  323. }
  324. }
  325. },
  326. moveFileFolder: function(){
  327. //move----------
  328. //move----------
  329. //move----------
  330. //move----------
  331. },
  332. renameFileFolder: function(){
  333. this.content.mask({
  334. "style": {
  335. "opacity": 0.7,
  336. "background-color": "#999"
  337. }
  338. });
  339. var renameNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  340. renameNode.position({
  341. relativeTo: this.node,
  342. position: "center"
  343. });
  344. var item = this.controller.selectedAttachments[0];
  345. var treeNode = item.treeNode;
  346. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.rename}).inject(renameNode);
  347. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputName}).inject(renameNode);
  348. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(renameNode);
  349. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode, "value": item.data.name}).inject(inputAreaNode);
  350. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(renameNode);
  351. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  352. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  353. cancelButton.addEvent("click", function(){
  354. this.content.unmask();
  355. renameNode.destroy();
  356. }.bind(this));
  357. okButton.addEvent("click", function(){
  358. if (inputNode.get("value")){
  359. item.data.name = inputNode.get("value");
  360. if (item.type=="folder"){
  361. this.restActions.saveFolder(item.data, function(json){
  362. if (this.currentFolder){
  363. this.currentFolder.clickNode();
  364. }else{
  365. this.topTreeNode.clickNode();
  366. }
  367. treeNode.setText(inputNode.get("value"));
  368. }.bind(this));
  369. }else{
  370. this.restActions.updateAttachment(this.controller.selectedAttachments[0].data.id, this.controller.selectedAttachments[0].data, function(json){
  371. if (this.currentFolder){
  372. this.currentFolder.clickNode();
  373. }else{
  374. this.topTreeNode.clickNode();
  375. }
  376. }.bind(this));
  377. }
  378. renameNode.destroy();
  379. this.content.unmask();
  380. }else{
  381. this.notice(this.lp.nameNotEmpty, "error", renameNode);
  382. }
  383. }.bind(this));
  384. },
  385. deleteAttachments: function(e, node, attachments){
  386. this.deleteFileFolder(e, attachments);
  387. },
  388. deleteFileFolder: function(e, attachments){
  389. if (attachments.length){
  390. var _self = this;
  391. var title = this.lp.deleteFolderFilesTitle;
  392. var content = this.lp.deleteFolderFiles;
  393. if (attachments.length==1){
  394. var title = (attachments[0].type=="folder") ? this.lp.deleteFolderTitle : this.lp.deleteFileTitle;
  395. var content = (attachments[0].type=="folder") ? this.lp.deleteFolder : this.lp.deleteFile;
  396. content = content+"("+attachments[0].data.name+")";
  397. }
  398. var size = this.node.getSize();
  399. // var position = this.operationMenu.items[7].item.getPosition(this.operationMenu.items[7].item.getOffsetParent());
  400. var ep = {"event": {"x": (size.x-300)/2, "y": (size.y-120)/2}};
  401. this.confirm("infor", ep, title, content, 300, 120, function(){
  402. var count = attachments.length;
  403. var current = 0;
  404. var callback = function(){
  405. if (current == count){
  406. if (this.currentFolder){
  407. this.currentFolder.loaded = false;
  408. this.currentFolder.clickNode();
  409. }else{
  410. this.topTreeNode.loaded = false;
  411. this.topTreeNode.clickNode();
  412. }
  413. }
  414. };
  415. attachments.each(function(att){
  416. if (att.type=="folder"){
  417. att.treeNode.destroy();
  418. _self.restActions.deleteFolder(att.data.id, function(){
  419. current++;
  420. callback.apply(_self);
  421. });
  422. }else{
  423. _self.restActions.deleteFile(att.data.id, function(){
  424. current++;
  425. callback.apply(_self);
  426. });
  427. }
  428. });
  429. this.close();
  430. }, function(){
  431. this.close();
  432. });
  433. }
  434. },
  435. shareAttachment: function(){
  436. this.shareFile();
  437. },
  438. shareFile: function(){
  439. this.content.mask({
  440. "style": {
  441. "opacity": 0.7,
  442. "background-color": "#999"
  443. }
  444. });
  445. var shareNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  446. shareNode.position({
  447. relativeTo: this.node,
  448. position: "center"
  449. });
  450. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.shareFile}).inject(shareNode);
  451. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.selectShareUser}).inject(shareNode);
  452. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(shareNode);
  453. var inputNode = new Element("div", {"type": "text", "readonly": true, "styles": this.css.shareFileInputNode}).inject(inputAreaNode);
  454. // if (this.controller.selectedAttachments.length==1) inputNode.set("value", this.controller.selectedAttachments[0].data.shareList.join(", "));
  455. debugger;
  456. inputNode.addEvent("click", function(){
  457. MWF.xDesktop.requireApp("Selector", "Person", function(){
  458. var selector = new MWF.xApplication.Selector.Person(this.node,{
  459. //"values": this.selectedItem.data.shareList,
  460. "onComplete": function(items){
  461. MWF.require("MWF.widget.O2Identity", function(){
  462. var names = [];
  463. var texts = [];
  464. inputNode.empty();
  465. items.each(function(item){
  466. names.push(item.data.distinguishedName);
  467. texts.push(item.data.name);
  468. new MWF.widget.O2Person({"name": item.data.distinguishedName}, inputNode, {"style": "xform"})
  469. });
  470. inputNode.store("texts", texts);
  471. inputNode.set("value", names.join(", "));
  472. }.bind(this));
  473. }.bind(this)
  474. });
  475. selector.load();
  476. }.bind(this));
  477. }.bind(this));
  478. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(shareNode);
  479. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  480. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  481. cancelButton.addEvent("click", function(){
  482. this.content.unmask();
  483. shareNode.destroy();
  484. }.bind(this));
  485. okButton.addEvent("click", function(){
  486. var count = this.controller.selectedAttachments.length;
  487. var current = 0;
  488. var callback = function(){
  489. if (current === count){
  490. if (inputNode.get("value")) this.notice(this.lp.fileShareSuccess+inputNode.retrieve("texts", []).join(","), "success", this.content);
  491. shareNode.destroy();
  492. this.content.unmask();
  493. }
  494. };
  495. this.controller.selectedAttachments.each(function(att){
  496. if (att.type!="folder"){
  497. att.data.shareList = inputNode.get("value").split(/,\s*/g);
  498. this.restActions.updateAttachment(att.data.id, att.data, function(json){
  499. current++;
  500. callback.apply(this);
  501. }.bind(this));
  502. }else{
  503. current++;
  504. callback.apply(this);
  505. }
  506. }.bind(this));
  507. }.bind(this));
  508. },
  509. sendAttachment: function(){
  510. this.sendFile();
  511. },
  512. sendFile: function(){
  513. this.content.mask({
  514. "style": {
  515. "opacity": 0.7,
  516. "background-color": "#999"
  517. }
  518. });
  519. var shareNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  520. shareNode.position({
  521. relativeTo: this.node,
  522. position: "center"
  523. });
  524. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.sendFile}).inject(shareNode);
  525. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.selectSendUser}).inject(shareNode);
  526. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(shareNode);
  527. var inputNode = new Element("div", {"type": "text", "readonly": true, "styles": this.css.shareFileInputNode}).inject(inputAreaNode);
  528. // if (this.controller.selectedAttachments.length==1) inputNode.set("value", this.controller.selectedAttachments[0].data.shareList.join(", "));
  529. inputNode.addEvent("click", function(){
  530. MWF.xDesktop.requireApp("Selector", "Person", function(){
  531. var selector = new MWF.xApplication.Selector.Person(this.node,{
  532. //"values": this.selectedItem.data.shareList,
  533. "onComplete": function(items){
  534. MWF.require("MWF.widget.O2Identity", function(){
  535. var names = [];
  536. var texts = [];
  537. inputNode.empty();
  538. items.each(function(item){
  539. names.push(item.data.distinguishedName);
  540. texts.push(item.data.name);
  541. new MWF.widget.O2Person({"name": item.data.distinguishedName}, inputNode, {"style": "xform"})
  542. });
  543. //inputNode.set("text", texts.join(", "));
  544. inputNode.store("texts", texts);
  545. inputNode.set("value", names.join(", "));
  546. }.bind(this));
  547. // var names = [];
  548. // items.each(function(item){
  549. // names.push(item.data.distinguishedName);
  550. // });
  551. // inputNode.set("value", names.join(", "));
  552. }.bind(this)
  553. });
  554. selector.load();
  555. }.bind(this));
  556. }.bind(this));
  557. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(shareNode);
  558. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  559. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  560. cancelButton.addEvent("click", function(){
  561. this.content.unmask();
  562. shareNode.destroy();
  563. }.bind(this));
  564. okButton.addEvent("click", function(){
  565. var count = this.controller.selectedAttachments.length;
  566. var current = 0;
  567. var callback = function(){
  568. if (current == count){
  569. if (inputNode.get("value")) this.notice(this.lp.fileSendSuccess+inputNode.retrieve("texts", []).join(","), "success", this.content);
  570. shareNode.destroy();
  571. this.content.unmask();
  572. }
  573. };
  574. this.controller.selectedAttachments.each(function(att){
  575. if (att.type!="folder"){
  576. att.data.editorList = inputNode.get("value").split(/,\s*/g);
  577. this.restActions.updateAttachment(att.data.id, att.data, function(json){
  578. current++;
  579. callback.apply(this);
  580. }.bind(this));
  581. }else{
  582. current++;
  583. callback.apply(this);
  584. }
  585. }.bind(this));
  586. }.bind(this));
  587. },
  588. uploadAttachment: function(e, node){
  589. debugger;
  590. folderId = (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "";
  591. this.controller.doUploadAttachment(null, this.restActions.action, "addAttachment", {"folder": folderId || "(0)"}, function(){
  592. if (this.currentFolder){
  593. this.currentFolder.clickNode();
  594. }else{
  595. this.topTreeNode.clickNode();
  596. }
  597. }.bind(this));
  598. },
  599. replaceAttachment: function(e, node, attachment){
  600. var fileId = attachment.data.id;
  601. debugger;
  602. this.controller.doReplaceAttachment(null, this.restActions.action, "updateAttachmentData", {"id": fileId}, function(){
  603. if (this.currentFolder){
  604. this.currentFolder.clickNode();
  605. }else{
  606. this.topTreeNode.clickNode();
  607. }
  608. }.bind(this));
  609. //this.replaceUploadFile(attachment);
  610. },
  611. // replaceUploadFile: function(attachment){
  612. // if (!this.replaceFileAreaNode){
  613. // this.replaceFileAreaNode = new Element("div");
  614. // var html = "<input name=\"file\" multiple type=\"file\"/>";
  615. // this.replaceFileAreaNode.set("html", html);
  616. //
  617. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  618. // this.fileReplaceNode.addEvent("change", function(){
  619. // var fileId = attachment.data.id;
  620. //
  621. // var files = fileNode.files;
  622. // if (files.length){
  623. // var count = files.length;
  624. // var current = 0;
  625. // var callback = function(){
  626. // if (current == count){
  627. // if (this.currentFolder){
  628. // this.currentFolder.clickNode();
  629. // }else{
  630. // this.topTreeNode.clickNode();
  631. // }
  632. // }
  633. // };
  634. // for (var i = 0; i < files.length; i++) {
  635. // var file = files.item(i);
  636. //
  637. // var formData = new FormData();
  638. // formData.append('file', file);
  639. //
  640. // this.restActions.updateAttachmentData(fileId, formData, file, function(){
  641. // current++;
  642. // callback.apply(this);
  643. // }.bind(this));
  644. // }
  645. // }
  646. //
  647. // }.bind(this));
  648. // }
  649. // this.fileReplaceNode.set("accept", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
  650. // this.fileReplaceNode.set("multiple", false);
  651. //
  652. // var fileNode = this.replaceFileAreaNode.getFirst();
  653. // fileNode.set("accept", "*/*");
  654. // fileNode.click();
  655. // },
  656. createFolder: function(){
  657. this.content.mask({
  658. "style": {
  659. "opacity": 0.7,
  660. "background-color": "#999"
  661. }
  662. });
  663. var createFolderNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  664. createFolderNode.position({
  665. relativeTo: this.node,
  666. position: "center"
  667. });
  668. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.createFolder}).inject(createFolderNode);
  669. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputFolderName}).inject(createFolderNode);
  670. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(createFolderNode);
  671. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode}).inject(inputAreaNode);
  672. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(createFolderNode);
  673. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  674. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  675. cancelButton.addEvent("click", function(){
  676. this.content.unmask();
  677. createFolderNode.destroy();
  678. }.bind(this));
  679. okButton.addEvent("click", function(){
  680. if (inputNode.get("value")){
  681. var data = {
  682. "name": inputNode.get("value"),
  683. "superior": (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : ""
  684. };
  685. debugger;
  686. this.restActions.saveFolder(data, function(json){
  687. data.id = json.data.id;
  688. this.restActions.getFolder(data.id, function(folderJson){
  689. if (this.currentFolder){
  690. var json = {"data":[folderJson.data]};
  691. this.createTreeNode(json, this.currentFolder);
  692. this.currentFolder.clickNode();
  693. }else{
  694. this.topTreeNode.clickNode();
  695. }
  696. }.bind(this));
  697. }.bind(this));
  698. createFolderNode.destroy();
  699. this.content.unmask();
  700. }else{
  701. this.notice(this.lp.folderNameNotEmpty, "error", createFolderNode);
  702. }
  703. }.bind(this));
  704. },
  705. getAttachmentUrl: function(attachment, callback){
  706. this.restActions.getFileUrl(attachment.data.id, callback);
  707. },
  708. loadFolderTreeNode: function(){
  709. this.folderTreeNode = new Element("div", {
  710. "styles": this.css.folderTreeNode
  711. }).inject(this.folderTreeAreaScrollNode);
  712. // MWF.require("MWF.widget.Tree", function(){
  713. this.folderTree = new MWF.widget.Tree(this.folderTreeNode, {
  714. "style": "file"
  715. // "onQueryExpand": function(node){
  716. // this.loadFolderTree(node);
  717. // }.bind(this)
  718. });
  719. this.folderTree.load();
  720. var rootData = {
  721. "expand": false,
  722. "title": "root",
  723. "text": "root",
  724. "action": function(treeNode){
  725. this.recordHistory(treeNode);
  726. this.expand(treeNode, function(){
  727. this.loadSub(treeNode);
  728. }.bind(this));
  729. }.bind(this),
  730. "icon": "folder.png"
  731. };
  732. this.topTreeNode = this.folderTree.appendChild(rootData);
  733. //this.topTreeNode.clickNode();
  734. // this.loadFolderTree();
  735. // }.bind(this));
  736. },
  737. createShareTreeNode: function(json){
  738. json.data.each(function(data){
  739. var name = data.name.substring(0, data.name.indexOf("@"));
  740. var nodeData = {
  741. "expand": false,
  742. "title": name+"("+data.count+")",
  743. "text": name+"("+data.count+")",
  744. "action": function(treeNode){
  745. this.loadShareFile(treeNode);
  746. }.bind(this),
  747. "icon": "folder.png"
  748. };
  749. var treeNode = this.shareTree.appendChild(nodeData);
  750. treeNode.data = data;
  751. }.bind(this));
  752. },
  753. loadShareTreeNode: function(){
  754. this.shareTreeNode = new Element("div", {
  755. "styles": this.css.folderTreeNode
  756. }).inject(this.shareTreeAreaScrollNode);
  757. // MWF.require("MWF.widget.Tree", function(){
  758. this.shareTree = new MWF.widget.Tree(this.shareTreeNode, {
  759. "style": "file"
  760. });
  761. this.shareTree.load();
  762. this.restActions.listShare(function(json){
  763. this.createShareTreeNode(json);
  764. // node.setOperateIcon();
  765. if (this.shareTree.loadCallback) this.shareTree.loadCallback.apply(this);
  766. }.bind(this), null, false);
  767. // this.loadFolderTree();
  768. // }.bind(this));
  769. },
  770. loadShareFile: function(treeNode){
  771. var person = treeNode.data.name;
  772. this.restActions.listShareAttachment(person, function(json){
  773. //this.fileContentAreaNode.empty();
  774. this.controller.clear();
  775. json.data.each(function(file){
  776. this.controller.addAttachment(file);
  777. //new MWF.xApplication.File.ShareAttachment(file, this);
  778. }.bind(this));
  779. }.bind(this));
  780. },
  781. createEditorTreeNode: function(json){
  782. json.data.each(function(data){
  783. var name = MWF.name.cn(data.name);
  784. var nodeData = {
  785. "expand": false,
  786. "title": name+"("+data.count+")",
  787. "text": name+"("+data.count+")",
  788. "action": function(treeNode){
  789. this.loadEditorFile(treeNode);
  790. }.bind(this),
  791. "icon": "folder.png"
  792. };
  793. var treeNode = this.editorTree.appendChild(nodeData);
  794. treeNode.data = data;
  795. }.bind(this));
  796. },
  797. loadEditorTreeNode: function(){
  798. this.editorTreeNode = new Element("div", {
  799. "styles": this.css.folderTreeNode
  800. }).inject(this.editorTreeAreaScrollNode);
  801. // MWF.require("MWF.widget.Tree", function(){
  802. this.editorTree = new MWF.widget.Tree(this.editorTreeNode, {
  803. "style": "file"
  804. });
  805. this.editorTree.load();
  806. this.restActions.listEditor(function(json){
  807. this.createEditorTreeNode(json);
  808. // node.setOperateIcon();
  809. if (this.editorTree.loadCallback) this.editorTree.loadCallback.apply(this);
  810. }.bind(this), null, false);
  811. // this.loadFolderTree();
  812. // }.bind(this));
  813. },
  814. loadEditorFile: function(treeNode){
  815. var person = treeNode.data.name;
  816. this.restActions.listEditorAttachment(person, function(json){
  817. //this.fileContentAreaNode.empty();
  818. this.controller.clear();
  819. json.data.each(function(file){
  820. this.controller.addAttachment(file);
  821. //new MWF.xApplication.File.ShareAttachment(file, this);
  822. }.bind(this));
  823. }.bind(this));
  824. },
  825. loadFileContentAreaNode: function(){
  826. this.controller = new MWF.xApplication.File.AttachmentController(this.attachmentContentNode, this, {
  827. "resize": false,
  828. "isSizeChange": false,
  829. })
  830. this.controller.load();
  831. //this.fileContentAreaScrollNode = new Element("div", {
  832. // "styles": this.css.fileContentAreaScrollNode
  833. //}).inject(this.attachmentContentNode);
  834. //
  835. //this.fileContentAreaScrollNode.addEvent("click", function(){
  836. // if (this.selectedItem) this.selectedItem.unSelected();
  837. //}.bind(this));
  838. //
  839. //this.fileContentAreaNode = new Element("div", {
  840. // "styles": this.css.fileContentAreaNode
  841. //}).inject(this.fileContentAreaScrollNode);
  842. //
  843. //this.initDropUpLoad();
  844. },
  845. createTreeNode: function(json, topNode){
  846. json.data.each(function(data){
  847. var nodeData = {
  848. "expand": false,
  849. "title": data.name,
  850. "text": data.name,
  851. "action": function(treeNode){
  852. this.recordHistory(treeNode);
  853. this.expand(treeNode, function(){
  854. this.loadSub(treeNode);
  855. }.bind(this));
  856. }.bind(this),
  857. "icon": "folder.png"
  858. };
  859. var treeNode = topNode.appendChild(nodeData);
  860. treeNode.data = data;
  861. }.bind(this));
  862. },
  863. loadFolderTree: function(node, callback){
  864. if (!node.loaded){
  865. node.loaded = true;
  866. if (node.data){
  867. this.restActions.listFolder(node.data.id, function(json){
  868. this.createTreeNode(json, node);
  869. node.setOperateIcon();
  870. if (callback) callback();
  871. }.bind(this), null, false);
  872. }else{
  873. this.restActions.listTopFolder(function(json){
  874. this.createTreeNode(json, node);
  875. node.setOperateIcon();
  876. if (callback) callback();
  877. }.bind(this), null, false);
  878. }
  879. }else{
  880. if (callback) callback();
  881. }
  882. },
  883. setContentHeight: function(node){
  884. var size = this.node.getSize();
  885. var tSize = this.topNode.getSize();
  886. // var toolSize = this.toolsNode.getSize();
  887. var mtt = this.topNode.getStyle("margin-top").toFloat();
  888. var mbt = this.topNode.getStyle("margin-bottom").toFloat();
  889. // var mttool = this.toolsNode.getStyle("margin-top").toFloat();
  890. // var mbtool = this.toolsNode.getStyle("margin-bottom").toFloat();
  891. var mtc = this.fileContentNode.getStyle("margin-top").toFloat();
  892. var mbc = this.fileContentNode.getStyle("margin-bottom").toFloat();
  893. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  894. this.fileContentNode.setStyle("height", height);
  895. this.attachmentContentNode.setStyle("height", height);
  896. var attTopSzie = this.controller.topNode.getSize();
  897. var y = height-attTopSzie.y;
  898. this.controller.contentScrollNode.setStyle("height", ""+y+"px");
  899. // this.fileContentAreaNode.setStyle("min-height", height);
  900. var tabSize = this.treeTab.tabNodeContainer.getSize();
  901. var height = height-tabSize.y;
  902. this.folderTreeAreaScrollNode.setStyle("height", height);
  903. this.shareTreeAreaScrollNode.setStyle("height", height);
  904. this.editorTreeAreaScrollNode.setStyle("height", height);
  905. },
  906. expand: function(treeNode, callback){
  907. if (!treeNode.options.expand){
  908. this.loadFolderTree(treeNode, function(){
  909. if (callback) callback();
  910. }.bind(this));
  911. this.folderTree.expand(treeNode);
  912. treeNode.options.expand = true;
  913. treeNode.setOperateIcon();
  914. }else{
  915. if (callback) callback();
  916. }
  917. },
  918. checkHistory: function(){
  919. if (this.history.length>1){
  920. if (this.currentHistory>0){
  921. this.enabledLeftNode();
  922. }else{
  923. this.disabledLeftNode();
  924. }
  925. if (this.currentHistory<this.history.length-1){
  926. this.enabledRightNode();
  927. }else{
  928. this.disabledRightNode();
  929. }
  930. }else{
  931. this.disabledLeftNode();
  932. this.disabledRightNode();
  933. }
  934. },
  935. enabledLeftNode: function(){
  936. this.leftNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/left_enabled.png)");
  937. },
  938. enabledRightNode: function(){
  939. this.rightNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/right_enabled.png)");
  940. },
  941. disabledLeftNode: function(){
  942. this.leftNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/left.png)");
  943. },
  944. disabledRightNode: function(){
  945. this.rightNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/right.png)");
  946. },
  947. leftPath: function(){
  948. if (this.currentHistory>0){
  949. this.currentHistory--;
  950. var treeNode = this.history[this.currentHistory];
  951. if (treeNode){
  952. treeNode.selectNode();
  953. this.loadSub(treeNode);
  954. this.checkHistory();
  955. }
  956. }
  957. },
  958. rightPath: function(){
  959. if (this.currentHistory<this.history.length-1){
  960. this.currentHistory++;
  961. var treeNode = this.history[this.currentHistory];
  962. if (treeNode){
  963. treeNode.selectNode();
  964. this.loadSub(treeNode);
  965. this.checkHistory();
  966. }
  967. }
  968. },
  969. recordHistory: function(treeNode){
  970. if (!this.history.length || this.history[this.history.length-1]!=treeNode){
  971. this.history.push(treeNode);
  972. this.currentHistory = this.history.length-1;
  973. this.checkHistory();
  974. }
  975. },
  976. setPathNode: function(treeNode){
  977. this.pathNode.empty();
  978. var paths = [];
  979. var tmpNode = treeNode;
  980. while (tmpNode){
  981. paths.unshift(tmpNode);
  982. tmpNode = tmpNode.parentNode;
  983. };
  984. var _self = this;
  985. paths.each(function(node, index){
  986. this.expand(node);
  987. var pathNode = new Element("div",{
  988. "styles": this.css.pathItemNode,
  989. "text": (node.data) ? node.data.name : "root",
  990. "events": {
  991. "mouseover": function(){
  992. this.setStyles(_self.css.pathItemNode_over);
  993. },
  994. "mouseout": function(){
  995. this.setStyles(_self.css.pathItemNode);
  996. },
  997. "click": function(){
  998. node.clickNode();
  999. }
  1000. }
  1001. }).inject(this.pathNode);
  1002. if (index<paths.length-1) new Element("div",{"styles": this.css.pathItemIconNode}).inject(this.pathNode);
  1003. }.bind(this));
  1004. },
  1005. loadSub: function(treeNode){
  1006. this.setPathNode(treeNode);
  1007. //this.fileContentAreaNode.empty();
  1008. this.controller.clear();
  1009. treeNode.children.each(function(node){
  1010. var folder = this.controller.addAttachmentFolder(node.data);
  1011. folder.treeNode = node;
  1012. //var folder = new MWF.xApplication.File.Folder(node.data, this);
  1013. //folder.treeNode = node;
  1014. }.bind(this));
  1015. this.currentFolder = treeNode;
  1016. if (treeNode.data){
  1017. this.restActions.listAttachment(treeNode.data.id, function(json){
  1018. json.data.each(function(file){
  1019. this.controller.addAttachment(file);
  1020. //new MWF.xApplication.File.Attachment(file, this);
  1021. }.bind(this));
  1022. }.bind(this));
  1023. }else{
  1024. this.restActions.listAttachmentTop(function(json){
  1025. json.data.each(function(file){
  1026. this.controller.addAttachment(file);
  1027. //new MWF.xApplication.File.Attachment(file, this);
  1028. }.bind(this));
  1029. }.bind(this));
  1030. }
  1031. },
  1032. uploadFiles: function(files){
  1033. if (!this.uploadFileList) this.uploadFileList = [];
  1034. if (!this.uploadFileTotalSize) this.uploadFileTotalSize = 0;
  1035. if (!files || !files.length) return;
  1036. for (var i = 0; i < files.length && i < 5; i++) {
  1037. this.uploadFileList.push(files[i]);
  1038. this.uploadFileTotalSize += files[i].size;
  1039. }
  1040. this.uploadNext();
  1041. },
  1042. uploadNext: function(){
  1043. if (this.uploadFileList.length) {
  1044. var nextFile = this.uploadFileList.shift();
  1045. if (nextFile){
  1046. this.uploadFile(nextFile);
  1047. this.uploadNext();
  1048. }
  1049. }
  1050. },
  1051. uploadFile: function(file){
  1052. var formData = new FormData();
  1053. formData.append('file', file);
  1054. formData.append('name', file.name);
  1055. formData.append('folder', (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "");
  1056. // xhr.send(formData);
  1057. this.restActions.addAttachment((this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "(0)", formData, file, function(){
  1058. if (!this.uploadFileList.length){
  1059. if (this.currentFolder){
  1060. this.currentFolder.clickNode();
  1061. }else{
  1062. this.topTreeNode.clickNode();
  1063. }
  1064. }
  1065. }.bind(this));
  1066. },
  1067. initDropUpLoad: function(){
  1068. this.fileContentAreaNode.addEventListener('drop', function(e){
  1069. e.stopPropagation();
  1070. e.preventDefault();
  1071. if (this.dropUploadInforNode){
  1072. this.dropUploadInforNode.destroy();
  1073. this.dropUploadInforNode = null;
  1074. }
  1075. if (e.dataTransfer.types.length<2){
  1076. this.uploadFiles(e.dataTransfer.files);
  1077. }
  1078. }.bind(this), false);
  1079. this.fileContentAreaNode.addEventListener('dragover', function(e){
  1080. if (e.dataTransfer.types.length<2){
  1081. e.stopPropagation();
  1082. e.preventDefault();
  1083. if (!this.dropUploadInforNode){
  1084. this.dropUploadInforNode = new Element("div", {
  1085. "styles": this.css.dropUploadInforNode,
  1086. "text": this.lp.dropUpload
  1087. }).inject(this.node);
  1088. this.dropUploadInforNode.position({
  1089. relativeTo: this.fileContentAreaNode,
  1090. position: "centerBottom",
  1091. edge: "centerBottom",
  1092. offset: {"x": 0, "y": -100}
  1093. });
  1094. this.dropUploadInforNode.fade(0.7);
  1095. }
  1096. }
  1097. }.bind(this), false);
  1098. this.fileContentAreaNode.addEventListener('dragleave', function(e){
  1099. e.stopPropagation();
  1100. e.preventDefault();
  1101. if (this.dropUploadInforNode) window.setTimeout(function(){
  1102. if (this.dropUploadInforNode){
  1103. this.dropUploadInforNode.destroy();
  1104. this.dropUploadInforNode = null;
  1105. }
  1106. }.bind(this), 2000);
  1107. }.bind(this), false);
  1108. }
  1109. });
  1110. MWF.xApplication.File.Attachment = new Class({
  1111. initialize: function(data, file){
  1112. this.data = data;
  1113. this.file = file;
  1114. this.type = "file";
  1115. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  1116. this.load();
  1117. },
  1118. getIcon: function(){
  1119. var iconName = this.file.icons[this.extension] || this.file.icons.unknow;
  1120. return "/x_component_File/$Main/default/file/"+iconName;
  1121. },
  1122. load: function(){
  1123. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  1124. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  1125. this.imgNode = new Element("div", {
  1126. "styles": this.file.css.attachmentImgNode
  1127. }).inject(this.iconNode);
  1128. this.imgNode.setStyle("background-image", "url("+this.getIcon()+")");
  1129. this.textNode = new Element("div", {
  1130. "styles": this.file.css.attachmentTextNode,
  1131. "text": this.data.name,
  1132. "title": this.data.name
  1133. }).inject(this.node);
  1134. if (this.data.shareList){
  1135. if (this.data.shareList.length){
  1136. this.shareIconNode = new Element("div", {"styles": this.file.css.shareIconNode}).inject(this.node);
  1137. // this.shareIconNode.position({
  1138. // relativeTo: this.node,
  1139. // position: "centerBottom",
  1140. // edge: "centerBottom"
  1141. // });
  1142. }
  1143. }
  1144. this.node.inject(this.file.fileContentAreaNode);
  1145. this.setEvents();
  1146. },
  1147. setEvents: function(){
  1148. this.node.addEvents({
  1149. "mouseover": function(){
  1150. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  1151. }.bind(this),
  1152. "mouseout": function(){
  1153. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  1154. }.bind(this),
  1155. "click": function(e){
  1156. this.selected();
  1157. e.stop();
  1158. e.stopPropagation();
  1159. }.bind(this),
  1160. "dblclick": function(){
  1161. this.open();
  1162. }.bind(this)
  1163. });
  1164. this.node.makeLnk({
  1165. "par": {
  1166. "icon": this.getIcon(),
  1167. "title": this.data.name,
  1168. "par": "FileOpen#{\"id\": \""+this.data.id+"\", \"type\": \"file\"}"
  1169. }
  1170. });
  1171. },
  1172. selected: function(){
  1173. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  1174. this.isSelected = true;
  1175. this.node.setStyles(this.file.css.attachmentNode_select);
  1176. this.file.selectedItem = this;
  1177. },
  1178. unSelected: function(){
  1179. this.isSelected = false;
  1180. this.node.setStyles(this.file.css.attachmentNode);
  1181. this.file.selectedItem = null;
  1182. },
  1183. open: function(){
  1184. this.file.restActions.getAttachment(this.data.id);
  1185. }
  1186. });
  1187. MWF.xApplication.File.Folder = new Class({
  1188. initialize: function(data, file){
  1189. this.data = data;
  1190. this.file = file;
  1191. this.type = "folder";
  1192. this.load();
  1193. },
  1194. getIcon: function(){
  1195. return "/x_component_File/$Main/default/file/folder.png";
  1196. },
  1197. load: function(){
  1198. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  1199. // this.node.addEvents();
  1200. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  1201. this.imgNode = new Element("img", {
  1202. "styles": this.file.css.attachmentImgNode,
  1203. "src": this.getIcon(),
  1204. "border": "0"
  1205. }).inject(this.iconNode);
  1206. this.textNode = new Element("div", {
  1207. "styles": this.file.css.attachmentTextNode,
  1208. "text": this.data.name
  1209. }).inject(this.node);
  1210. this.node.inject(this.file.fileContentAreaNode);
  1211. this.setEvents();
  1212. },
  1213. setEvents: function(){
  1214. this.node.addEvents({
  1215. "mouseover": function(){
  1216. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  1217. }.bind(this),
  1218. "mouseout": function(){
  1219. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  1220. }.bind(this),
  1221. "click": function(e){
  1222. this.selected();
  1223. e.stop();
  1224. e.stopPropagation();
  1225. }.bind(this),
  1226. "dblclick": function(){
  1227. this.open();
  1228. }.bind(this)
  1229. });
  1230. },
  1231. selected: function(){
  1232. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  1233. this.isSelected = true;
  1234. this.node.setStyles(this.file.css.attachmentNode_select);
  1235. this.file.selectedItem = this;
  1236. },
  1237. unSelected: function(){
  1238. this.isSelected = false;
  1239. this.node.setStyles(this.file.css.attachmentNode);
  1240. this.file.selectedItem = null;
  1241. },
  1242. open: function(){
  1243. this.treeNode.clickNode();
  1244. }
  1245. });
  1246. MWF.xApplication.File.ShareAttachment = new Class({
  1247. Extends: MWF.xApplication.File.Attachment,
  1248. initialize: function(data, file){
  1249. this.data = data;
  1250. this.file = file;
  1251. this.type = "share";
  1252. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  1253. this.load();
  1254. }
  1255. });