FileExplorer.js 17 KB

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