FileExplorer.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. return {
  155. "icon": this.explorer.path+this.explorer.options.style+"/fileIcon/lnk.png",
  156. "title": this.data.name,
  157. "par": "process.FileDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.options.application.id+"\"}"
  158. };
  159. },
  160. // deleteItem: function(e){
  161. // var _self = this;
  162. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  163. // _self.deleteForm();
  164. // this.close();
  165. // },function(){
  166. // this.close();
  167. // });
  168. // },
  169. deleteFile: function(callback){
  170. this.explorer.app.restActions.deleteFile(this.data.id, function(){
  171. this.node.destroy();
  172. if (callback) callback();
  173. }.bind(this));
  174. }
  175. });
  176. MWF.xApplication.process.ProcessManager.FileDesigner = new Class({
  177. initialize: function(explorer, item){
  178. this.explorer = explorer;
  179. this.app = this.explorer.app;
  180. this.data = item;
  181. this.container = this.explorer.container;
  182. this.css = this.explorer.css;
  183. this.lp = MWF.APPPM.LP;
  184. this.load();
  185. },
  186. getNewData: function(){
  187. return {
  188. "id": "",
  189. "name": "",
  190. "alias": "",
  191. "description": "",
  192. "application": (this.explorer.app.options.application || this.explorer.app.application).id,
  193. "fileName": ""
  194. }
  195. },
  196. resize: function(){
  197. var size = this.app.content.getSize();
  198. var nodeSize = this.fileAreaNode.getSize();
  199. var x = (size.x-nodeSize.x)/2;
  200. var y = (size.y-nodeSize.y)/2;
  201. if (y<0) y=0;
  202. if (x<0) x=0;
  203. this.fileAreaNode.setStyles({
  204. "top": ""+y+"px",
  205. "left": ""+x+"px"
  206. });
  207. var titleSize = this.titleNode.getSize();
  208. var buttonSize = this.buttonNode.getSize();
  209. var h = nodeSize.y-titleSize.y-buttonSize.y;
  210. this.contentNode.setStyle("height", ""+h+"px");
  211. },
  212. load: function(){
  213. if (!this.data) this.data = this.getNewData();
  214. this.fileMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  215. this.fileAreaNode = new Element("div", {"styles": this.css.createFormTemplateAreaNode}).inject(this.app.content);
  216. this.fileAreaNode.fade("in");
  217. this.titleNode = new Element("div", {"styles": this.css.fileDesignerTitleNode}).inject(this.fileAreaNode);
  218. this.titleIconNode = new Element("div", {"styles": this.css.fileDesignerTitleIconNode}).inject(this.titleNode);
  219. if (!this.data.id) this.titleIconNode.setStyle("background-image", "url("+this.explorer.path+this.app.options.style+"/icon/new.png)");
  220. this.titleTextNode = new Element("div", {"styles": this.css.fileDesignerTitleTextNode}).inject(this.titleNode);
  221. var title = (this.data.name) ? this.data.name : this.explorer.options.tooltip.create;
  222. this.titleTextNode.set("text", title);
  223. this.contentNode = new Element("div", {"styles": this.css.fileDesignerContentNode}).inject(this.fileAreaNode);
  224. this.createContent();
  225. this.buttonNode = new Element("div", {"styles": this.css.fileDesignerButtonNode}).inject(this.fileAreaNode);
  226. this.createButton();
  227. this.resizeFun = this.resize.bind(this);
  228. this.resizeFun();
  229. this.app.addEvent("resize", this.resizeFun);
  230. this.setEvent();
  231. },
  232. createContent: function(){
  233. this.contentAreaNode = new Element("div", {"styles": this.css.fileDesignerContentAreaNode}).inject(this.contentNode);
  234. this.nameInput = this.createContentLine(this.lp.name, this.data.name);
  235. this.aliasInput = this.createContentLine(this.lp.alias, this.data.alias);
  236. this.descriptionInput = this.createContentLine(this.lp.file.description, this.data.description, true);
  237. this.createContentFile();
  238. this.createContentFileUrl();
  239. },
  240. createContentFileUrl: function(){
  241. if (this.data.fileName){
  242. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  243. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": "URL"}).inject(div);
  244. this.fileUrlNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  245. div.setStyle("height", "80px");
  246. var url = MWF.Actions.get("x_processplatform_assemble_surface").action.actions.readFile.uri;
  247. url = url.replace(/{flag}/, this.data.id);
  248. url = url.replace(/{applicationFlag}/, this.data.application);
  249. url = "/x_processplatform_assemble_surface"+url;
  250. this.fileUrlNode.setStyle("line-height", "18px");
  251. var href = MWF.Actions.getHost("x_processplatform_assemble_surface")+url;
  252. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  253. this.fileUrlNode.set("text", url);
  254. var a = new Element("div", {
  255. "styles": {"height": "30px"},
  256. "html": "<a target='_blank' href='"+href+"'>open</a>"
  257. }).inject(this.fileUrlNode, "bottom");
  258. }
  259. },
  260. modifyContentFileUrl: function(){
  261. if (!this.fileUrlNode){
  262. this.createContentFileUrl();
  263. }else{
  264. var url = MWF.Actions.get("x_processplatform_assemble_surface").action.actions.readFile.uri;
  265. url = url.replace(/{flag}/, this.data.id);
  266. url = url.replace(/{applicationFlag}/, this.data.application);
  267. //this.fileUrlNode.set("text", "/x_processplatform_assemble_surface"+url);
  268. url = "/x_processplatform_assemble_surface"+url;
  269. this.fileUrlNode.setStyle("line-height", "18px");
  270. var href = MWF.Actions.getHost("x_processplatform_assemble_surface")+url;
  271. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  272. this.fileUrlNode.set("text", url);
  273. var a = new Element("div", {
  274. "styles": {"height": "30px"},
  275. "html": "<a target='_blank' href='"+href+"'>open</a>"
  276. }).inject(this.fileUrlNode, "bottom");
  277. }
  278. },
  279. createContentFile: function(){
  280. var div = new Element("div", {"styles": this.css.fileDesignerContentFileLineNode}).inject(this.contentAreaNode);
  281. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineTitleNode, "text": this.lp.attachment}).inject(div);
  282. var lineRightNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineRightNode}).inject(div);
  283. this.fileContentNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineContentNode}).inject(div);
  284. this.uploadFileButton = new Element("div", {"styles": this.css.fileDesignerUploadButtonNode, "text": this.lp.upload}).inject(lineRightNode);
  285. if (this.data.fileName){
  286. this.loadFileIcon();
  287. }
  288. },
  289. getIconJson: function(callback){
  290. if (!this.icons){
  291. MWF.getJSON("/x_component_File/$Main/icon.json", function(json){
  292. this.icons = json;
  293. if (callback) callback();
  294. }.bind(this), false, false);
  295. }else{
  296. if (callback) callback();
  297. }
  298. },
  299. getIcon: function(ext){
  300. if (!ext) ext="unkonw";
  301. var iconName = this.icons[ext.toLowerCase()] || this.icons.unknow;
  302. return "/x_component_File/$Main/default/file/"+iconName;
  303. },
  304. loadFileIcon: function(){
  305. this.fileContentNode.empty();
  306. var ext = this.data.fileName.substr(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length);
  307. this.getIconJson(function(){
  308. var url = this.getIcon(ext);
  309. var fileIconNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileIconNode}).inject(this.fileContentNode);
  310. fileIconNode.setStyle("background-image", "url('"+url+"')");
  311. var fileTextNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileNameNode, "text": this.data.fileName}).inject(this.fileContentNode);
  312. var fileSizeNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileSizeNode, "text": this.data.description}).inject(this.fileContentNode);
  313. }.bind(this));
  314. },
  315. createContentLine: function(text, value, readonly){
  316. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  317. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": text}).inject(div);
  318. var lineContentNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  319. return new Element("input", {"styles": this.css.fileDesignerContentLineInputNode, "value": value, "readonly": readonly}).inject(lineContentNode);
  320. },
  321. createButton: function(){
  322. this.cancelButton = new Element("div", {"styles": this.css.fileDesignerCancelButtonNode, "text": this.lp.cancel}).inject(this.buttonNode);
  323. this.okButton = new Element("div", {"styles": this.css.fileDesignerOkButtonNode, "text": this.lp.ok}).inject(this.buttonNode);
  324. },
  325. setEvent: function(){
  326. this.cancelButton.addEvent("click", function(e){ this.close(e); }.bind(this));
  327. this.okButton.addEvent("click", function(){ this.save(); }.bind(this));
  328. this.uploadFileButton.addEvent("click", function(){ this.upload(); }.bind(this));
  329. },
  330. upload: function(){
  331. if (!this.data.id){
  332. //MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(){
  333. // this.explorer.reload();
  334. this.uploadFile(function(){
  335. this.app.notice(this.lp.file.uploadSuccess, "success");
  336. }.bind(this));
  337. //}.bind(this));
  338. }else{
  339. this.uploadFile(function(){
  340. this.app.notice(this.lp.file.uploadSuccess, "success");
  341. }.bind(this));
  342. }
  343. },
  344. uploadFile: function(callback){
  345. MWF.require("MWF.widget.Upload", function(){
  346. new MWF.widget.Upload(this.app.content, {
  347. "action": MWF.Actions.get("x_processplatform_assemble_designer").action,
  348. "multiple": false,
  349. "method": "uploadFile",
  350. "parameter": {"id": this.data.id},
  351. "onCompleted": function(){
  352. this.loadFileIcon();
  353. this.modifyContentFileUrl();
  354. this.explorer.reload();
  355. if (callback) callback();
  356. }.bind(this),
  357. "onBeforeUpload": function(files, up){
  358. var name = files[0].name;
  359. this.nameInput.set("value", name);
  360. var data = this.getData();
  361. this.data = Object.merge(this.data, data);
  362. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(json){
  363. this.explorer.reload();
  364. up.options.parameter = {"id": json.data.id};
  365. }.bind(this), null, false);
  366. }.bind(this),
  367. "onEvery": function(json, current, count, file){
  368. //this.data.description = file.name+" "+this.getSizeText(file.size);
  369. //this.data.id = json.data.id;
  370. this.data.fileName = file.name;
  371. this.data.description = file.name+" "+this.getSizeText(file.size);
  372. this.descriptionInput.set("value", this.data.description);
  373. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data);
  374. }.bind(this)
  375. }).load();
  376. }.bind(this));
  377. },
  378. getSizeText: function(s){
  379. var o = [
  380. {"t": "K", "i": 1024},
  381. {"t": "M", "i": 1024*1024},
  382. {"t": "G", "i": 1024*1024*1024}
  383. ];
  384. var i = 0;
  385. var n = s/o[i].i;
  386. while (n>1000 && i<2){
  387. i++;
  388. n = s/o[i].i;
  389. }
  390. n = Math.round(n*100)/100;
  391. return ""+n+" "+o[i].t;
  392. },
  393. getData: function(){
  394. return {
  395. "name": this.nameInput.get("value"),
  396. "alias": this.aliasInput.get("value"),
  397. "description": this.descriptionInput.get("value")
  398. }
  399. },
  400. close: function(e){
  401. var data = this.getData();
  402. var _self = this;
  403. if (data.name!==this.data.name || data.alias!==this.data.alias || data.description!== this.data.description){
  404. this.app.confirm("infor", e, this.lp.file.saveConfirm, this.lp.file.saveConfirmText, 350, 120, function(){
  405. this.close();
  406. _self.save();
  407. }, function(){
  408. this.close();
  409. _self.destroy();
  410. })
  411. }else{
  412. this.destroy();
  413. }
  414. },
  415. save: function(){
  416. var data = this.getData();
  417. this.data = Object.merge(this.data, data);
  418. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(){
  419. this.explorer.reload();
  420. this.app.notice(this.lp.file.saveSuccess, "success");
  421. this.destroy();
  422. }.bind(this));
  423. },
  424. destroy: function(){
  425. this.fileMaskNode.destroy();
  426. this.fileAreaNode.destroy();
  427. if (this.resizeFun) this.app.removeEvent("resize", this.resizeFun);
  428. MWF.release(this);
  429. }
  430. });