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