Importer.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. MWF.xApplication.query.QueryExplorer.Importer = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default"
  6. },
  7. initialize: function(app, e, options){
  8. this.setOptions(options);
  9. this.app = app;
  10. this.container = this.app.content;
  11. this.actions = this.app.restActions;
  12. this.event = e;
  13. this.path = "../x_component_query_QueryExplorer/$Importer/";
  14. this.cssPath = "../x_component_query_QueryExplorer/$Importer/"+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.application.import}).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.application.export_cancel}).inject(this.buttonAreaNode);
  30. this.okButton = new Element("div", {"styles": this.css.okButton, "text": this.app.lp.application.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.textarea = new Element("textarea", {"styles": this.css.textarea}).inject(this.contentNode);
  42. },
  43. setEvent: function(){
  44. this.cancelButton.addEvent("click", function(e){
  45. this.close();
  46. }.bind(this));
  47. this.okButton.addEvent("click", function(e){
  48. this.importApplication();
  49. }.bind(this));
  50. },
  51. close: function(){
  52. this.container.unmask();
  53. this.node.destroy();
  54. this.cancelButton = null;
  55. this.okButton = null;
  56. this.buttonAreaNode = null;
  57. this.contentNode = null;
  58. this.titleNode = null;
  59. this.node = null;
  60. this.fireEvent("close");
  61. },
  62. importApplication: function(){
  63. var str = this.textarea.get("value");
  64. if (str){
  65. this.applicationJson = JSON.decode(str);
  66. var name = this.applicationJson.application.name;
  67. this.actions.listApplicationSummary("", function(json){
  68. var flag = "create";
  69. var overApplication = null;
  70. if (json.data){
  71. for (var i=0; i<json.data.length; i++){
  72. if (json.data[i].name == name){
  73. overApplication = json.data[i];
  74. flag = "overwrite";
  75. break;
  76. }
  77. }
  78. }
  79. if (flag == "overwrite"){
  80. var _self = this;
  81. this.app.confirm("infor", this.event, this.app.lp.application.import_confirm_title, this.app.lp.application.import_confirm, 400, 180, function(){
  82. _self.doImportOverwriteApplication(overApplication);
  83. this.close();
  84. }, function(){
  85. this.close();
  86. })
  87. }else{
  88. this.doImportApplication();
  89. }
  90. }.bind(this));
  91. }
  92. },
  93. readyProrressBar: function(){
  94. this.createProgressBar();
  95. this.status = {
  96. "count": this.applicationJson.viewList.length+this.applicationJson.statList.length+1,
  97. "complete": 0
  98. }
  99. },
  100. doImportApplication: function(){
  101. this.readyProrressBar();
  102. this.actions.action.invoke({"name": "addApplication","data": this.applicationJson.application,"success": function(){
  103. this.progressBarTextNode.set("text", "Import Application Property ...");
  104. this.checkExport();
  105. //this.importOverwriteProcessList();
  106. this.importOverwriteViewList();
  107. //this.importOverwriteDictionaryList();
  108. this.importOverwriteStatList();
  109. }.bind(this)});
  110. },
  111. doImportOverwriteApplication: function(overApplication){
  112. this.readyProrressBar();
  113. this.applicationJson.application.id = overApplication.id;
  114. this.actions.saveApplication(this.applicationJson.application, function(){
  115. this.progressBarTextNode.set("text", "Import Application Property ...");
  116. this.checkExport();
  117. }.bind(this));
  118. //this.importOverwriteProcessList();
  119. //this.importOverwritePageList();
  120. //this.importOverwriteDictionaryList();
  121. //this.importOverwriteScriptList();
  122. this.importOverwriteViewList();
  123. this.importOverwriteStatList();
  124. },
  125. //importOverwriteProcessList: function() {
  126. // debugger;
  127. // this.actions.listProcess(this.applicationJson.application.id, function(json){
  128. // var processList = json.data || [];
  129. //
  130. // this.applicationJson.processList.each(function(process){
  131. // var id = "";
  132. // process.application = this.applicationJson.application.id;
  133. // for (var i=0; i<processList.length; i++){
  134. // if (processList[i].name==process.name){
  135. // id = processList[i].id;
  136. // break;
  137. // }
  138. // }
  139. //
  140. // if (id) {
  141. // process.id = id;
  142. // process.begin.process = id;
  143. // process.agentList.each(function(a){a.process = id;});
  144. // process.cancelList.each(function(a){a.process = id;});
  145. // process.choiceList.each(function(a){a.process = id;});
  146. // process.embedList.each(function(a){a.process = id;});
  147. // process.endList.each(function(a){a.process = id;});
  148. // process.invokeList.each(function(a){a.process = id;});
  149. // process.manualList.each(function(a){a.process = id;});
  150. // process.mergeList.each(function(a){a.process = id;});
  151. // process.messageList.each(function(a){a.process = id;});
  152. // process.routeList.each(function(a){a.process = id;});
  153. // process.parallelList.each(function(a){a.process = id;});
  154. // process.serviceList.each(function(a){a.process = id;});
  155. // process.splitList.each(function(a){a.process = id;});
  156. //
  157. // this.actions.updateProcess(process, function(){
  158. // this.progressBarTextNode.set("text", "Import Process \""+process.name+"\" ...");
  159. // this.checkExport();
  160. // }.bind(this));
  161. // }else{
  162. //
  163. //
  164. // this.actions.addProcess(process, function(){
  165. // this.progressBarTextNode.set("text", "Import Process \""+process.name+"\" ...");
  166. // this.checkExport();
  167. // }.bind(this));
  168. // }
  169. // }.bind(this));
  170. // }.bind(this));
  171. //},
  172. // importOverwritePageList: function(){
  173. // this.actions.listPage(this.applicationJson.application.id, function(json){
  174. // var formList = json.data || [];
  175. // this.applicationJson.pageList.each(function(form){
  176. // form.application = this.applicationJson.application.id;
  177. // var id = "";
  178. // for (var i=0; i<formList.length; i++){
  179. // if (formList[i].name==form.name){
  180. // id = formList[i].id;
  181. // break;
  182. // }
  183. // }
  184. // if (id) {
  185. // form.id = id;
  186. // this.actions.action.invoke({"name": "updatePage","data": form,"parameter": {"id": form.id},"success": function(){
  187. // this.progressBarTextNode.set("text", "Import Page \""+form.name+"\" ...");
  188. // this.checkExport();
  189. // }.bind(this)});
  190. // }else{
  191. // this.actions.action.invoke({"name": "addPage","data": form,"parameter": {"id": form.id},"success": function(){
  192. // //this.progressBarTextNode.set("text", "Import Page \""+form.name+"\" ...");
  193. // this.checkExport();
  194. // }.bind(this)});
  195. // }
  196. //
  197. // }.bind(this));
  198. // }.bind(this));
  199. // },
  200. //importOverwriteDictionaryList: function(){
  201. // this.actions.listDictionary(this.applicationJson.application.id, function(json){
  202. // var dicList = json.data || [];
  203. // this.applicationJson.dictionaryList.each(function(dictionary){
  204. // dictionary.application = this.applicationJson.application.id;
  205. // var id = "";
  206. // for (var i=0; i<dicList.length; i++){
  207. // if (dicList[i].name==dictionary.name){
  208. // id = dicList[i].id;
  209. // break;
  210. // }
  211. // }
  212. // if (id){
  213. // dictionary.id = id;
  214. // this.actions.updateDictionary(dictionary, function(){
  215. // this.progressBarTextNode.set("text", "Import Process \""+dictionary.name+"\" ...");
  216. // this.checkExport();
  217. // }.bind(this));
  218. // }else{
  219. // this.actions.addDictionary(dictionary, function(){
  220. // this.progressBarTextNode.set("text", "Import Process \""+dictionary.name+"\" ...");
  221. // this.checkExport();
  222. // }.bind(this));
  223. // }
  224. // }.bind(this));
  225. // }.bind(this));
  226. //},
  227. importOverwriteViewList: function(){
  228. this.actions.listView(this.applicationJson.application.id, function(json){
  229. var viewList = json.data || [];
  230. this.applicationJson.viewList.each(function(view){
  231. view.application = this.applicationJson.application.id;
  232. var id = "";
  233. for (var i=0; i<viewList.length; i++){
  234. if (viewList[i].name==view.name){
  235. id = viewList[i].id;
  236. break;
  237. }
  238. }
  239. var data = JSON.decode(view.data);
  240. view.data = data;
  241. if (id){
  242. view.id = id;
  243. this.actions.updateView(view, function(){
  244. this.progressBarTextNode.set("text", "Import View \""+view.name+"\" ...");
  245. this.checkExport();
  246. }.bind(this));
  247. }else{
  248. this.actions.addView(view, function(){
  249. this.progressBarTextNode.set("text", "Import View \""+view.name+"\" ...");
  250. this.checkExport();
  251. }.bind(this));
  252. }
  253. }.bind(this));
  254. }.bind(this));
  255. },
  256. importOverwriteStatList: function(){
  257. this.actions.listStat(this.applicationJson.application.id, function(json){
  258. var statList = json.data || [];
  259. this.applicationJson.statList.each(function(stat){
  260. stat.application = this.applicationJson.application.id;
  261. var id = "";
  262. for (var i=0; i<statList.length; i++){
  263. if (statList[i].name==stat.name){
  264. id = statList[i].id;
  265. break;
  266. }
  267. }
  268. var data = JSON.decode(stat.data);
  269. stat.data = data;
  270. if (id){
  271. stat.id = id;
  272. this.actions.updateStat(stat, function(){
  273. this.progressBarTextNode.set("text", "Import Stat \""+stat.name+"\" ...");
  274. this.checkExport();
  275. }.bind(this));
  276. }else{
  277. this.actions.addStat(stat, function(){
  278. this.progressBarTextNode.set("text", "Import Stat \""+stat.name+"\" ...");
  279. this.checkExport();
  280. }.bind(this));
  281. }
  282. }.bind(this));
  283. }.bind(this));
  284. },
  285. checkExport: function(){
  286. this.status.complete = this.status.complete+1;
  287. var x = 358*(this.status.complete/this.status.count);
  288. this.progressBarPercent.setStyle("width", ""+x+"px");
  289. if (this.status.complete == this.status.count){
  290. this.progressBarNode.destroy();
  291. this.progressBarNode = null;
  292. this.progressBarTextNode = null;
  293. this.progressBar = null;
  294. this.progressBarPercent = null;
  295. this.close();
  296. }
  297. },
  298. createProgressBar: function(){
  299. this.node.hide();
  300. this.progressBarNode = new Element("div", {"styles": this.css.progressBarNode});
  301. this.progressBarNode.inject(this.container);
  302. this.progressBarNode.position({
  303. relativeTo: this.container,
  304. position: 'center',
  305. edge: 'center'
  306. });
  307. this.progressBarTextNode = new Element("div", {"styles": this.css.progressBarTextNode}).inject(this.progressBarNode);
  308. this.progressBar = new Element("div", {"styles": this.css.progressBar}).inject(this.progressBarNode);
  309. this.progressBarPercent = new Element("div", {"styles": this.css.progressBarPercent}).inject(this.progressBar);
  310. }
  311. });