Importer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. MWF.xDesktop.requireApp("process.ApplicationExplorer", "Actions.RestActions", null, false);
  2. MWF.xApplication.process.ApplicationExplorer.Importer = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default"
  7. },
  8. initialize: function(app, e, options){
  9. this.setOptions(options);
  10. this.app = app;
  11. this.container = this.app.content;
  12. this.actions = this.app.restActions;
  13. this.event = e;
  14. this.path = "/x_component_process_ApplicationExplorer/$Importer/";
  15. this.cssPath = "/x_component_process_ApplicationExplorer/$Importer/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. },
  18. load: function(){
  19. this.container.mask({
  20. "destroyOnHide": true,
  21. "style": {
  22. "background-color": "#666",
  23. "opacity": 0.6
  24. }
  25. });
  26. this.node = new Element("div", {"styles": this.css.content});
  27. this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.app.lp.application.import}).inject(this.node);
  28. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  29. this.buttonAreaNode = new Element("div", {"styles": this.css.buttonAreaNode}).inject(this.node);
  30. this.cancelButton = new Element("div", {"styles": this.css.button, "text": this.app.lp.application.export_cancel}).inject(this.buttonAreaNode);
  31. this.okButton = new Element("div", {"styles": this.css.okButton, "text": this.app.lp.application.export_ok}).inject(this.buttonAreaNode);
  32. this.loadContent();
  33. this.setEvent();
  34. this.node.inject(this.container);
  35. this.node.position({
  36. relativeTo: this.container,
  37. position: 'center',
  38. edge: 'center'
  39. });
  40. },
  41. loadContent: function(){
  42. this.textarea = new Element("textarea", {"styles": this.css.textarea}).inject(this.contentNode);
  43. },
  44. setEvent: function(){
  45. this.cancelButton.addEvent("click", function(e){
  46. this.close();
  47. }.bind(this));
  48. this.okButton.addEvent("click", function(e){
  49. this.importApplication();
  50. }.bind(this));
  51. },
  52. close: function(){
  53. this.container.unmask();
  54. this.node.destroy();
  55. this.cancelButton = null;
  56. this.okButton = null;
  57. this.buttonAreaNode = null;
  58. this.contentNode = null;
  59. this.titleNode = null;
  60. this.node = null;
  61. this.fireEvent("close");
  62. },
  63. importApplication: function(){
  64. var str = this.textarea.get("value");
  65. if (str){
  66. this.applicationJson = JSON.decode(str);
  67. var name = this.applicationJson.application.name
  68. this.actions.listApplicationSummary("", function(json){
  69. var flag = "create";
  70. var overApplication = null;
  71. if (json.data){
  72. for (var i=0; i<json.data.length; i++){
  73. if (json.data[i].name == name){
  74. overApplication = json.data[i];
  75. flag = "overwrite";
  76. break;
  77. }
  78. }
  79. }
  80. if (flag == "overwrite"){
  81. var _self = this;
  82. this.app.confirm("infor", this.event, this.app.lp.application.import_confirm_title, this.app.lp.application.import_confirm, 400, 180, function(){
  83. _self.doImportOverwriteApplication(overApplication);
  84. this.close();
  85. }, function(){
  86. this.close();
  87. })
  88. }else{
  89. this.doImportApplication();
  90. }
  91. }.bind(this));
  92. }
  93. },
  94. readyProrressBar: function(){
  95. this.createProgressBar();
  96. this.status = {
  97. "count": this.applicationJson.processList.length+this.applicationJson.formList.length+this.applicationJson.dictionaryList.length+this.applicationJson.scriptList.length+1,
  98. "complete": 0
  99. }
  100. },
  101. doImportApplication: function(){
  102. this.readyProrressBar();
  103. this.actions.action.invoke({"name": "addApplication","data": this.applicationJson.application,"success": function(){
  104. this.progressBarTextNode.set("text", "Import Application Property ...");
  105. this.checkExport();
  106. this.importOverwriteProcessList();
  107. this.importOverwriteFormList();
  108. this.importOverwriteDictionaryList();
  109. this.importOverwriteScriptList();
  110. }.bind(this)});
  111. },
  112. doImportOverwriteApplication: function(overApplication){
  113. this.readyProrressBar();
  114. this.applicationJson.application.id = overApplication.id;
  115. this.actions.saveApplication(this.applicationJson.application, function(){
  116. this.progressBarTextNode.set("text", "Import Application Property ...");
  117. this.checkExport();
  118. }.bind(this));
  119. this.importOverwriteProcessList();
  120. this.importOverwriteFormList();
  121. this.importOverwriteDictionaryList();
  122. this.importOverwriteScriptList();
  123. },
  124. importOverwriteProcessList: function() {
  125. debugger;
  126. this.actions.listProcess(this.applicationJson.application.id, function(json){
  127. var processList = json.data || [];
  128. this.applicationJson.processList.each(function(process){
  129. var id = "";
  130. process.application = this.applicationJson.application.id;
  131. for (var i=0; i<processList.length; i++){
  132. if (processList[i].name==process.name){
  133. id = processList[i].id;
  134. break;
  135. }
  136. }
  137. if (id) {
  138. process.id = id;
  139. process.begin.process = id;
  140. process.agentList.each(function(a){a.process = id;});
  141. process.cancelList.each(function(a){a.process = id;});
  142. process.choiceList.each(function(a){a.process = id;});
  143. process.embedList.each(function(a){a.process = id;});
  144. process.endList.each(function(a){a.process = id;});
  145. process.invokeList.each(function(a){a.process = id;});
  146. process.manualList.each(function(a){a.process = id;});
  147. process.mergeList.each(function(a){a.process = id;});
  148. process.messageList.each(function(a){a.process = id;});
  149. process.routeList.each(function(a){a.process = id;});
  150. process.parallelList.each(function(a){a.process = id;});
  151. process.serviceList.each(function(a){a.process = id;});
  152. process.splitList.each(function(a){a.process = id;});
  153. this.actions.updateProcess(process, function(){
  154. this.progressBarTextNode.set("text", "Import Process \""+process.name+"\" ...");
  155. this.checkExport();
  156. }.bind(this));
  157. }else{
  158. this.actions.addProcess(process, function(){
  159. this.progressBarTextNode.set("text", "Import Process \""+process.name+"\" ...");
  160. this.checkExport();
  161. }.bind(this));
  162. }
  163. }.bind(this));
  164. }.bind(this));
  165. },
  166. importOverwriteFormList: function(){
  167. this.actions.listForm(this.applicationJson.application.id, function(json){
  168. var formList = json.data || [];
  169. this.applicationJson.formList.each(function(form){
  170. form.application = this.applicationJson.application.id;
  171. var id = "";
  172. for (var i=0; i<formList.length; i++){
  173. if (formList[i].name==form.name){
  174. id = formList[i].id;
  175. break;
  176. }
  177. }
  178. if (id) {
  179. form.id = id;
  180. this.actions.action.invoke({"name": "updataForm","data": form,"parameter": {"id": form.id},"success": function(){
  181. this.progressBarTextNode.set("text", "Import Form \""+form.name+"\" ...");
  182. this.checkExport();
  183. }.bind(this)});
  184. }else{
  185. this.actions.action.invoke({"name": "addForm","data": form,"parameter": {"id": form.id},"success": function(){
  186. this.progressBarTextNode.set("text", "Import Form \""+form.name+"\" ...");
  187. this.checkExport();
  188. }.bind(this)});
  189. }
  190. }.bind(this));
  191. }.bind(this));
  192. },
  193. importOverwriteDictionaryList: function(){
  194. this.actions.listDictionary(this.applicationJson.application.id, function(json){
  195. var dicList = json.data || [];
  196. this.applicationJson.dictionaryList.each(function(dictionary){
  197. dictionary.application = this.applicationJson.application.id;
  198. var id = "";
  199. for (var i=0; i<dicList.length; i++){
  200. if (dicList[i].name==dictionary.name){
  201. id = dicList[i].id;
  202. break;
  203. }
  204. }
  205. if (id){
  206. dictionary.id = id;
  207. this.actions.updateDictionary(dictionary, function(){
  208. this.progressBarTextNode.set("text", "Import Process \""+dictionary.name+"\" ...");
  209. this.checkExport();
  210. }.bind(this));
  211. }else{
  212. this.actions.addDictionary(dictionary, function(){
  213. this.progressBarTextNode.set("text", "Import Process \""+dictionary.name+"\" ...");
  214. this.checkExport();
  215. }.bind(this));
  216. }
  217. }.bind(this));
  218. }.bind(this));
  219. },
  220. importOverwriteScriptList: function(){
  221. this.actions.listScript(this.applicationJson.application.id, function(json){
  222. var scriptList = json.data || [];
  223. this.applicationJson.scriptList.each(function(script){
  224. script.application = this.applicationJson.application.id;
  225. var id = "";
  226. for (var i=0; i<scriptList.length; i++){
  227. if (scriptList[i].name==script.name){
  228. id = scriptList[i].id;
  229. break;
  230. }
  231. }
  232. if (id){
  233. script.id = id;
  234. this.actions.updateScript(script, function(){
  235. this.progressBarTextNode.set("text", "Import Process \""+script.name+"\" ...");
  236. this.checkExport();
  237. }.bind(this));
  238. }else{
  239. this.actions.addScript(script, function(){
  240. this.progressBarTextNode.set("text", "Import Process \""+script.name+"\" ...");
  241. this.checkExport();
  242. }.bind(this));
  243. }
  244. }.bind(this));
  245. }.bind(this));
  246. },
  247. checkExport: function(){
  248. this.status.complete = this.status.complete+1;
  249. var x = 358*(this.status.complete/this.status.count);
  250. this.progressBarPercent.setStyle("width", ""+x+"px");
  251. if (this.status.complete == this.status.count){
  252. this.progressBarNode.destroy();
  253. this.progressBarNode = null;
  254. this.progressBarTextNode = null;
  255. this.progressBar = null;
  256. this.progressBarPercent = null;
  257. this.close();
  258. }
  259. },
  260. createProgressBar: function(){
  261. this.node.hide();
  262. this.progressBarNode = new Element("div", {"styles": this.css.progressBarNode});
  263. this.progressBarNode.inject(this.container);
  264. this.progressBarNode.position({
  265. relativeTo: this.container,
  266. position: 'center',
  267. edge: 'center'
  268. });
  269. this.progressBarTextNode = new Element("div", {"styles": this.css.progressBarTextNode}).inject(this.progressBarNode);
  270. this.progressBar = new Element("div", {"styles": this.css.progressBar}).inject(this.progressBarNode);
  271. this.progressBarPercent = new Element("div", {"styles": this.css.progressBarPercent}).inject(this.progressBar);
  272. }
  273. });