FileExplorer.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. MWF.xDesktop.requireApp("process.ProcessManager", "DictionaryExplorer", null, false);
  2. MWF.xApplication.process.ProcessManager.FileExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "create": MWF.APPPM.LP.file.create,
  7. "search": MWF.APPPM.LP.file.search,
  8. "searchText": MWF.APPPM.LP.file.searchText,
  9. "noElement": MWF.APPPM.LP.file.noDictionaryNoticeText
  10. },
  11. createSearchElementNode: function(){
  12. this.titleActionNodeNode = new Element("div", {
  13. "styles": this.css.titleActionNode,
  14. "text": MWF.APPPM.LP.file.loadFiles
  15. }).inject(this.toolbarNode);
  16. this.titleActionNodeNode.addEvent("click", function(){
  17. this.implodeFiles();
  18. }.bind(this));
  19. },
  20. getNewData: function(){
  21. return {
  22. "id": "",
  23. "name": "",
  24. "alias": "",
  25. "description": "",
  26. "application": (this.app.options.application || this.app.application).id,
  27. "fileName": ""
  28. }
  29. },
  30. getSizeText: function(s){
  31. var o = [
  32. {"t": "K", "i": 1024},
  33. {"t": "M", "i": 1024*1024},
  34. {"t": "G", "i": 1024*1024*1024}
  35. ];
  36. var i = 0;
  37. var n = s/o[i].i;
  38. while (n>1000 && i<2){
  39. i++;
  40. n = s/o[i].i;
  41. }
  42. n = Math.round(n*100)/100;
  43. return ""+n+" "+o[i].t;
  44. },
  45. implodeFiles: function(){
  46. MWF.require("MWF.widget.Upload", function(){
  47. new MWF.widget.Upload(this.app.content, {
  48. "action": MWF.Actions.get("x_processplatform_assemble_designer").action,
  49. "multiple": true,
  50. "method": "uploadFile",
  51. "parameter": {"id": ""},
  52. "onBeforeUploadEntry": function(file, up){
  53. var data = this.getNewData();
  54. data.name = file.name;
  55. data.fileName = file.name;
  56. data.description = file.name+" "+this.getSizeText(file.size);
  57. data.updateTime = (new Date()).format("db");
  58. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(data, function(json){
  59. up.options.parameter = {"id": json.data.id};
  60. var node = this.elementContentListNode.getFirst();
  61. if (node) if (node.hasClass("noElementNode")){
  62. node.destroy();
  63. }
  64. var itemObj = this._getItemObject(data);
  65. itemObj.load();
  66. }.bind(this), null, false);
  67. }.bind(this)
  68. }).load();
  69. }.bind(this));
  70. },
  71. _createElement: function(e){
  72. // var _self = this;
  73. // var options = {
  74. // "onQueryLoad": function(){
  75. // this.actions = _self.app.restActions;
  76. // this.application = _self.app.options.application || _self.app.application;
  77. // this.explorer = _self;
  78. // }
  79. // };
  80. // this.app.desktop.openApplication(e, "process.FileDesigner", options);
  81. new MWF.xApplication.process.ProcessManager.FileDesigner(this);
  82. },
  83. _loadItemDataList: function(callback){
  84. var id = "";
  85. if (this.app.application) id = this.app.application.id;
  86. if (this.app.options.application) id = this.app.options.application.id;
  87. this.actions.listFile(id,callback);
  88. },
  89. _getItemObject: function(item){
  90. return new MWF.xApplication.process.ProcessManager.FileExplorer.File(this, item)
  91. },
  92. setTooltip: function(){
  93. this.options.tooltip = {
  94. "create": MWF.APPPM.LP.file.create,
  95. "search": MWF.APPPM.LP.file.search,
  96. "searchText": MWF.APPPM.LP.file.searchText,
  97. "noElement": MWF.APPPM.LP.file.noScriptNoticeText
  98. };
  99. },
  100. deleteItems: function(){
  101. this.hideDeleteAction();
  102. while (this.deleteMarkItems.length){
  103. var item = this.deleteMarkItems.shift();
  104. if (this.deleteMarkItems.length){
  105. item.deleteFile();
  106. }else{
  107. item.deleteFile(function(){
  108. // this.reloadItems();
  109. // this.hideDeleteAction();
  110. }.bind(this));
  111. }
  112. }
  113. }
  114. });
  115. MWF.xApplication.process.ProcessManager.FileExplorer.File = new Class({
  116. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary,
  117. _createActions: function(){
  118. this.deleteActionNode = new Element("div", {
  119. "styles": this.explorer.css.deleteActionNode
  120. }).inject(this.node);
  121. this.deleteActionNode.addEvent("click", function(e){
  122. this.deleteItem(e);
  123. }.bind(this));
  124. },
  125. _customNodes: function(){
  126. // if (!this.data.validated){
  127. // new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  128. // this.node.setStyle("background-color", "#f9e8e8");
  129. // }
  130. },
  131. _open: function(e){
  132. var _self = this;
  133. MWF.Actions.get("x_processplatform_assemble_designer").getFile(this.data.id, function(json){
  134. this.data = json.data;
  135. new MWF.xApplication.process.ProcessManager.FileDesigner(this.explorer, this.data);
  136. }.bind(this));
  137. // var options = {
  138. // "onQueryLoad": function(){
  139. // this.actions = _self.explorer.actions;
  140. // this.category = _self;
  141. // this.options.id = _self.data.id;
  142. // this.application = _self.explorer.app.options.application;
  143. // this.explorer = _self.explorer
  144. // }
  145. // };
  146. // this.explorer.app.desktop.openApplication(e, "process.FileDesigner", options);
  147. },
  148. _getIcon: function(){
  149. //var x = (Math.random()*33).toInt();
  150. //return "process_icon_"+x+".png";
  151. return "file.png";
  152. },
  153. _getLnkPar: function(){
  154. var url = MWF.Actions.get("x_processplatform_assemble_surface").action.actions.readFile.uri;
  155. url = url.replace(/{flag}/, this.data.id);
  156. url = url.replace(/{applicationFlag}/, this.data.application);
  157. url = "/x_processplatform_assemble_surface"+url;
  158. var href = MWF.Actions.getHost("x_processplatform_assemble_surface")+url;
  159. return {
  160. "icon": this.explorer.path+this.explorer.options.style+"/fileIcon/lnk.png",
  161. "title": this.data.name,
  162. "par": "@url#"+href
  163. };
  164. },
  165. // deleteItem: function(e){
  166. // var _self = this;
  167. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  168. // _self.deleteForm();
  169. // this.close();
  170. // },function(){
  171. // this.close();
  172. // });
  173. // },
  174. deleteFile: function(callback){
  175. this.explorer.app.restActions.deleteFile(this.data.id, function(){
  176. this.node.destroy();
  177. if (callback) callback();
  178. }.bind(this));
  179. }
  180. });
  181. MWF.xApplication.process.ProcessManager.FileDesigner = new Class({
  182. initialize: function(explorer, item){
  183. this.explorer = explorer;
  184. this.app = this.explorer.app;
  185. this.data = item;
  186. this.container = this.explorer.container;
  187. this.css = this.explorer.css;
  188. this.lp = MWF.APPPM.LP;
  189. this.load();
  190. },
  191. getNewData: function(){
  192. return {
  193. "id": "",
  194. "name": "",
  195. "alias": "",
  196. "description": "",
  197. "application": (this.explorer.app.options.application || this.explorer.app.application).id,
  198. "fileName": ""
  199. }
  200. },
  201. resize: function(){
  202. var size = this.app.content.getSize();
  203. var nodeSize = this.fileAreaNode.getSize();
  204. var x = (size.x-nodeSize.x)/2;
  205. var y = (size.y-nodeSize.y)/2;
  206. if (y<0) y=0;
  207. if (x<0) x=0;
  208. this.fileAreaNode.setStyles({
  209. "top": ""+y+"px",
  210. "left": ""+x+"px"
  211. });
  212. var titleSize = this.titleNode.getSize();
  213. var buttonSize = this.buttonNode.getSize();
  214. var h = nodeSize.y-titleSize.y-buttonSize.y;
  215. this.contentNode.setStyle("height", ""+h+"px");
  216. },
  217. load: function(){
  218. if (!this.data) this.data = this.getNewData();
  219. this.fileMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  220. this.fileAreaNode = new Element("div", {"styles": this.css.createFormTemplateAreaNode}).inject(this.app.content);
  221. this.fileAreaNode.fade("in");
  222. this.titleNode = new Element("div", {"styles": this.css.fileDesignerTitleNode}).inject(this.fileAreaNode);
  223. this.titleIconNode = new Element("div", {"styles": this.css.fileDesignerTitleIconNode}).inject(this.titleNode);
  224. if (!this.data.id) this.titleIconNode.setStyle("background-image", "url("+this.explorer.path+this.app.options.style+"/icon/new.png)");
  225. this.titleTextNode = new Element("div", {"styles": this.css.fileDesignerTitleTextNode}).inject(this.titleNode);
  226. var title = (this.data.name) ? this.data.name : this.explorer.options.tooltip.create;
  227. this.titleTextNode.set("text", title);
  228. this.contentNode = new Element("div", {"styles": this.css.fileDesignerContentNode}).inject(this.fileAreaNode);
  229. this.createContent();
  230. this.buttonNode = new Element("div", {"styles": this.css.fileDesignerButtonNode}).inject(this.fileAreaNode);
  231. this.createButton();
  232. this.resizeFun = this.resize.bind(this);
  233. this.resizeFun();
  234. this.app.addEvent("resize", this.resizeFun);
  235. this.setEvent();
  236. },
  237. createContent: function(){
  238. this.contentAreaNode = new Element("div", {"styles": this.css.fileDesignerContentAreaNode}).inject(this.contentNode);
  239. this.nameInput = this.createContentLine(this.lp.name, this.data.name);
  240. this.aliasInput = this.createContentLine(this.lp.alias, this.data.alias);
  241. this.descriptionInput = this.createContentLine(this.lp.file.description, this.data.description, true);
  242. this.createContentFile();
  243. this.createContentFileUrl();
  244. },
  245. createContentFileUrl: function(){
  246. if (this.data.fileName){
  247. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  248. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": "URL"}).inject(div);
  249. this.fileUrlNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  250. div.setStyle("height", "80px");
  251. var url = MWF.Actions.get("x_processplatform_assemble_surface").action.actions.readFile.uri;
  252. url = url.replace(/{flag}/, this.data.id);
  253. url = url.replace(/{applicationFlag}/, this.data.application);
  254. url = "/x_processplatform_assemble_surface"+url;
  255. this.fileUrlNode.setStyle("line-height", "18px");
  256. var href = MWF.Actions.getHost("x_processplatform_assemble_surface")+url;
  257. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  258. this.fileUrlNode.set("text", url);
  259. var a = new Element("div", {
  260. "styles": {"height": "30px"},
  261. "html": "<a target='_blank' href='"+href+"'>open</a>"
  262. }).inject(this.fileUrlNode, "bottom");
  263. }
  264. },
  265. modifyContentFileUrl: function(){
  266. if (!this.fileUrlNode){
  267. this.createContentFileUrl();
  268. }else{
  269. var url = MWF.Actions.get("x_processplatform_assemble_surface").action.actions.readFile.uri;
  270. url = url.replace(/{flag}/, this.data.id);
  271. url = url.replace(/{applicationFlag}/, this.data.application);
  272. //this.fileUrlNode.set("text", "/x_processplatform_assemble_surface"+url);
  273. url = "/x_processplatform_assemble_surface"+url;
  274. this.fileUrlNode.setStyle("line-height", "18px");
  275. var href = MWF.Actions.getHost("x_processplatform_assemble_surface")+url;
  276. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  277. this.fileUrlNode.set("text", url);
  278. var a = new Element("div", {
  279. "styles": {"height": "30px"},
  280. "html": "<a target='_blank' href='"+href+"'>open</a>"
  281. }).inject(this.fileUrlNode, "bottom");
  282. }
  283. },
  284. createContentFile: function(){
  285. var div = new Element("div", {"styles": this.css.fileDesignerContentFileLineNode}).inject(this.contentAreaNode);
  286. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineTitleNode, "text": this.lp.attachment}).inject(div);
  287. var lineRightNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineRightNode}).inject(div);
  288. this.fileContentNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineContentNode}).inject(div);
  289. this.uploadFileButton = new Element("div", {"styles": this.css.fileDesignerUploadButtonNode, "text": this.lp.upload}).inject(lineRightNode);
  290. if (this.data.fileName){
  291. this.loadFileIcon();
  292. }
  293. },
  294. getIconJson: function(callback){
  295. if (!this.icons){
  296. MWF.getJSON("/x_component_File/$Main/icon.json", function(json){
  297. this.icons = json;
  298. if (callback) callback();
  299. }.bind(this), false, false);
  300. }else{
  301. if (callback) callback();
  302. }
  303. },
  304. getIcon: function(ext){
  305. if (!ext) ext="unkonw";
  306. var iconName = this.icons[ext.toLowerCase()] || this.icons.unknow;
  307. return "/x_component_File/$Main/default/file/"+iconName;
  308. },
  309. loadFileIcon: function(){
  310. this.fileContentNode.empty();
  311. var ext = this.data.fileName.substr(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length);
  312. this.getIconJson(function(){
  313. var url = this.getIcon(ext);
  314. var fileIconNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileIconNode}).inject(this.fileContentNode);
  315. fileIconNode.setStyle("background-image", "url('"+url+"')");
  316. var fileTextNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileNameNode, "text": this.data.fileName}).inject(this.fileContentNode);
  317. var fileSizeNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileSizeNode, "text": this.data.description}).inject(this.fileContentNode);
  318. }.bind(this));
  319. },
  320. createContentLine: function(text, value, readonly){
  321. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  322. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": text}).inject(div);
  323. var lineContentNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  324. return new Element("input", {"styles": this.css.fileDesignerContentLineInputNode, "value": value, "readonly": readonly}).inject(lineContentNode);
  325. },
  326. createButton: function(){
  327. this.cancelButton = new Element("div", {"styles": this.css.fileDesignerCancelButtonNode, "text": this.lp.cancel}).inject(this.buttonNode);
  328. this.okButton = new Element("div", {"styles": this.css.fileDesignerOkButtonNode, "text": this.lp.ok}).inject(this.buttonNode);
  329. },
  330. setEvent: function(){
  331. this.cancelButton.addEvent("click", function(e){ this.close(e); }.bind(this));
  332. this.okButton.addEvent("click", function(){ this.save(); }.bind(this));
  333. this.uploadFileButton.addEvent("click", function(){ this.upload(); }.bind(this));
  334. },
  335. upload: function(){
  336. if (!this.data.id){
  337. //MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(){
  338. // this.explorer.reload();
  339. this.uploadFile(function(){
  340. this.app.notice(this.lp.file.uploadSuccess, "success");
  341. }.bind(this));
  342. //}.bind(this));
  343. }else{
  344. this.uploadFile(function(){
  345. this.app.notice(this.lp.file.uploadSuccess, "success");
  346. }.bind(this));
  347. }
  348. },
  349. uploadFile: function(callback){
  350. MWF.require("MWF.widget.Upload", function(){
  351. new MWF.widget.Upload(this.app.content, {
  352. "action": MWF.Actions.get("x_processplatform_assemble_designer").action,
  353. "multiple": false,
  354. "method": "uploadFile",
  355. "parameter": {"id": this.data.id},
  356. "onCompleted": function(){
  357. this.loadFileIcon();
  358. this.modifyContentFileUrl();
  359. this.explorer.reload();
  360. if (callback) callback();
  361. }.bind(this),
  362. "onBeforeUpload": function(files, up){
  363. var name = files[0].name;
  364. this.nameInput.set("value", name);
  365. var data = this.getData();
  366. this.data = Object.merge(this.data, data);
  367. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(json){
  368. this.explorer.reload();
  369. up.options.parameter = {"id": json.data.id};
  370. }.bind(this), null, false);
  371. }.bind(this),
  372. "onEvery": function(json, current, count, file){
  373. //this.data.description = file.name+" "+this.getSizeText(file.size);
  374. //this.data.id = json.data.id;
  375. this.data.fileName = file.name;
  376. this.data.description = file.name+" "+this.getSizeText(file.size);
  377. this.descriptionInput.set("value", this.data.description);
  378. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data);
  379. }.bind(this)
  380. }).load();
  381. }.bind(this));
  382. },
  383. getSizeText: function(s){
  384. var o = [
  385. {"t": "K", "i": 1024},
  386. {"t": "M", "i": 1024*1024},
  387. {"t": "G", "i": 1024*1024*1024}
  388. ];
  389. var i = 0;
  390. var n = s/o[i].i;
  391. while (n>1000 && i<2){
  392. i++;
  393. n = s/o[i].i;
  394. }
  395. n = Math.round(n*100)/100;
  396. return ""+n+" "+o[i].t;
  397. },
  398. getData: function(){
  399. return {
  400. "name": this.nameInput.get("value"),
  401. "alias": this.aliasInput.get("value"),
  402. "description": this.descriptionInput.get("value")
  403. }
  404. },
  405. close: function(e){
  406. var data = this.getData();
  407. var _self = this;
  408. if (data.name!==this.data.name || data.alias!==this.data.alias || data.description!== this.data.description){
  409. this.app.confirm("infor", e, this.lp.file.saveConfirm, this.lp.file.saveConfirmText, 350, 120, function(){
  410. this.close();
  411. _self.save();
  412. }, function(){
  413. this.close();
  414. _self.destroy();
  415. })
  416. }else{
  417. this.destroy();
  418. }
  419. },
  420. save: function(){
  421. var data = this.getData();
  422. this.data = Object.merge(this.data, data);
  423. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(){
  424. this.explorer.reload();
  425. this.app.notice(this.lp.file.saveSuccess, "success");
  426. this.destroy();
  427. }.bind(this));
  428. },
  429. destroy: function(){
  430. this.fileMaskNode.destroy();
  431. this.fileAreaNode.destroy();
  432. if (this.resizeFun) this.app.removeEvent("resize", this.resizeFun);
  433. MWF.release(this);
  434. }
  435. });