FileExplorer.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. debugger;
  154. if (!this.data) this.data = this.getNewData();
  155. this.fileMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  156. this.fileAreaNode = new Element("div", {"styles": this.css.createFormTemplateAreaNode}).inject(this.app.content);
  157. this.fileAreaNode.fade("in");
  158. this.titleNode = new Element("div", {"styles": this.css.fileDesignerTitleNode}).inject(this.fileAreaNode);
  159. this.titleIconNode = new Element("div", {"styles": this.css.fileDesignerTitleIconNode}).inject(this.titleNode);
  160. if (!this.data.id) this.titleIconNode.setStyle("background-image", "url("+this.explorer.path+this.app.options.style+"/icon/new.png)");
  161. this.titleTextNode = new Element("div", {"styles": this.css.fileDesignerTitleTextNode}).inject(this.titleNode);
  162. var title = (this.data.name) ? this.data.name : this.explorer.options.tooltip.create;
  163. this.titleTextNode.set("text", title);
  164. this.contentNode = new Element("div", {"styles": this.css.fileDesignerContentNode}).inject(this.fileAreaNode);
  165. this.createContent();
  166. this.buttonNode = new Element("div", {"styles": this.css.fileDesignerButtonNode}).inject(this.fileAreaNode);
  167. this.createButton();
  168. this.resizeFun = this.resize.bind(this);
  169. this.resizeFun();
  170. this.app.addEvent("resize", this.resizeFun);
  171. this.setEvent();
  172. },
  173. createContent: function(){
  174. this.contentAreaNode = new Element("div", {"styles": this.css.fileDesignerContentAreaNode}).inject(this.contentNode);
  175. this.nameInput = this.createContentLine(this.lp.name, this.data.name);
  176. this.aliasInput = this.createContentLine(this.lp.alias, this.data.alias);
  177. this.descriptionInput = this.createContentLine(this.lp.file.description, this.data.description, true);
  178. this.createContentFile();
  179. this.createContentFileUrl();
  180. },
  181. createContentFileUrl: function(){
  182. if (this.data.fileName){
  183. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  184. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": "URL"}).inject(div);
  185. this.fileUrlNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  186. div.setStyle("height", "80px");
  187. var url = MWF.Actions.get("x_processplatform_assemble_surface").action.actions.readFile.uri;
  188. url = url.replace(/{flag}/, this.data.id);
  189. url = url.replace(/{applicationFlag}/, this.data.application);
  190. url = "/x_processplatform_assemble_surface"+url;
  191. this.fileUrlNode.setStyle("line-height", "18px");
  192. var href = MWF.Actions.getHost("x_processplatform_assemble_surface")+url;
  193. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  194. this.fileUrlNode.set("text", url);
  195. var a = new Element("div", {
  196. "styles": {"height": "30px"},
  197. "html": "<a target='_blank' href='"+href+"'>open</a>"
  198. }).inject(this.fileUrlNode, "bottom");
  199. }
  200. },
  201. modifyContentFileUrl: function(){
  202. if (!this.fileUrlNode){
  203. this.createContentFileUrl();
  204. }else{
  205. var url = MWF.Actions.get("x_processplatform_assemble_surface").action.actions.readFile.uri;
  206. url = url.replace(/{flag}/, this.data.id);
  207. url = url.replace(/{applicationFlag}/, this.data.application);
  208. //this.fileUrlNode.set("text", "/x_processplatform_assemble_surface"+url);
  209. url = "/x_processplatform_assemble_surface"+url;
  210. this.fileUrlNode.setStyle("line-height", "18px");
  211. var href = MWF.Actions.getHost("x_processplatform_assemble_surface")+url;
  212. //this.fileUrlNode.set("html", "<a target='_blank' href='"+href+"'>"+url+"</a>");
  213. this.fileUrlNode.set("text", url);
  214. var a = new Element("div", {
  215. "styles": {"height": "30px"},
  216. "html": "<a target='_blank' href='"+href+"'>open</a>"
  217. }).inject(this.fileUrlNode, "bottom");
  218. }
  219. },
  220. createContentFile: function(){
  221. var div = new Element("div", {"styles": this.css.fileDesignerContentFileLineNode}).inject(this.contentAreaNode);
  222. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineTitleNode, "text": this.lp.attachment}).inject(div);
  223. var lineRightNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineRightNode}).inject(div);
  224. this.fileContentNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineContentNode}).inject(div);
  225. this.uploadFileButton = new Element("div", {"styles": this.css.fileDesignerUploadButtonNode, "text": this.lp.upload}).inject(lineRightNode);
  226. if (this.data.fileName){
  227. this.loadFileIcon();
  228. }
  229. },
  230. getIconJson: function(callback){
  231. if (!this.icons){
  232. MWF.getJSON("/x_component_File/$Main/icon.json", function(json){
  233. this.icons = json;
  234. if (callback) callback();
  235. }.bind(this), false, false);
  236. }else{
  237. if (callback) callback();
  238. }
  239. },
  240. getIcon: function(ext){
  241. if (!ext) ext="unkonw";
  242. var iconName = this.icons[ext.toLowerCase()] || this.icons.unknow;
  243. return "/x_component_File/$Main/default/file/"+iconName;
  244. },
  245. loadFileIcon: function(){
  246. debugger;
  247. this.fileContentNode.empty();
  248. var ext = this.data.fileName.substr(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length);
  249. this.getIconJson(function(){
  250. var url = this.getIcon(ext);
  251. var fileIconNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileIconNode}).inject(this.fileContentNode);
  252. fileIconNode.setStyle("background-image", "url('"+url+"')");
  253. var fileTextNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileNameNode, "text": this.data.fileName}).inject(this.fileContentNode);
  254. var fileSizeNode = new Element("div", {"styles": this.css.fileDesignerContentFileLineFileSizeNode, "text": this.data.description}).inject(this.fileContentNode);
  255. }.bind(this));
  256. },
  257. createContentLine: function(text, value, readonly){
  258. var div = new Element("div", {"styles": this.css.fileDesignerContentLineNode}).inject(this.contentAreaNode);
  259. var lineTitleNode = new Element("div", {"styles": this.css.fileDesignerContentLineTitleNode, "text": text}).inject(div);
  260. var lineContentNode = new Element("div", {"styles": this.css.fileDesignerContentLineContentNode}).inject(div);
  261. return new Element("input", {"styles": this.css.fileDesignerContentLineInputNode, "value": value, "readonly": readonly}).inject(lineContentNode);
  262. },
  263. createButton: function(){
  264. this.cancelButton = new Element("div", {"styles": this.css.fileDesignerCancelButtonNode, "text": this.lp.cancel}).inject(this.buttonNode);
  265. this.okButton = new Element("div", {"styles": this.css.fileDesignerOkButtonNode, "text": this.lp.ok}).inject(this.buttonNode);
  266. },
  267. setEvent: function(){
  268. this.cancelButton.addEvent("click", function(e){ this.close(e); }.bind(this));
  269. this.okButton.addEvent("click", function(){ this.save(); }.bind(this));
  270. this.uploadFileButton.addEvent("click", function(){ this.upload(); }.bind(this));
  271. },
  272. upload: function(){
  273. debugger;
  274. if (!this.data.id){
  275. var data = this.getData();
  276. this.data = Object.merge(this.data, data);
  277. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(){
  278. this.explorer.reload();
  279. this.uploadFile(function(){
  280. this.app.notice(this.lp.file.uploadSuccess, "success");
  281. }.bind(this));
  282. }.bind(this));
  283. }else{
  284. this.uploadFile(function(){
  285. this.app.notice(this.lp.file.uploadSuccess, "success");
  286. }.bind(this));
  287. }
  288. },
  289. uploadFile: function(callback){
  290. MWF.require("MWF.widget.Upload", function(){
  291. new MWF.widget.Upload(this.app.content, {
  292. "action": MWF.Actions.get("x_processplatform_assemble_designer").action,
  293. "method": "uploadFile",
  294. "parameter": {"id": this.data.id},
  295. "onCompleted": function(){
  296. this.loadFileIcon();
  297. this.modifyContentFileUrl();
  298. if (callback) callback();
  299. }.bind(this),
  300. "onEvery": function(json, current, count, file){
  301. //this.data.description = file.name+" "+this.getSizeText(file.size);
  302. this.data.fileName = file.name;
  303. this.data.description = file.name+" "+this.getSizeText(file.size);
  304. this.descriptionInput.set("value", this.data.description);
  305. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data);
  306. }.bind(this)
  307. }).load();
  308. }.bind(this));
  309. },
  310. getSizeText: function(s){
  311. var o = [
  312. {"t": "K", "i": 1024},
  313. {"t": "M", "i": 1024*1024},
  314. {"t": "G", "i": 1024*1024*1024}
  315. ];
  316. var i = 0;
  317. var n = s/o[i].i;
  318. while (n>1000 && i<2){
  319. i++;
  320. n = s/o[i].i;
  321. }
  322. n = Math.round(n*100)/100;
  323. return ""+n+" "+o[i].t;
  324. },
  325. getData: function(){
  326. return {
  327. "name": this.nameInput.get("value"),
  328. "alias": this.aliasInput.get("value"),
  329. "description": this.descriptionInput.get("value")
  330. }
  331. },
  332. close: function(e){
  333. var data = this.getData();
  334. var _self = this;
  335. if (data.name!==this.data.name || data.alias!==this.data.alias || data.description!== this.data.description){
  336. this.app.confirm("infor", e, this.lp.file.saveConfirm, this.lp.file.saveConfirmText, 350, 120, function(){
  337. this.close();
  338. _self.save();
  339. }, function(){
  340. this.close();
  341. _self.destroy();
  342. })
  343. }else{
  344. this.destroy();
  345. }
  346. },
  347. save: function(){
  348. var data = this.getData();
  349. this.data = Object.merge(this.data, data);
  350. MWF.Actions.get("x_processplatform_assemble_designer").saveFile(this.data, function(){
  351. this.explorer.reload();
  352. this.app.notice(this.lp.file.saveSuccess, "success");
  353. this.destroy();
  354. }.bind(this));
  355. },
  356. destroy: function(){
  357. this.fileMaskNode.destroy();
  358. this.fileAreaNode.destroy();
  359. if (this.resizeFun) this.app.removeEvent("resize", this.resizeFun);
  360. MWF.release(this);
  361. }
  362. });