Exporter.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. MWF.xApplication.query.QueryExplorer.Exporter = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default"
  6. },
  7. initialize: function(app, data, options){
  8. this.setOptions(options);
  9. this.app = app;
  10. this.container = this.app.content;
  11. this.data = data;
  12. this.path = "../x_component_portal_PortalExplorer/$Exporter/";
  13. this.cssPath = "../x_component_portal_PortalExplorer/$Exporter/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. },
  16. load: function(){
  17. this.container.mask({
  18. "destroyOnHide": true,
  19. "style": {
  20. "background-color": "#666",
  21. "opacity": 0.6
  22. }
  23. });
  24. this.node = new Element("div", {"styles": this.css.content});
  25. this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.app.lp.application.export}).inject(this.node);
  26. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  27. this.buttonAreaNode = new Element("div", {"styles": this.css.buttonAreaNode}).inject(this.node);
  28. this.cancelButton = new Element("div", {"styles": this.css.button, "text": this.app.lp.application.export_cancel}).inject(this.buttonAreaNode);
  29. this.okButton = new Element("div", {"styles": this.css.okButton, "text": this.app.lp.application.export_ok}).inject(this.buttonAreaNode);
  30. this.loadContent();
  31. this.setEvent();
  32. this.node.inject(this.container);
  33. this.node.position({
  34. relativeTo: this.container,
  35. position: 'center',
  36. edge: 'center'
  37. });
  38. },
  39. loadContent: function(){
  40. this.actions = this.app.restActions;
  41. //var listTitleNodeArea = new Element("div", {"styles": this.css.listTitleNodeArea}).inject(this.contentNode);
  42. //this.processSelectAction = new Element("div", {"styles": this.css.listTitleActionNode, "text": this.app.lp.application.select}).inject(listTitleNodeArea);
  43. //new Element("div", {"styles": this.css.listTitleNode, "text": this.app.lp.application.process}).inject(listTitleNodeArea);
  44. //this.processListNode = new Element("div", {"styles": this.css.listNode}).inject(this.contentNode);
  45. //
  46. listTitleNodeArea = new Element("div", {"styles": this.css.listTitleNodeArea}).inject(this.contentNode);
  47. this.viewSelectAction = new Element("div", {"styles": this.css.listTitleActionNode, "text": this.app.lp.application.select}).inject(listTitleNodeArea);
  48. new Element("div", {"styles": this.css.listTitleNode, "text": this.app.lp.application.view}).inject(listTitleNodeArea);
  49. this.viewListNode = new Element("div", {"styles": this.css.listNode}).inject(this.contentNode);
  50. //
  51. //listTitleNodeArea = new Element("div", {"styles": this.css.listTitleNodeArea}).inject(this.contentNode);
  52. //this.dictionarySelectAction = new Element("div", {"styles": this.css.listTitleActionNode, "text": this.app.lp.application.select}).inject(listTitleNodeArea);
  53. //new Element("div", {"styles": this.css.listTitleNode, "text": this.app.lp.application.dictionary}).inject(listTitleNodeArea);
  54. //this.dictionaryListNode = new Element("div", {"styles": this.css.listNode}).inject(this.contentNode);
  55. //
  56. listTitleNodeArea = new Element("div", {"styles": this.css.listTitleNodeArea}).inject(this.contentNode);
  57. this.statSelectAction = new Element("div", {"styles": this.css.listTitleActionNode, "text": this.app.lp.application.select}).inject(listTitleNodeArea);
  58. new Element("div", {"styles": this.css.listTitleNode, "text": this.app.lp.application.stat}).inject(listTitleNodeArea);
  59. this.statListNode = new Element("div", {"styles": this.css.listNode}).inject(this.contentNode);
  60. //this.listProcess();
  61. //this.listPage();
  62. //this.listDictionary();
  63. //this.listScript();
  64. this.listView();
  65. this.listStat();
  66. //this.processSelectAction.addEvent("click", function(){this.inverse(this.processListNode);}.bind(this));
  67. //this.formSelectAction.addEvent("click", function(){this.inverse(this.formListNode);}.bind(this));
  68. //this.dictionarySelectAction.addEvent("click", function(){this.inverse(this.dictionaryListNode);}.bind(this));
  69. //this.scriptSelectAction.addEvent("click", function(){this.inverse(this.scriptListNode);}.bind(this));
  70. this.viewSelectAction.addEvent("click", function(){this.inverse(this.viewListNode);}.bind(this));
  71. this.statSelectAction.addEvent("click", function(){this.inverse(this.statListNode);}.bind(this));
  72. },
  73. //listProcess: function(){
  74. // this.actions.listProcess(this.data.id, function(json){
  75. // if (json.data){
  76. // json.data.each(function(process){
  77. // this.createItem(process, this.processListNode);
  78. // }.bind(this));
  79. // }
  80. // }.bind(this));
  81. //},
  82. // listPage: function(){
  83. // this.actions.listPage(this.data.id, function(json){
  84. // if (json.data){
  85. // json.data.each(function(form){
  86. // this.createItem(form, this.formListNode);
  87. // }.bind(this));
  88. // }
  89. // }.bind(this));
  90. // },
  91. //listDictionary: function(){
  92. // this.actions.listDictionary(this.data.id, function(json){
  93. // if (json.data){
  94. // json.data.each(function(dic){
  95. // this.createItem(dic, this.dictionaryListNode);
  96. // }.bind(this));
  97. // }
  98. // }.bind(this));
  99. //},
  100. listView: function(){
  101. this.actions.listView(this.data.id, function(json){
  102. if (json.data){
  103. json.data.each(function(view){
  104. this.createItem(view, this.viewListNode);
  105. }.bind(this));
  106. }
  107. }.bind(this));
  108. },
  109. listStat: function(){
  110. this.actions.listStat(this.data.id, function(json){
  111. if (json.data){
  112. json.data.each(function(stat){
  113. this.createItem(stat, this.statListNode);
  114. }.bind(this));
  115. }
  116. }.bind(this));
  117. },
  118. inverse: function(node){
  119. var inputs = node.getElements("input");
  120. inputs.each(function(input){
  121. if (input.checked){
  122. input.set("checked", false);
  123. }else{
  124. input.set("checked", true);
  125. }
  126. });
  127. },
  128. createItem: function(data, node){
  129. var item = new Element("div", {"styles": this.css.processItem}).inject(node);
  130. var checkbox = new Element("input", {
  131. "styles": this.css.processItemCheckbox,
  132. "type": "checkbox",
  133. "checked": true
  134. }).inject(item);
  135. checkbox.store("itemData", data);
  136. var textNode = new Element("div", {"text": data.name, "styles": this.css.processItemText}).inject(item);
  137. },
  138. setEvent: function(){
  139. this.cancelButton.addEvent("click", function(e){
  140. this.close();
  141. }.bind(this));
  142. this.okButton.addEvent("click", function(e){
  143. this.exportApplication();
  144. // this.close();
  145. }.bind(this));
  146. },
  147. close: function(){
  148. this.container.unmask();
  149. this.node.destroy();
  150. this.cancelButton = null;
  151. this.okButton = null;
  152. this.buttonAreaNode = null;
  153. this.contentNode = null;
  154. this.titleNode = null;
  155. this.node = null;
  156. //this.processListNode = null;
  157. //this.formListNode = null;
  158. //this.dictionaryListNode = null;
  159. //this.scriptListNode = null;
  160. this.viewListNode = null;
  161. this.statListNode = null;
  162. this.fireEvent("close");
  163. },
  164. exportApplication: function(){
  165. this.applicationJson = {
  166. "application": {},
  167. //"processList": [],
  168. "viewList": [],
  169. //"dictionaryList": [],
  170. "statList": []
  171. };
  172. this.createProgressBar();
  173. //var process = this.processListNode.getElements("input:checked");
  174. var views = this.viewListNode.getElements("input:checked");
  175. //var dics = this.dictionaryListNode.getElements("input:checked");
  176. var stats = this.statListNode.getElements("input:checked");
  177. this.status = {
  178. "count": views.length+stats.length+1,
  179. "complete": 0
  180. };
  181. this.exportProperty();
  182. //this.exportProcesses(process);
  183. //this.exportPages(pages);
  184. //this.exportDictionarys(dics);
  185. //this.exportScripts(scripts);
  186. this.exportViews(views);
  187. this.exportStats(stats);
  188. },
  189. exportProperty: function(){
  190. this.actions.getApplication(this.data.id, function(json){
  191. this.progressBarTextNode.set("text", "load Application Property ...");
  192. if (json.data){
  193. this.applicationJson.application = json.data;
  194. }
  195. this.checkExport();
  196. }.bind(this));
  197. },
  198. //exportProcesses: function(processes){
  199. // processes.each(function(processCheckbox){
  200. // var process = processCheckbox.retrieve("itemData");
  201. // this.actions.getProcess(process.id, function(json){
  202. // this.progressBarTextNode.set("text", "load Process \""+process.name+"\" ...");
  203. // if (json.data){
  204. // this.applicationJson.processList.push(json.data);
  205. // }
  206. // this.checkExport();
  207. // }.bind(this));
  208. // }.bind(this));
  209. //},
  210. // exportPages: function(forms){
  211. // forms.each(function(formCheckbox){
  212. // var form = formCheckbox.retrieve("itemData");
  213. // this.actions.getPage(form.id, function(json){
  214. // this.progressBarTextNode.set("text", "load Form \""+form.name+"\" ...");
  215. // if (json.data){
  216. // this.applicationJson.pageList.push(json.data);
  217. // }
  218. // this.checkExport();
  219. // }.bind(this));
  220. // }.bind(this));
  221. // },
  222. //exportDictionarys: function(dics){
  223. // dics.each(function(dicCheckbox){
  224. // var dic = dicCheckbox.retrieve("itemData");
  225. // this.actions.getDictionary(dic.id, function(json){
  226. // this.progressBarTextNode.set("text", "load Dictionary \""+dic.name+"\" ...");
  227. // if (json.data){
  228. // this.applicationJson.dictionaryList.push(json.data);
  229. // }
  230. // this.checkExport();
  231. // }.bind(this));
  232. // }.bind(this));
  233. //},
  234. exportViews: function(views){
  235. views.each(function(viewCheckbox){
  236. var view = viewCheckbox.retrieve("itemData");
  237. this.actions.getView(view.id, function(json){
  238. this.progressBarTextNode.set("text", "load View \""+view.name+"\" ...");
  239. if (json.data){
  240. this.applicationJson.viewList.push(json.data);
  241. }
  242. this.checkExport();
  243. }.bind(this));
  244. }.bind(this));
  245. },
  246. exportStats: function(stats){
  247. stats.each(function(statCheckbox){
  248. var stat = statCheckbox.retrieve("itemData");
  249. this.actions.getStat(stat.id, function(json){
  250. this.progressBarTextNode.set("text", "load Stat \""+stat.name+"\" ...");
  251. if (json.data){
  252. this.applicationJson.statList.push(json.data);
  253. }
  254. this.checkExport();
  255. }.bind(this));
  256. }.bind(this));
  257. },
  258. checkExport: function(){
  259. this.status.complete = this.status.complete+1;
  260. var x = 358*(this.status.complete/this.status.count);
  261. this.progressBarPercent.setStyle("width", ""+x+"px");
  262. if (this.status.complete == this.status.count){
  263. this.saveApplicationToLocal();
  264. }
  265. },
  266. saveApplicationToLocal: function(){
  267. if (window.hasOwnProperty("ActiveXObject")){
  268. var win = window.open("", "_blank");
  269. win.document.write(JSON.encode(this.applicationJson));
  270. }else{
  271. this.downloadFile(this.data.name+".xapp", JSON.encode(this.applicationJson));
  272. }
  273. this.progressBarNode.destroy();
  274. this.progressBarNode = null;
  275. this.progressBarTextNode = null;
  276. this.progressBar = null;
  277. this.progressBarPercent = null;
  278. this.close();
  279. },
  280. downloadFile: function(fileName, content){
  281. var link = new Element("a", {"text": this.data.name}).inject(this.progressBarTextNode);
  282. var blob = new Blob([content]);
  283. link.download = fileName;
  284. link.href = URL.createObjectURL(blob);
  285. //link.href = "data:text/plain," + content;
  286. var evt = document.createEvent("HTMLEvents");
  287. evt.initEvent("click", false, false);
  288. link.dispatchEvent(evt);
  289. link.click();
  290. },
  291. createProgressBar: function(){
  292. this.node.hide();
  293. this.progressBarNode = new Element("div", {"styles": this.css.progressBarNode});
  294. this.progressBarNode.inject(this.container);
  295. this.progressBarNode.position({
  296. relativeTo: this.container,
  297. position: 'center',
  298. edge: 'center'
  299. });
  300. this.progressBarTextNode = new Element("div", {"styles": this.css.progressBarTextNode}).inject(this.progressBarNode);
  301. this.progressBar = new Element("div", {"styles": this.css.progressBar}).inject(this.progressBarNode);
  302. this.progressBarPercent = new Element("div", {"styles": this.css.progressBarPercent}).inject(this.progressBar);
  303. }
  304. });