Main.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  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. },
  18. loadApplication: function(callback){
  19. this.history = [];
  20. this.currentHistory = 1;
  21. this.currentFolder = null;
  22. this.restActions = new MWF.xApplication.File.Actions.RestActions();
  23. MWF.getJSON("/x_component_File/$Main/icon.json", function(json){
  24. this.icons = json;
  25. }.bind(this), false, false);
  26. this.createNode();
  27. this.loadApplicationContent();
  28. if (callback) callback();
  29. },
  30. createNode: function(){
  31. this.content.setStyle("overflow", "hidden");
  32. this.node = new Element("div", {
  33. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  34. }).inject(this.content);
  35. },
  36. loadApplicationContent: function(){
  37. this.loadTop();
  38. // this.loadTools();
  39. this.fileContentNode = new Element("div", {"styles": this.css.fileContentNode}).inject(this.node);
  40. this.folderContentNode = new Element("div", {"styles": this.css.folderContentNode}).inject(this.fileContentNode);
  41. this.attachmentContentNode = new Element("div", {"styles": this.css.attachmentContentNode}).inject(this.fileContentNode);
  42. this.resizeContentNode = new Element("div", {"styles": this.css.resizeContentNode}).inject(this.folderContentNode);
  43. this.folderTreeAreaNode = new Element("div", {
  44. "styles": this.css.folderTreeAreaNode
  45. }).inject(this.folderContentNode);
  46. this.folderTreeAreaScrollNode = new Element("div", {
  47. "styles": this.css.folderTreeAreaScrollNode
  48. }).inject(this.folderContentNode);
  49. this.shareTreeAreaScrollNode = new Element("div", {
  50. "styles": this.css.folderTreeAreaScrollNode
  51. }).inject(this.folderContentNode);
  52. this.editorTreeAreaScrollNode = new Element("div", {
  53. "styles": this.css.folderTreeAreaScrollNode
  54. }).inject(this.folderContentNode);
  55. this.loadFileContentAreaNode();
  56. this.loadFolderTreeNode();
  57. this.loadShareTreeNode();
  58. this.loadEditorTreeNode();
  59. this.shareTree.loadCallback = function(){
  60. if (this.shareTab.isShow){
  61. if (this.status){
  62. if (this.status.node){
  63. var found = false;
  64. for (var i=0; i<this.shareTree.children.length; i++){
  65. if (this.shareTree.children[i].data.name == this.status.node){
  66. this.shareTree.children[i].clickNode();
  67. found = true;
  68. break;
  69. }
  70. }
  71. if (!found) this.shareTree.firstChild.clickNode();
  72. }else{
  73. this.shareTree.firstChild.clickNode();
  74. }
  75. }else{
  76. this.shareTree.firstChild.clickNode();
  77. }
  78. }
  79. }
  80. this.editorTree.loadCallback = function(){
  81. if (this.editorTab.isShow){
  82. if (this.status){
  83. if (this.status.node){
  84. var found = false;
  85. for (var i=0; i<this.editorTree.children.length; i++){
  86. if (this.editorTree.children[i].data.name == this.status.node){
  87. this.editorTree.children[i].clickNode();
  88. found = true;
  89. break;
  90. }
  91. }
  92. if (!found) this.editorTree.firstChild.clickNode();
  93. }else{
  94. this.editorTree.firstChild.clickNode();
  95. }
  96. }else{
  97. this.editorTree.firstChild.clickNode();
  98. }
  99. }
  100. }
  101. this.treeResize = new Drag(this.resizeContentNode,{
  102. "snap": 1,
  103. "onStart": function(el, e){
  104. //alert(e.event.clientX);
  105. var x = e.event.clientX;
  106. var y = e.event.clientY;
  107. el.store("position", {"x": x, "y": y});
  108. var size = this.folderContentNode.getSize();
  109. el.store("initialWidth", size.x);
  110. }.bind(this),
  111. "onDrag": function(el, e){
  112. var x = e.event.clientX;
  113. // var y = e.event.y;
  114. var bodySize = this.content.getSize();
  115. var position = el.retrieve("position");
  116. var initialWidth = el.retrieve("initialWidth").toFloat();
  117. var dx = x.toFloat() - position.x.toFloat();
  118. var width = initialWidth+dx;
  119. if (width> bodySize.x/2) width = bodySize.x/2;
  120. if (width<200) width = 200;
  121. this.attachmentContentNode.setStyle("margin-left", width);
  122. this.folderContentNode.setStyle("width", width);
  123. }.bind(this)
  124. });
  125. MWF.require("MWF.widget.Tab", function(){
  126. this.treeTab = new MWF.widget.Tab(this.folderTreeAreaNode, {"style": "processlayout"});
  127. this.treeTab.load();
  128. this.fileTabe = this.treeTab.addTab(this.folderTreeAreaScrollNode, this.lp.myFiles, false);
  129. this.shareTab = this.treeTab.addTab(this.shareTreeAreaScrollNode, this.lp.shareFiles, false);
  130. this.editorTab = this.treeTab.addTab(this.editorTreeAreaScrollNode, this.lp.editorFiles, false);
  131. this.fileTabe.addEvent("show", function(){
  132. if (this.folderTree.currentNode){
  133. this.folderTree.currentNode.clickNode();
  134. }else{
  135. if (this.folderTree.firstChild){
  136. this.folderTree.firstChild.clickNode();
  137. }else{
  138. if (this.controller) this.controller.clear();
  139. }
  140. }
  141. this.checkControllerActionsFile();
  142. }.bind(this));
  143. this.shareTab.addEvent("show", function(){
  144. if (this.shareTree.currentNode){
  145. this.shareTree.currentNode.clickNode();
  146. }else{
  147. if (this.shareTree.firstChild){
  148. this.shareTree.firstChild.clickNode();
  149. }else{
  150. if (this.controller) this.controller.clear();
  151. }
  152. }
  153. this.checkControllerActionsShare();
  154. }.bind(this));
  155. this.editorTab.addEvent("show", function(){
  156. if (this.editorTree.currentNode){
  157. this.editorTree.currentNode.clickNode();
  158. }else{
  159. if (this.editorTree.firstChild){
  160. this.editorTree.firstChild.clickNode();
  161. }else{
  162. if (this.controller) this.controller.clear();
  163. }
  164. }
  165. this.checkControllerActionsEditor();
  166. }.bind(this));
  167. var tabName = "file";
  168. if (this.status){
  169. if (this.status.tab){
  170. tabName = this.status.tab;
  171. }
  172. }
  173. if (tabName == "file") this.fileTabe.showIm();
  174. if (tabName == "share") this.shareTab.showIm();
  175. if (tabName == "editor") this.editorTab.showIm();
  176. this.setContentHeight();
  177. this.addEvent("resize", function(){this.setContentHeight();}.bind(this));
  178. }.bind(this));
  179. MWF.require("MWF.widget.ScrollBar", function(){
  180. new MWF.widget.ScrollBar(this.folderTreeAreaScrollNode, {
  181. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  182. });
  183. new MWF.widget.ScrollBar(this.shareTreeAreaScrollNode, {
  184. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  185. });
  186. new MWF.widget.ScrollBar(this.editorTreeAreaScrollNode, {
  187. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  188. });
  189. //new MWF.widget.ScrollBar(this.fileContentAreaScrollNode, {
  190. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  191. //});
  192. }.bind(this));
  193. },
  194. checkControllerActionsFile: function(){
  195. this.controller.folderActionBoxNode.setStyle("display", "block");
  196. //this.controller.editActionBoxNode.setStyle("display", "block");
  197. this.controller.uploadAction.setStyle("display", "block");
  198. this.controller.deleteAction.setStyle("display", "block");
  199. this.controller.replaceAction.setStyle("display", "block");
  200. this.controller.editActionSeparateNode.setStyle("display", "block");
  201. this.controller.shareActionBoxNode.setStyle("display", "block");
  202. },
  203. checkControllerActionsShare: function(){
  204. this.controller.folderActionBoxNode.setStyle("display", "none");
  205. this.controller.uploadAction.setStyle("display", "none");
  206. this.controller.deleteAction.setStyle("display", "none");
  207. this.controller.replaceAction.setStyle("display", "none");
  208. this.controller.editActionSeparateNode.setStyle("display", "none");
  209. // this.controller.editActionBoxNode.setStyle("display", "none");
  210. this.controller.shareActionBoxNode.setStyle("display", "none");
  211. },
  212. checkControllerActionsEditor: function(){
  213. this.controller.folderActionBoxNode.setStyle("display", "none");
  214. this.controller.uploadAction.setStyle("display", "none");
  215. this.controller.deleteAction.setStyle("display", "none");
  216. this.controller.replaceAction.setStyle("display", "block");
  217. this.controller.editActionSeparateNode.setStyle("display", "block");
  218. // this.controller.editActionBoxNode.setStyle("display", "none");
  219. this.controller.shareActionBoxNode.setStyle("display", "none");
  220. },
  221. loadTop: function(){
  222. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  223. this.leftNode = new Element("div", {"styles": this.css.leftNode}).inject(this.topNode);
  224. this.leftNode.addEvent("click", function(){
  225. this.leftPath();
  226. }.bind(this));
  227. this.rightNode = new Element("div", {"styles": this.css.rightNode}).inject(this.topNode);
  228. this.rightNode.addEvent("click", function(){
  229. this.rightPath();
  230. }.bind(this));
  231. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.topNode);
  232. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.topNode);
  233. this.pathNode = new Element("div", {"styles": this.css.pathNode}).inject(this.topNode);
  234. },
  235. //loadTools: function(){
  236. // this.toolsNode = new Element("div", {"styles": this.css.toolsNode}).inject(this.node);
  237. // this.uploadNode = new Element("div", {"styles": this.css.toolsActionNode, "text": this.lp.upload}).inject(this.toolsNode);
  238. // this.createFolderNode = new Element("div", {"styles": this.css.toolsActionNode, "text": this.lp.createFolder}).inject(this.toolsNode);
  239. // this.operationNode = new Element("div", {"styles": this.css.toolsMenuActionNode}).inject(this.toolsNode);
  240. // var downTextNode = new Element("div", {"styles": this.css.downTextNode, "text": this.lp.operation}).inject(this.operationNode);
  241. // var downIconNode = new Element("div", {"styles": this.css.downIconNode}).inject(this.operationNode);
  242. //
  243. // this.uploadNode.addEvents({
  244. // "mouseover": function(){this.uploadNode.setStyles(this.css.toolsActionNode_over);}.bind(this),
  245. // "mouseout": function(){this.uploadNode.setStyles(this.css.toolsActionNode);}.bind(this),
  246. // "click": function(){this.createUploadFile();}.bind(this)
  247. // });
  248. // this.createFolderNode.addEvents({
  249. // "mouseover": function(){this.createFolderNode.setStyles(this.css.toolsActionNode_over);}.bind(this),
  250. // "mouseout": funtion(){this.createFolderNode.setStyles(this.css.toolsActionNode);}.bind(this),
  251. // "click": function(){this.createFolder();}.bind(this)
  252. // });
  253. // this.operationNode.addEvents({
  254. // "mouseover": function(){this.operationNode.setStyles(this.css.toolsMenuActionNode_over);}.bind(this),
  255. // "mouseout": function(){this.operationNode.setStyles(this.css.toolsMenuActionNode);}.bind(this),
  256. // "click": function(){}.bind(this)
  257. // });
  258. // this.operationMenu = new MWF.xDesktop.Menu(this.operationNode, {
  259. // "event": "click",
  260. // "style": "fileOperation",
  261. // "offsetX": -4,
  262. // "offsetY": 4,
  263. // "onQueryShow": function(){
  264. // this.operationMenu.items.each(function(item){item.setDisable(true);});
  265. // if (this.selectedItem){
  266. // if (this.selectedItem.type=="folder"){
  267. // this.operationMenu.items[0].setText(this.lp.uploadTo+" "+this.selectedItem.data.name+"...");
  268. // this.operationMenu.items[0].setDisable(false);
  269. // this.operationMenu.items[3].setDisable(false);
  270. // this.operationMenu.items[4].setDisable(false);
  271. // this.operationMenu.items[7].setDisable(false);
  272. // }
  273. // if (this.selectedItem.type=="file"){
  274. // this.operationMenu.items[0].setText(this.lp.uploadTo);
  275. // this.operationMenu.items[0].setDisable(true);
  276. // this.operationMenu.items[1].setDisable(false);
  277. // this.operationMenu.items[3].setDisable(false);
  278. // this.operationMenu.items[4].setDisable(false);
  279. // this.operationMenu.items[5].setDisable(false);
  280. // this.operationMenu.items[7].setDisable(false);
  281. // }
  282. // }
  283. // }.bind(this)
  284. // });
  285. // this.operationMenu.load();
  286. //
  287. // var img = this.path+this.options.style+"/operation/upload.png";
  288. // this.operationMenu.addMenuItem(this.lp.uploadTo, "click", function(){this.createUploadFile(this.selectedItem);}.bind(this), img);
  289. // var img = this.path+this.options.style+"/operation/download.png";
  290. // this.operationMenu.addMenuItem(this.lp.download, "click", function(){this.downloadCurrentFile();}.bind(this), img);
  291. //
  292. // this.operationMenu.addMenuLine();
  293. //
  294. // var img = this.path+this.options.style+"/operation/move.png";
  295. // this.operationMenu.addMenuItem(this.lp.move, "click", function(){this.moveFileFolder();}.bind(this), img);
  296. // var img = this.path+this.options.style+"/operation/rename.png";
  297. // this.operationMenu.addMenuItem(this.lp.rename, "click", function(){this.renameFileFolder();}.bind(this), img);
  298. // var img = this.path+this.options.style+"/operation/share.png";
  299. // this.operationMenu.addMenuItem(this.lp.share, "click", function(){this.shareFile();}.bind(this), img);
  300. //
  301. // this.operationMenu.addMenuLine();
  302. //
  303. // var img = this.path+this.options.style+"/operation/delete.png";
  304. // this.operationMenu.addMenuItem(this.lp["delete"], "click", function(e){this.deleteFileFolder(e);}.bind(this), img);
  305. //},
  306. openAttachment: function(e, node, attachment){
  307. this.restActions.getFileUrl(attachment[0].data.id, function(url){
  308. window.open(url);
  309. });
  310. },
  311. downloadAttachment: function(e, node, attachments){
  312. attachments.each(function(attachment){
  313. this.restActions.getFileDownloadUrl(attachment.data.id, function(url){
  314. window.open(url);
  315. });
  316. }.bind(this));
  317. },
  318. downloadCurrentFile: function(){
  319. if (this.selectedItem){
  320. if (this.selectedItem.type=="file"){
  321. this.selectedItem.open();
  322. }
  323. }
  324. },
  325. moveFileFolder: function(){
  326. //move----------
  327. //move----------
  328. //move----------
  329. //move----------
  330. },
  331. renameFileFolder: function(){
  332. this.content.mask({
  333. "style": {
  334. "opacity": 0.7,
  335. "background-color": "#999"
  336. }
  337. });
  338. var renameNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  339. renameNode.position({
  340. relativeTo: this.node,
  341. position: "center"
  342. });
  343. var item = this.controller.selectedAttachments[0];
  344. var treeNode = item.treeNode;
  345. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.rename}).inject(renameNode);
  346. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputName}).inject(renameNode);
  347. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(renameNode);
  348. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode, "value": item.data.name}).inject(inputAreaNode);
  349. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(renameNode);
  350. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  351. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  352. cancelButton.addEvent("click", function(){
  353. this.content.unmask();
  354. renameNode.destroy();
  355. }.bind(this));
  356. okButton.addEvent("click", function(){
  357. if (inputNode.get("value")){
  358. item.data.name = inputNode.get("value");
  359. if (item.type=="folder"){
  360. this.restActions.saveFolder(item.data, function(json){
  361. if (this.currentFolder){
  362. this.currentFolder.clickNode();
  363. }else{
  364. this.topTreeNode.clickNode();
  365. }
  366. treeNode.setText(inputNode.get("value"));
  367. }.bind(this));
  368. }else{
  369. this.restActions.updateAttachment(this.controller.selectedAttachments[0].data, function(json){
  370. if (this.currentFolder){
  371. this.currentFolder.clickNode();
  372. }else{
  373. this.topTreeNode.clickNode();
  374. }
  375. }.bind(this));
  376. }
  377. renameNode.destroy();
  378. this.content.unmask();
  379. }else{
  380. this.notice(this.lp.nameNotEmpty, "error", renameNode);
  381. }
  382. }.bind(this));
  383. },
  384. deleteAttachments: function(e, node, attachments){
  385. this.deleteFileFolder(e, attachments);
  386. },
  387. deleteFileFolder: function(e, attachments){
  388. if (attachments.length){
  389. var _self = this;
  390. var title = this.lp.deleteFolderFilesTitle;
  391. var content = this.lp.deleteFolderFiles;
  392. if (attachments.length==1){
  393. var title = (attachments[0].type=="folder") ? this.lp.deleteFolderTitle : this.lp.deleteFileTitle;
  394. var content = (attachments[0].type=="folder") ? this.lp.deleteFolder : this.lp.deleteFile;
  395. content = content+"("+attachments[0].data.name+")";
  396. }
  397. var size = this.node.getSize();
  398. // var position = this.operationMenu.items[7].item.getPosition(this.operationMenu.items[7].item.getOffsetParent());
  399. var ep = {"event": {"x": (size.x-300)/2, "y": (size.y-120)/2}};
  400. this.confirm("infor", ep, title, content, 300, 120, function(){
  401. var count = attachments.length;
  402. var current = 0;
  403. var callback = function(){
  404. if (current == count){
  405. if (this.currentFolder){
  406. this.currentFolder.loaded = false;
  407. this.currentFolder.clickNode();
  408. }else{
  409. this.topTreeNode.loaded = false;
  410. this.topTreeNode.clickNode();
  411. }
  412. }
  413. };
  414. attachments.each(function(att){
  415. if (att.type=="folder"){
  416. att.treeNode.destroy();
  417. _self.restActions.deleteFolder(att.data.id, function(){
  418. current++;
  419. callback.apply(_self);
  420. });
  421. }else{
  422. _self.restActions.deleteFile(att.data.id, function(){
  423. current++;
  424. callback.apply(_self);
  425. });
  426. }
  427. });
  428. this.close();
  429. }, function(){
  430. this.close();
  431. });
  432. }
  433. },
  434. shareAttachment: function(){
  435. this.shareFile();
  436. },
  437. shareFile: function(){
  438. this.content.mask({
  439. "style": {
  440. "opacity": 0.7,
  441. "background-color": "#999"
  442. }
  443. });
  444. var shareNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  445. shareNode.position({
  446. relativeTo: this.node,
  447. position: "center"
  448. });
  449. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.shareFile}).inject(shareNode);
  450. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.selectShareUser}).inject(shareNode);
  451. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(shareNode);
  452. var inputNode = new Element("input", {"type": "text", "readonly": true, "styles": this.css.shareFileInputNode}).inject(inputAreaNode);
  453. // if (this.controller.selectedAttachments.length==1) inputNode.set("value", this.controller.selectedAttachments[0].data.shareList.join(", "));
  454. inputNode.addEvent("click", function(){
  455. MWF.xDesktop.requireApp("Organization", "Selector.Person", function(){
  456. var selector = new MWF.xApplication.Organization.Selector.Person(this.node,{
  457. //"names": this.selectedItem.data.shareList,
  458. "onComplete": function(items){
  459. var names = [];
  460. items.each(function(item){
  461. names.push(item.data.name);
  462. });
  463. inputNode.set("value", names.join(", "));
  464. }.bind(this)
  465. });
  466. selector.load();
  467. }.bind(this));
  468. }.bind(this));
  469. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(shareNode);
  470. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  471. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  472. cancelButton.addEvent("click", function(){
  473. this.content.unmask();
  474. shareNode.destroy();
  475. }.bind(this));
  476. okButton.addEvent("click", function(){
  477. var count = this.controller.selectedAttachments.length;
  478. var current = 0;
  479. var callback = function(){
  480. if (current == count){
  481. if (inputNode.get("value")) this.notice(this.lp.fileShareSuccess+inputNode.get("value"), "success", this.content);
  482. shareNode.destroy();
  483. this.content.unmask();
  484. }
  485. };
  486. this.controller.selectedAttachments.each(function(att){
  487. if (att.type!="folder"){
  488. att.data.shareList = inputNode.get("value").split(/,\s*/g);
  489. this.restActions.updateAttachment(att.data, function(json){
  490. current++;
  491. callback.apply(this);
  492. }.bind(this));
  493. }else{
  494. current++;
  495. callback.apply(this);
  496. }
  497. }.bind(this));
  498. }.bind(this));
  499. },
  500. sendAttachment: function(){
  501. this.sendFile();
  502. },
  503. sendFile: function(){
  504. this.content.mask({
  505. "style": {
  506. "opacity": 0.7,
  507. "background-color": "#999"
  508. }
  509. });
  510. var shareNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  511. shareNode.position({
  512. relativeTo: this.node,
  513. position: "center"
  514. });
  515. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.sendFile}).inject(shareNode);
  516. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.selectSendUser}).inject(shareNode);
  517. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(shareNode);
  518. var inputNode = new Element("input", {"type": "text", "readonly": true, "styles": this.css.shareFileInputNode}).inject(inputAreaNode);
  519. // if (this.controller.selectedAttachments.length==1) inputNode.set("value", this.controller.selectedAttachments[0].data.shareList.join(", "));
  520. inputNode.addEvent("click", function(){
  521. MWF.xDesktop.requireApp("Organization", "Selector.Person", function(){
  522. var selector = new MWF.xApplication.Organization.Selector.Person(this.node,{
  523. //"names": this.selectedItem.data.shareList,
  524. "onComplete": function(items){
  525. var names = [];
  526. items.each(function(item){
  527. names.push(item.data.name);
  528. });
  529. inputNode.set("value", names.join(", "));
  530. }.bind(this)
  531. });
  532. selector.load();
  533. }.bind(this));
  534. }.bind(this));
  535. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(shareNode);
  536. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  537. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  538. cancelButton.addEvent("click", function(){
  539. this.content.unmask();
  540. shareNode.destroy();
  541. }.bind(this));
  542. okButton.addEvent("click", function(){
  543. var count = this.controller.selectedAttachments.length;
  544. var current = 0;
  545. var callback = function(){
  546. if (current == count){
  547. if (inputNode.get("value")) this.notice(this.lp.fileSendSuccess+inputNode.get("value"), "success", this.content);
  548. shareNode.destroy();
  549. this.content.unmask();
  550. }
  551. };
  552. this.controller.selectedAttachments.each(function(att){
  553. if (att.type!="folder"){
  554. att.data.editorList = inputNode.get("value").split(/,\s*/g);
  555. this.restActions.updateAttachment(att.data, function(json){
  556. current++;
  557. callback.apply(this);
  558. }.bind(this));
  559. }else{
  560. current++;
  561. callback.apply(this);
  562. }
  563. }.bind(this));
  564. }.bind(this));
  565. },
  566. uploadAttachment: function(){
  567. this.createUploadFile();
  568. },
  569. createUploadFile: function(folder){
  570. if (!this.uploadFileAreaNode){
  571. this.uploadFileAreaNode = new Element("div");
  572. var html = "<input name=\"file\" multiple type=\"file\" accept=\"*/*\"/>";
  573. this.uploadFileAreaNode.set("html", html);
  574. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  575. this.fileUploadNode.addEvent("change", function(){
  576. var folderId = "";
  577. if (folder){
  578. folderId = folder.data.id;
  579. }else{
  580. folderId = (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "";
  581. }
  582. var files = fileNode.files;
  583. if (files.length){
  584. var count = files.length;
  585. var current = 0;
  586. var callback = function(){
  587. if (current == count){
  588. if (this.currentFolder){
  589. this.currentFolder.clickNode();
  590. }else{
  591. this.topTreeNode.clickNode();
  592. }
  593. }
  594. };
  595. for (var i = 0; i < files.length; i++) {
  596. var file = files.item(i);
  597. var formData = new FormData();
  598. formData.append('file', file);
  599. this.restActions.addAttachment(function(){
  600. current++;
  601. callback.apply(this);
  602. }.bind(this), null, formData, folderId, file);
  603. }
  604. }
  605. }.bind(this));
  606. }
  607. this.fileUploadNode.set("accept", "*/*");
  608. this.fileUploadNode.set("multiple", true);
  609. var fileNode = this.uploadFileAreaNode.getFirst();
  610. fileNode.set("accept", "*/*");
  611. fileNode.click();
  612. },
  613. replaceAttachment: function(e, node, attachment){
  614. this.replaceUploadFile(attachment);
  615. },
  616. replaceUploadFile: function(attachment){
  617. if (!this.replaceFileAreaNode){
  618. this.replaceFileAreaNode = new Element("div");
  619. var html = "<input name=\"file\" multiple type=\"file\"/>";
  620. this.replaceFileAreaNode.set("html", html);
  621. this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  622. this.fileReplaceNode.addEvent("change", function(){
  623. var fileId = attachment.data.id;
  624. var files = fileNode.files;
  625. if (files.length){
  626. var count = files.length;
  627. var current = 0;
  628. var callback = function(){
  629. if (current == count){
  630. if (this.currentFolder){
  631. this.currentFolder.clickNode();
  632. }else{
  633. this.topTreeNode.clickNode();
  634. }
  635. }
  636. };
  637. for (var i = 0; i < files.length; i++) {
  638. var file = files.item(i);
  639. var formData = new FormData();
  640. formData.append('file', file);
  641. this.restActions.updateAttachmentData(function(){
  642. current++;
  643. callback.apply(this);
  644. }.bind(this), null, formData, fileId, file);
  645. }
  646. }
  647. }.bind(this));
  648. }
  649. this.fileReplaceNode.set("accept", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
  650. this.fileReplaceNode.set("multiple", false);
  651. var fileNode = this.replaceFileAreaNode.getFirst();
  652. fileNode.set("accept", "*/*");
  653. fileNode.click();
  654. },
  655. createFolder: function(){
  656. this.content.mask({
  657. "style": {
  658. "opacity": 0.7,
  659. "background-color": "#999"
  660. }
  661. });
  662. var createFolderNode = new Element("div", {"styles": this.css.createFolderNode}).inject(this.content);
  663. createFolderNode.position({
  664. relativeTo: this.node,
  665. position: "center"
  666. });
  667. var titleNode = new Element("div", {"styles": this.css.createFolderTitleNode, "text": this.lp.createFolder}).inject(createFolderNode);
  668. var inforNode = new Element("div", {"styles": this.css.createFolderInforNode, "text": this.lp.inputFolderName}).inject(createFolderNode);
  669. var inputAreaNode = new Element("div", {"styles": this.css.createFolderInputAreaNode}).inject(createFolderNode);
  670. var inputNode = new Element("input", {"type": "text", "styles": this.css.createFolderInputNode}).inject(inputAreaNode);
  671. var actionNode = new Element("div", {"styles": this.css.createFolderActionNode}).inject(createFolderNode);
  672. var cancelButton = new Element("button", {"styles": this.css.createFolderCancelButton, "text": this.lp.cancel}).inject(actionNode);
  673. var okButton = new Element("button", {"styles": this.css.createFolderOkButton, "text": this.lp.ok}).inject(actionNode);
  674. cancelButton.addEvent("click", function(){
  675. this.content.unmask();
  676. createFolderNode.destroy();
  677. }.bind(this));
  678. okButton.addEvent("click", function(){
  679. if (inputNode.get("value")){
  680. var data = {
  681. "name": inputNode.get("value"),
  682. "superior": (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : ""
  683. };
  684. this.restActions.saveFolder(data, function(json){
  685. data.id = json.data.id;
  686. this.restActions.getFolder(function(folderJson){
  687. if (this.currentFolder){
  688. var json = {"data":[folderJson.data]};
  689. this.createTreeNode(json, this.currentFolder);
  690. this.currentFolder.clickNode();
  691. }else{
  692. this.topTreeNode.clickNode();
  693. }
  694. }.bind(this), null, data.id);
  695. }.bind(this));
  696. createFolderNode.destroy();
  697. this.content.unmask();
  698. }else{
  699. this.notice(this.lp.folderNameNotEmpty, "error", createFolderNode);
  700. }
  701. }.bind(this));
  702. },
  703. getAttachmentUrl: function(attachment, callback){
  704. this.restActions.getFileUrl(attachment.data.id, callback);
  705. },
  706. loadFolderTreeNode: function(){
  707. this.folderTreeNode = new Element("div", {
  708. "styles": this.css.folderTreeNode
  709. }).inject(this.folderTreeAreaScrollNode);
  710. // MWF.require("MWF.widget.Tree", function(){
  711. this.folderTree = new MWF.widget.Tree(this.folderTreeNode, {
  712. "style": "file",
  713. // "onQueryExpand": function(node){
  714. // this.loadFolderTree(node);
  715. // }.bind(this)
  716. });
  717. this.folderTree.load();
  718. var rootData = {
  719. "expand": false,
  720. "title": "root",
  721. "text": "root",
  722. "action": function(treeNode){
  723. this.recordHistory(treeNode);
  724. this.expand(treeNode, function(){
  725. this.loadSub(treeNode);
  726. }.bind(this));
  727. }.bind(this),
  728. "icon": "folder.png"
  729. };
  730. this.topTreeNode = this.folderTree.appendChild(rootData);
  731. //this.topTreeNode.clickNode();
  732. // this.loadFolderTree();
  733. // }.bind(this));
  734. },
  735. createShareTreeNode: function(json){
  736. json.data.each(function(data){
  737. var nodeData = {
  738. "expand": false,
  739. "title": data.name+"("+data.count+")",
  740. "text": data.name+"("+data.count+")",
  741. "action": function(treeNode){
  742. this.loadShareFile(treeNode);
  743. }.bind(this),
  744. "icon": "folder.png"
  745. };
  746. var treeNode = this.shareTree.appendChild(nodeData);
  747. treeNode.data = data;
  748. }.bind(this));
  749. },
  750. loadShareTreeNode: function(){
  751. this.shareTreeNode = new Element("div", {
  752. "styles": this.css.folderTreeNode
  753. }).inject(this.shareTreeAreaScrollNode);
  754. // MWF.require("MWF.widget.Tree", function(){
  755. this.shareTree = new MWF.widget.Tree(this.shareTreeNode, {
  756. "style": "file"
  757. });
  758. this.shareTree.load();
  759. this.restActions.listShare(function(json){
  760. this.createShareTreeNode(json);
  761. // node.setOperateIcon();
  762. if (this.shareTree.loadCallback) this.shareTree.loadCallback.apply(this);
  763. }.bind(this), null, false);
  764. // this.loadFolderTree();
  765. // }.bind(this));
  766. },
  767. loadShareFile: function(treeNode){
  768. var person = treeNode.data.name;
  769. this.restActions.listShareAttachment(function(json){
  770. //this.fileContentAreaNode.empty();
  771. this.controller.clear();
  772. json.data.each(function(file){
  773. this.controller.addAttachment(file);
  774. //new MWF.xApplication.File.ShareAttachment(file, this);
  775. }.bind(this));
  776. }.bind(this), null, person);
  777. },
  778. createEditorTreeNode: function(json){
  779. json.data.each(function(data){
  780. var nodeData = {
  781. "expand": false,
  782. "title": data.name+"("+data.count+")",
  783. "text": data.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(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), null, person);
  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(function(json){
  864. this.createTreeNode(json, node);
  865. node.setOperateIcon();
  866. if (callback) callback();
  867. }.bind(this), null, node.data.id, 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(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), null, treeNode.data.id);
  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(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), null, formData, file);
  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. });