Exporter.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. MWF.xApplication.process.ApplicationExplorer.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_process_ApplicationExplorer/$Exporter/";
  13. this.cssPath = "../x_component_process_ApplicationExplorer/$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. listTitleNodeArea = new Element("div", {"styles": this.css.listTitleNodeArea}).inject(this.contentNode);
  46. this.formSelectAction = new Element("div", {"styles": this.css.listTitleActionNode, "text": this.app.lp.application.select}).inject(listTitleNodeArea);
  47. new Element("div", {"styles": this.css.listTitleNode, "text": this.app.lp.application.form}).inject(listTitleNodeArea);
  48. this.formListNode = new Element("div", {"styles": this.css.listNode}).inject(this.contentNode);
  49. listTitleNodeArea = new Element("div", {"styles": this.css.listTitleNodeArea}).inject(this.contentNode);
  50. this.dictionarySelectAction = new Element("div", {"styles": this.css.listTitleActionNode, "text": this.app.lp.application.select}).inject(listTitleNodeArea);
  51. new Element("div", {"styles": this.css.listTitleNode, "text": this.app.lp.application.dictionary}).inject(listTitleNodeArea);
  52. this.dictionaryListNode = new Element("div", {"styles": this.css.listNode}).inject(this.contentNode);
  53. listTitleNodeArea = new Element("div", {"styles": this.css.listTitleNodeArea}).inject(this.contentNode);
  54. this.scriptSelectAction = new Element("div", {"styles": this.css.listTitleActionNode, "text": this.app.lp.application.select}).inject(listTitleNodeArea);
  55. new Element("div", {"styles": this.css.listTitleNode, "text": this.app.lp.application.script}).inject(listTitleNodeArea);
  56. this.scriptListNode = new Element("div", {"styles": this.css.listNode}).inject(this.contentNode);
  57. this.listProcess();
  58. this.listForm();
  59. this.listDictionary();
  60. this.listScript();
  61. this.processSelectAction.addEvent("click", function(){this.inverse(this.processListNode);}.bind(this));
  62. this.formSelectAction.addEvent("click", function(){this.inverse(this.formListNode);}.bind(this));
  63. this.dictionarySelectAction.addEvent("click", function(){this.inverse(this.dictionaryListNode);}.bind(this));
  64. this.scriptSelectAction.addEvent("click", function(){this.inverse(this.scriptListNode);}.bind(this));
  65. },
  66. listProcess: function(){
  67. this.actions.listProcess(this.data.id, function(json){
  68. if (json.data){
  69. json.data.each(function(process){
  70. this.createItem(process, this.processListNode);
  71. }.bind(this));
  72. }
  73. }.bind(this));
  74. },
  75. listForm: function(){
  76. this.actions.listForm(this.data.id, function(json){
  77. if (json.data){
  78. json.data.each(function(form){
  79. this.createItem(form, this.formListNode);
  80. }.bind(this));
  81. }
  82. }.bind(this));
  83. },
  84. listDictionary: function(){
  85. this.actions.listDictionary(this.data.id, function(json){
  86. if (json.data){
  87. json.data.each(function(dic){
  88. this.createItem(dic, this.dictionaryListNode);
  89. }.bind(this));
  90. }
  91. }.bind(this));
  92. },
  93. listScript: function(){
  94. this.actions.listScript(this.data.id, function(json){
  95. if (json.data){
  96. json.data.each(function(script){
  97. this.createItem(script, this.scriptListNode);
  98. }.bind(this));
  99. }
  100. }.bind(this));
  101. },
  102. inverse: function(node){
  103. var inputs = node.getElements("input");
  104. inputs.each(function(input){
  105. if (input.checked){
  106. input.set("checked", false);
  107. }else{
  108. input.set("checked", true);
  109. }
  110. });
  111. },
  112. createItem: function(data, node){
  113. var item = new Element("div", {"styles": this.css.processItem}).inject(node);
  114. var checkbox = new Element("input", {
  115. "styles": this.css.processItemCheckbox,
  116. "type": "checkbox",
  117. "checked": true
  118. }).inject(item);
  119. checkbox.store("itemData", data);
  120. var textNode = new Element("div", {"text": data.name, "styles": this.css.processItemText}).inject(item);
  121. },
  122. setEvent: function(){
  123. this.cancelButton.addEvent("click", function(e){
  124. this.close();
  125. }.bind(this));
  126. this.okButton.addEvent("click", function(e){
  127. this.exportApplication();
  128. // this.close();
  129. }.bind(this));
  130. },
  131. close: function(){
  132. this.container.unmask();
  133. this.node.destroy();
  134. this.cancelButton = null;
  135. this.okButton = null;
  136. this.buttonAreaNode = null;
  137. this.contentNode = null;
  138. this.titleNode = null;
  139. this.node = null;
  140. this.processListNode = null;
  141. this.formListNode = null;
  142. this.dictionaryListNode = null;
  143. this.scriptListNode = null;
  144. this.fireEvent("close");
  145. },
  146. exportApplication: function(){
  147. this.applicationJson = {
  148. "application": {},
  149. "processList": [],
  150. "formList": [],
  151. "dictionaryList": [],
  152. "scriptList": []
  153. };
  154. this.createProgressBar();
  155. var process = this.processListNode.getElements("input:checked");
  156. var forms = this.formListNode.getElements("input:checked");
  157. var dics = this.dictionaryListNode.getElements("input:checked");
  158. var scripts = this.scriptListNode.getElements("input:checked");
  159. this.status = {
  160. "count": process.length+forms.length+dics.length+scripts.length+1,
  161. "complete": 0
  162. }
  163. this.exportProperty();
  164. this.exportProcesses(process);
  165. this.exportForms(forms);
  166. this.exportDictionarys(dics);
  167. this.exportScripts(scripts);
  168. },
  169. exportProperty: function(){
  170. this.actions.getApplication(this.data.id, function(json){
  171. this.progressBarTextNode.set("text", "load Application Property ...");
  172. if (json.data){
  173. this.applicationJson.application = json.data;
  174. }
  175. this.checkExport();
  176. }.bind(this));
  177. },
  178. exportProcesses: function(processes){
  179. processes.each(function(processCheckbox){
  180. var process = processCheckbox.retrieve("itemData");
  181. this.actions.getProcess(process.id, function(json){
  182. this.progressBarTextNode.set("text", "load Process \""+process.name+"\" ...");
  183. if (json.data){
  184. this.applicationJson.processList.push(json.data);
  185. }
  186. this.checkExport();
  187. }.bind(this));
  188. }.bind(this));
  189. },
  190. exportForms: function(forms){
  191. forms.each(function(formCheckbox){
  192. var form = formCheckbox.retrieve("itemData");
  193. this.actions.getForm(form.id, function(json){
  194. this.progressBarTextNode.set("text", "load Form \""+form.name+"\" ...");
  195. if (json.data){
  196. this.applicationJson.formList.push(json.data);
  197. }
  198. this.checkExport();
  199. }.bind(this));
  200. }.bind(this));
  201. },
  202. exportDictionarys: function(dics){
  203. dics.each(function(dicCheckbox){
  204. var dic = dicCheckbox.retrieve("itemData");
  205. this.actions.getDictionary(dic.id, function(json){
  206. this.progressBarTextNode.set("text", "load Dictionary \""+dic.name+"\" ...");
  207. if (json.data){
  208. this.applicationJson.dictionaryList.push(json.data);
  209. }
  210. this.checkExport();
  211. }.bind(this));
  212. }.bind(this));
  213. },
  214. exportScripts: function(scripts){
  215. scripts.each(function(scriptCheckbox){
  216. var script = scriptCheckbox.retrieve("itemData");
  217. this.actions.getScript(script.id, function(json){
  218. this.progressBarTextNode.set("text", "load Script \""+script.name+"\" ...");
  219. if (json.data){
  220. this.applicationJson.scriptList.push(json.data);
  221. }
  222. this.checkExport();
  223. }.bind(this));
  224. }.bind(this));
  225. },
  226. checkExport: function(){
  227. this.status.complete = this.status.complete+1;
  228. var x = 358*(this.status.complete/this.status.count);
  229. this.progressBarPercent.setStyle("width", ""+x+"px");
  230. if (this.status.complete == this.status.count){
  231. this.saveApplicationToLocal();
  232. }
  233. },
  234. saveApplicationToLocal: function(){
  235. if (window.hasOwnProperty("ActiveXObject")){
  236. var win = window.open("", "_blank");
  237. win.document.write(JSON.encode(this.applicationJson));
  238. }else{
  239. this.downloadFile(this.data.name+".xapp", JSON.encode(this.applicationJson));
  240. }
  241. this.progressBarNode.destroy();
  242. this.progressBarNode = null;
  243. this.progressBarTextNode = null;
  244. this.progressBar = null;
  245. this.progressBarPercent = null;
  246. this.close();
  247. },
  248. downloadFile: function(fileName, content){
  249. var link = new Element("a", {"text": this.data.name}).inject(this.progressBarTextNode);
  250. var blob = new Blob([content]);
  251. link.download = fileName;
  252. link.href = URL.createObjectURL(blob);
  253. //link.href = "data:text/plain," + content;
  254. var evt = document.createEvent("HTMLEvents");
  255. evt.initEvent("click", false, false);
  256. link.dispatchEvent(evt);
  257. link.click();
  258. },
  259. createProgressBar: function(){
  260. this.node.hide();
  261. this.progressBarNode = new Element("div", {"styles": this.css.progressBarNode});
  262. this.progressBarNode.inject(this.container);
  263. this.progressBarNode.position({
  264. relativeTo: this.container,
  265. position: 'center',
  266. edge: 'center'
  267. });
  268. this.progressBarTextNode = new Element("div", {"styles": this.css.progressBarTextNode}).inject(this.progressBarNode);
  269. this.progressBar = new Element("div", {"styles": this.css.progressBar}).inject(this.progressBarNode);
  270. this.progressBarPercent = new Element("div", {"styles": this.css.progressBarPercent}).inject(this.progressBar);
  271. }
  272. });