Exporter.js 15 KB

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