FileExplorer.js 21 KB

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