Main.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  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.click();
  611. },
  612. replaceAttachment: function(e, node, attachment){
  613. this.replaceUploadFile(attachment);
  614. },
  615. replaceUploadFile: function(attachment){
  616. if (!this.uploadFileAreaNode){
  617. this.uploadFileAreaNode = new Element("div");
  618. var html = "<input name=\"file\" multiple type=\"file\"/>";
  619. this.uploadFileAreaNode.set("html", html);
  620. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  621. this.fileUploadNode.addEvent("change", function(){
  622. var fileId = attachment.data.id;
  623. var files = fileNode.files;
  624. if (files.length){
  625. var count = files.length;
  626. var current = 0;
  627. var callback = function(){
  628. if (current == count){
  629. if (this.currentFolder){
  630. this.currentFolder.clickNode();
  631. }else{
  632. this.topTreeNode.clickNode();
  633. }
  634. }
  635. };
  636. for (var i = 0; i < files.length; i++) {
  637. var file = files.item(i);
  638. var formData = new FormData();
  639. formData.append('file', file);
  640. this.restActions.updateAttachmentData(function(){
  641. current++;
  642. callback.apply(this);
  643. }.bind(this), null, formData, fileId, file);
  644. }
  645. }
  646. }.bind(this));
  647. }
  648. this.fileUploadNode.set("accept", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
  649. this.fileUploadNode.set("multiple", false);
  650. var fileNode = this.uploadFileAreaNode.getFirst();
  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(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), null, data.id);
  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 nodeData = {
  736. "expand": false,
  737. "title": data.name+"("+data.count+")",
  738. "text": data.name+"("+data.count+")",
  739. "action": function(treeNode){
  740. this.loadShareFile(treeNode);
  741. }.bind(this),
  742. "icon": "folder.png"
  743. };
  744. var treeNode = this.shareTree.appendChild(nodeData);
  745. treeNode.data = data;
  746. }.bind(this));
  747. },
  748. loadShareTreeNode: function(){
  749. this.shareTreeNode = new Element("div", {
  750. "styles": this.css.folderTreeNode
  751. }).inject(this.shareTreeAreaScrollNode);
  752. // MWF.require("MWF.widget.Tree", function(){
  753. this.shareTree = new MWF.widget.Tree(this.shareTreeNode, {
  754. "style": "file"
  755. });
  756. this.shareTree.load();
  757. this.restActions.listShare(function(json){
  758. this.createShareTreeNode(json);
  759. // node.setOperateIcon();
  760. if (this.shareTree.loadCallback) this.shareTree.loadCallback.apply(this);
  761. }.bind(this), null, false);
  762. // this.loadFolderTree();
  763. // }.bind(this));
  764. },
  765. loadShareFile: function(treeNode){
  766. var person = treeNode.data.name;
  767. this.restActions.listShareAttachment(function(json){
  768. //this.fileContentAreaNode.empty();
  769. this.controller.clear();
  770. json.data.each(function(file){
  771. this.controller.addAttachment(file);
  772. //new MWF.xApplication.File.ShareAttachment(file, this);
  773. }.bind(this));
  774. }.bind(this), null, person);
  775. },
  776. createEditorTreeNode: function(json){
  777. json.data.each(function(data){
  778. var nodeData = {
  779. "expand": false,
  780. "title": data.name+"("+data.count+")",
  781. "text": data.name+"("+data.count+")",
  782. "action": function(treeNode){
  783. this.loadEditorFile(treeNode);
  784. }.bind(this),
  785. "icon": "folder.png"
  786. };
  787. var treeNode = this.editorTree.appendChild(nodeData);
  788. treeNode.data = data;
  789. }.bind(this));
  790. },
  791. loadEditorTreeNode: function(){
  792. this.editorTreeNode = new Element("div", {
  793. "styles": this.css.folderTreeNode
  794. }).inject(this.editorTreeAreaScrollNode);
  795. // MWF.require("MWF.widget.Tree", function(){
  796. this.editorTree = new MWF.widget.Tree(this.editorTreeNode, {
  797. "style": "file"
  798. });
  799. this.editorTree.load();
  800. this.restActions.listEditor(function(json){
  801. this.createEditorTreeNode(json);
  802. // node.setOperateIcon();
  803. if (this.editorTree.loadCallback) this.editorTree.loadCallback.apply(this);
  804. }.bind(this), null, false);
  805. // this.loadFolderTree();
  806. // }.bind(this));
  807. },
  808. loadEditorFile: function(treeNode){
  809. var person = treeNode.data.name;
  810. this.restActions.listEditorAttachment(function(json){
  811. //this.fileContentAreaNode.empty();
  812. this.controller.clear();
  813. json.data.each(function(file){
  814. this.controller.addAttachment(file);
  815. //new MWF.xApplication.File.ShareAttachment(file, this);
  816. }.bind(this));
  817. }.bind(this), null, person);
  818. },
  819. loadFileContentAreaNode: function(){
  820. this.controller = new MWF.xApplication.File.AttachmentController(this.attachmentContentNode, this, {
  821. "resize": false,
  822. "isSizeChange": false,
  823. })
  824. this.controller.load();
  825. //this.fileContentAreaScrollNode = new Element("div", {
  826. // "styles": this.css.fileContentAreaScrollNode
  827. //}).inject(this.attachmentContentNode);
  828. //
  829. //this.fileContentAreaScrollNode.addEvent("click", function(){
  830. // if (this.selectedItem) this.selectedItem.unSelected();
  831. //}.bind(this));
  832. //
  833. //this.fileContentAreaNode = new Element("div", {
  834. // "styles": this.css.fileContentAreaNode
  835. //}).inject(this.fileContentAreaScrollNode);
  836. //
  837. //this.initDropUpLoad();
  838. },
  839. createTreeNode: function(json, topNode){
  840. json.data.each(function(data){
  841. var nodeData = {
  842. "expand": false,
  843. "title": data.name,
  844. "text": data.name,
  845. "action": function(treeNode){
  846. this.recordHistory(treeNode);
  847. this.expand(treeNode, function(){
  848. this.loadSub(treeNode);
  849. }.bind(this));
  850. }.bind(this),
  851. "icon": "folder.png"
  852. };
  853. var treeNode = topNode.appendChild(nodeData);
  854. treeNode.data = data;
  855. }.bind(this));
  856. },
  857. loadFolderTree: function(node, callback){
  858. if (!node.loaded){
  859. node.loaded = true;
  860. if (node.data){
  861. this.restActions.listFolder(function(json){
  862. this.createTreeNode(json, node);
  863. node.setOperateIcon();
  864. if (callback) callback();
  865. }.bind(this), null, node.data.id, false);
  866. }else{
  867. this.restActions.listTopFolder(function(json){
  868. this.createTreeNode(json, node);
  869. node.setOperateIcon();
  870. if (callback) callback();
  871. }.bind(this), null, false);
  872. }
  873. }else{
  874. if (callback) callback();
  875. }
  876. },
  877. setContentHeight: function(node){
  878. var size = this.node.getSize();
  879. var tSize = this.topNode.getSize();
  880. // var toolSize = this.toolsNode.getSize();
  881. var mtt = this.topNode.getStyle("margin-top").toFloat();
  882. var mbt = this.topNode.getStyle("margin-bottom").toFloat();
  883. // var mttool = this.toolsNode.getStyle("margin-top").toFloat();
  884. // var mbtool = this.toolsNode.getStyle("margin-bottom").toFloat();
  885. var mtc = this.fileContentNode.getStyle("margin-top").toFloat();
  886. var mbc = this.fileContentNode.getStyle("margin-bottom").toFloat();
  887. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  888. this.fileContentNode.setStyle("height", height);
  889. this.attachmentContentNode.setStyle("height", height);
  890. var attTopSzie = this.controller.topNode.getSize();
  891. var y = height-attTopSzie.y;
  892. this.controller.contentScrollNode.setStyle("height", ""+y+"px");
  893. // this.fileContentAreaNode.setStyle("min-height", height);
  894. var tabSize = this.treeTab.tabNodeContainer.getSize();
  895. var height = height-tabSize.y;
  896. this.folderTreeAreaScrollNode.setStyle("height", height);
  897. this.shareTreeAreaScrollNode.setStyle("height", height);
  898. this.editorTreeAreaScrollNode.setStyle("height", height);
  899. },
  900. expand: function(treeNode, callback){
  901. if (!treeNode.options.expand){
  902. this.loadFolderTree(treeNode, function(){
  903. if (callback) callback();
  904. }.bind(this));
  905. this.folderTree.expand(treeNode);
  906. treeNode.options.expand = true;
  907. treeNode.setOperateIcon();
  908. }else{
  909. if (callback) callback();
  910. }
  911. },
  912. checkHistory: function(){
  913. if (this.history.length>1){
  914. if (this.currentHistory>0){
  915. this.enabledLeftNode();
  916. }else{
  917. this.disabledLeftNode();
  918. }
  919. if (this.currentHistory<this.history.length-1){
  920. this.enabledRightNode();
  921. }else{
  922. this.disabledRightNode();
  923. }
  924. }else{
  925. this.disabledLeftNode();
  926. this.disabledRightNode();
  927. }
  928. },
  929. enabledLeftNode: function(){
  930. this.leftNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/left_enabled.png)");
  931. },
  932. enabledRightNode: function(){
  933. this.rightNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/right_enabled.png)");
  934. },
  935. disabledLeftNode: function(){
  936. this.leftNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/left.png)");
  937. },
  938. disabledRightNode: function(){
  939. this.rightNode.setStyle("background-image", "url("+"/x_component_File/$Main/default/icon/right.png)");
  940. },
  941. leftPath: function(){
  942. if (this.currentHistory>0){
  943. this.currentHistory--;
  944. var treeNode = this.history[this.currentHistory];
  945. if (treeNode){
  946. treeNode.selectNode();
  947. this.loadSub(treeNode);
  948. this.checkHistory();
  949. }
  950. }
  951. },
  952. rightPath: function(){
  953. if (this.currentHistory<this.history.length-1){
  954. this.currentHistory++;
  955. var treeNode = this.history[this.currentHistory];
  956. if (treeNode){
  957. treeNode.selectNode();
  958. this.loadSub(treeNode);
  959. this.checkHistory();
  960. }
  961. }
  962. },
  963. recordHistory: function(treeNode){
  964. if (!this.history.length || this.history[this.history.length-1]!=treeNode){
  965. this.history.push(treeNode);
  966. this.currentHistory = this.history.length-1;
  967. this.checkHistory();
  968. }
  969. },
  970. setPathNode: function(treeNode){
  971. this.pathNode.empty();
  972. var paths = [];
  973. var tmpNode = treeNode;
  974. while (tmpNode){
  975. paths.unshift(tmpNode);
  976. tmpNode = tmpNode.parentNode;
  977. };
  978. var _self = this;
  979. paths.each(function(node, index){
  980. this.expand(node);
  981. var pathNode = new Element("div",{
  982. "styles": this.css.pathItemNode,
  983. "text": (node.data) ? node.data.name : "root",
  984. "events": {
  985. "mouseover": function(){
  986. this.setStyles(_self.css.pathItemNode_over);
  987. },
  988. "mouseout": function(){
  989. this.setStyles(_self.css.pathItemNode);
  990. },
  991. "click": function(){
  992. node.clickNode();
  993. },
  994. }
  995. }).inject(this.pathNode);
  996. if (index<paths.length-1) new Element("div",{"styles": this.css.pathItemIconNode}).inject(this.pathNode);
  997. }.bind(this));
  998. },
  999. loadSub: function(treeNode){
  1000. this.setPathNode(treeNode);
  1001. //this.fileContentAreaNode.empty();
  1002. this.controller.clear();
  1003. treeNode.children.each(function(node){
  1004. var folder = this.controller.addAttachmentFolder(node.data);
  1005. folder.treeNode = node;
  1006. //var folder = new MWF.xApplication.File.Folder(node.data, this);
  1007. //folder.treeNode = node;
  1008. }.bind(this));
  1009. this.currentFolder = treeNode;
  1010. if (treeNode.data){
  1011. this.restActions.listAttachment(function(json){
  1012. json.data.each(function(file){
  1013. this.controller.addAttachment(file);
  1014. //new MWF.xApplication.File.Attachment(file, this);
  1015. }.bind(this));
  1016. }.bind(this), null, treeNode.data.id);
  1017. }else{
  1018. this.restActions.listAttachmentTop(function(json){
  1019. json.data.each(function(file){
  1020. this.controller.addAttachment(file);
  1021. //new MWF.xApplication.File.Attachment(file, this);
  1022. }.bind(this));
  1023. }.bind(this));
  1024. }
  1025. },
  1026. uploadFiles: function(files){
  1027. if (!this.uploadFileList) this.uploadFileList = [];
  1028. if (!this.uploadFileTotalSize) this.uploadFileTotalSize = 0;
  1029. if (!files || !files.length) return;
  1030. for (var i = 0; i < files.length && i < 5; i++) {
  1031. this.uploadFileList.push(files[i]);
  1032. this.uploadFileTotalSize += files[i].size;
  1033. }
  1034. this.uploadNext();
  1035. },
  1036. uploadNext: function(){
  1037. if (this.uploadFileList.length) {
  1038. var nextFile = this.uploadFileList.shift();
  1039. if (nextFile){
  1040. this.uploadFile(nextFile);
  1041. this.uploadNext();
  1042. }
  1043. }
  1044. },
  1045. uploadFile: function(file){
  1046. var formData = new FormData();
  1047. formData.append('file', file);
  1048. formData.append('name', file.name);
  1049. formData.append('folder', (this.currentFolder && this.currentFolder.data) ? this.currentFolder.data.id : "");
  1050. // xhr.send(formData);
  1051. this.restActions.addAttachment(function(){
  1052. if (!this.uploadFileList.length){
  1053. if (this.currentFolder){
  1054. this.currentFolder.clickNode();
  1055. }else{
  1056. this.topTreeNode.clickNode();
  1057. }
  1058. }
  1059. }.bind(this), null, formData, file);
  1060. },
  1061. initDropUpLoad: function(){
  1062. this.fileContentAreaNode.addEventListener('drop', function(e){
  1063. e.stopPropagation();
  1064. e.preventDefault();
  1065. if (this.dropUploadInforNode){
  1066. this.dropUploadInforNode.destroy();
  1067. this.dropUploadInforNode = null;
  1068. }
  1069. if (e.dataTransfer.types.length<2){
  1070. this.uploadFiles(e.dataTransfer.files);
  1071. }
  1072. }.bind(this), false);
  1073. this.fileContentAreaNode.addEventListener('dragover', function(e){
  1074. if (e.dataTransfer.types.length<2){
  1075. e.stopPropagation();
  1076. e.preventDefault();
  1077. if (!this.dropUploadInforNode){
  1078. this.dropUploadInforNode = new Element("div", {
  1079. "styles": this.css.dropUploadInforNode,
  1080. "text": this.lp.dropUpload
  1081. }).inject(this.node);
  1082. this.dropUploadInforNode.position({
  1083. relativeTo: this.fileContentAreaNode,
  1084. position: "centerBottom",
  1085. edge: "centerBottom",
  1086. offset: {"x": 0, "y": -100}
  1087. });
  1088. this.dropUploadInforNode.fade(0.7);
  1089. }
  1090. }
  1091. }.bind(this), false);
  1092. this.fileContentAreaNode.addEventListener('dragleave', function(e){
  1093. e.stopPropagation();
  1094. e.preventDefault();
  1095. if (this.dropUploadInforNode) window.setTimeout(function(){
  1096. if (this.dropUploadInforNode){
  1097. this.dropUploadInforNode.destroy();
  1098. this.dropUploadInforNode = null;
  1099. }
  1100. }.bind(this), 2000);
  1101. }.bind(this), false);
  1102. }
  1103. });
  1104. MWF.xApplication.File.Attachment = new Class({
  1105. initialize: function(data, file){
  1106. this.data = data;
  1107. this.file = file;
  1108. this.type = "file";
  1109. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  1110. this.load();
  1111. },
  1112. getIcon: function(){
  1113. var iconName = this.file.icons[this.extension] || this.file.icons.unknow;
  1114. return "/x_component_File/$Main/default/file/"+iconName;
  1115. },
  1116. load: function(){
  1117. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  1118. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  1119. this.imgNode = new Element("div", {
  1120. "styles": this.file.css.attachmentImgNode
  1121. }).inject(this.iconNode);
  1122. this.imgNode.setStyle("background-image", "url("+this.getIcon()+")");
  1123. this.textNode = new Element("div", {
  1124. "styles": this.file.css.attachmentTextNode,
  1125. "text": this.data.name,
  1126. "title": this.data.name
  1127. }).inject(this.node);
  1128. if (this.data.shareList){
  1129. if (this.data.shareList.length){
  1130. this.shareIconNode = new Element("div", {"styles": this.file.css.shareIconNode}).inject(this.node);
  1131. // this.shareIconNode.position({
  1132. // relativeTo: this.node,
  1133. // position: "centerBottom",
  1134. // edge: "centerBottom"
  1135. // });
  1136. }
  1137. }
  1138. this.node.inject(this.file.fileContentAreaNode);
  1139. this.setEvents();
  1140. },
  1141. setEvents: function(){
  1142. this.node.addEvents({
  1143. "mouseover": function(){
  1144. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  1145. }.bind(this),
  1146. "mouseout": function(){
  1147. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  1148. }.bind(this),
  1149. "click": function(e){
  1150. this.selected();
  1151. e.stop();
  1152. e.stopPropagation();
  1153. }.bind(this),
  1154. "dblclick": function(){
  1155. this.open();
  1156. }.bind(this),
  1157. });
  1158. this.node.makeLnk({
  1159. "par": {
  1160. "icon": this.getIcon(),
  1161. "title": this.data.name,
  1162. "par": "FileOpen#{\"id\": \""+this.data.id+"\", \"type\": \"file\"}"
  1163. }
  1164. });
  1165. },
  1166. selected: function(){
  1167. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  1168. this.isSelected = true;
  1169. this.node.setStyles(this.file.css.attachmentNode_select);
  1170. this.file.selectedItem = this;
  1171. },
  1172. unSelected: function(){
  1173. this.isSelected = false;
  1174. this.node.setStyles(this.file.css.attachmentNode);
  1175. this.file.selectedItem = null;
  1176. },
  1177. open: function(){
  1178. this.file.restActions.getAttachment(this.data.id);
  1179. }
  1180. });
  1181. MWF.xApplication.File.Folder = new Class({
  1182. initialize: function(data, file){
  1183. this.data = data;
  1184. this.file = file;
  1185. this.type = "folder";
  1186. this.load();
  1187. },
  1188. getIcon: function(){
  1189. return "/x_component_File/$Main/default/file/folder.png";
  1190. },
  1191. load: function(){
  1192. this.node = new Element("div", {"styles": this.file.css.attachmentNode});
  1193. // this.node.addEvents();
  1194. this.iconNode = new Element("div", {"styles": this.file.css.attachmentIconNode}).inject(this.node);
  1195. this.imgNode = new Element("img", {
  1196. "styles": this.file.css.attachmentImgNode,
  1197. "src": this.getIcon(),
  1198. "border": "0"
  1199. }).inject(this.iconNode);
  1200. this.textNode = new Element("div", {
  1201. "styles": this.file.css.attachmentTextNode,
  1202. "text": this.data.name
  1203. }).inject(this.node);
  1204. this.node.inject(this.file.fileContentAreaNode);
  1205. this.setEvents();
  1206. },
  1207. setEvents: function(){
  1208. this.node.addEvents({
  1209. "mouseover": function(){
  1210. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode_over);
  1211. }.bind(this),
  1212. "mouseout": function(){
  1213. if (!this.isSelected) this.node.setStyles(this.file.css.attachmentNode);
  1214. }.bind(this),
  1215. "click": function(e){
  1216. this.selected();
  1217. e.stop();
  1218. e.stopPropagation();
  1219. }.bind(this),
  1220. "dblclick": function(){
  1221. this.open();
  1222. }.bind(this),
  1223. });
  1224. },
  1225. selected: function(){
  1226. if (this.file.selectedItem) this.file.selectedItem.unSelected();
  1227. this.isSelected = true;
  1228. this.node.setStyles(this.file.css.attachmentNode_select);
  1229. this.file.selectedItem = this;
  1230. },
  1231. unSelected: function(){
  1232. this.isSelected = false;
  1233. this.node.setStyles(this.file.css.attachmentNode);
  1234. this.file.selectedItem = null;
  1235. },
  1236. open: function(){
  1237. this.treeNode.clickNode();
  1238. }
  1239. });
  1240. MWF.xApplication.File.ShareAttachment = new Class({
  1241. Extends: MWF.xApplication.File.Attachment,
  1242. initialize: function(data, file){
  1243. this.data = data;
  1244. this.file = file;
  1245. this.type = "share";
  1246. this.extension = this.data.name.substr(this.data.name.lastIndexOf(".")+1, this.data.name.length);
  1247. this.load();
  1248. }
  1249. });