Importer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. MWF.xApplication.process.ApplicationExplorer.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_process_ApplicationExplorer/$Importer/";
  14. this.cssPath = "../x_component_process_ApplicationExplorer/$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.processList.length+this.applicationJson.formList.length+this.applicationJson.dictionaryList.length+this.applicationJson.scriptList.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.importOverwriteFormList();
  107. this.importOverwriteDictionaryList();
  108. this.importOverwriteScriptList();
  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.importOverwriteFormList();
  120. this.importOverwriteDictionaryList();
  121. this.importOverwriteScriptList();
  122. },
  123. importOverwriteProcessList: function() {
  124. this.actions.listProcess(this.applicationJson.application.id, function(json){
  125. var processList = json.data || [];
  126. this.applicationJson.processList.each(function(process){
  127. var id = "";
  128. process.application = this.applicationJson.application.id;
  129. for (var i=0; i<processList.length; i++){
  130. if (processList[i].name==process.name){
  131. id = processList[i].id;
  132. break;
  133. }
  134. }
  135. if (id) {
  136. process.id = id;
  137. process.begin.process = id;
  138. process.agentList.each(function(a){a.process = id;});
  139. process.cancelList.each(function(a){a.process = id;});
  140. process.choiceList.each(function(a){a.process = id;});
  141. process.embedList.each(function(a){a.process = id;});
  142. process.endList.each(function(a){a.process = id;});
  143. process.invokeList.each(function(a){a.process = id;});
  144. process.manualList.each(function(a){a.process = id;});
  145. process.mergeList.each(function(a){a.process = id;});
  146. process.messageList.each(function(a){a.process = id;});
  147. process.routeList.each(function(a){a.process = id;});
  148. process.parallelList.each(function(a){a.process = id;});
  149. process.serviceList.each(function(a){a.process = id;});
  150. process.splitList.each(function(a){a.process = id;});
  151. if(process.publishList)process.publishList.each(function(a){a.process = id;});
  152. this.actions.updateProcess(process, function(){
  153. this.progressBarTextNode.set("text", "Import Process \""+process.name+"\" ...");
  154. this.checkExport();
  155. }.bind(this));
  156. }else{
  157. this.actions.addProcess(process, function(){
  158. this.progressBarTextNode.set("text", "Import Process \""+process.name+"\" ...");
  159. this.checkExport();
  160. }.bind(this));
  161. }
  162. }.bind(this));
  163. }.bind(this));
  164. },
  165. importOverwriteFormList: function(){
  166. this.actions.listForm(this.applicationJson.application.id, function(json){
  167. var formList = json.data || [];
  168. this.applicationJson.formList.each(function(form){
  169. form.application = this.applicationJson.application.id;
  170. var id = "";
  171. for (var i=0; i<formList.length; i++){
  172. if (formList[i].name==form.name){
  173. id = formList[i].id;
  174. break;
  175. }
  176. }
  177. if (id) {
  178. form.id = id;
  179. this.actions.action.invoke({"name": "updataForm","data": form,"parameter": {"id": form.id},"success": function(){
  180. this.progressBarTextNode.set("text", "Import Form \""+form.name+"\" ...");
  181. this.checkExport();
  182. }.bind(this)});
  183. }else{
  184. this.actions.action.invoke({"name": "addForm","data": form,"parameter": {"id": form.id},"success": function(){
  185. this.progressBarTextNode.set("text", "Import Form \""+form.name+"\" ...");
  186. this.checkExport();
  187. }.bind(this)});
  188. }
  189. }.bind(this));
  190. }.bind(this));
  191. },
  192. importOverwriteDictionaryList: function(){
  193. this.actions.listDictionary(this.applicationJson.application.id, function(json){
  194. var dicList = json.data || [];
  195. this.applicationJson.dictionaryList.each(function(dictionary){
  196. dictionary.application = this.applicationJson.application.id;
  197. var id = "";
  198. for (var i=0; i<dicList.length; i++){
  199. if (dicList[i].name==dictionary.name){
  200. id = dicList[i].id;
  201. break;
  202. }
  203. }
  204. if (id){
  205. dictionary.id = id;
  206. this.actions.updateDictionary(dictionary, function(){
  207. this.progressBarTextNode.set("text", "Import Process \""+dictionary.name+"\" ...");
  208. this.checkExport();
  209. }.bind(this));
  210. }else{
  211. this.actions.addDictionary(dictionary, function(){
  212. this.progressBarTextNode.set("text", "Import Process \""+dictionary.name+"\" ...");
  213. this.checkExport();
  214. }.bind(this));
  215. }
  216. }.bind(this));
  217. }.bind(this));
  218. },
  219. importOverwriteScriptList: function(){
  220. this.actions.listScript(this.applicationJson.application.id, function(json){
  221. var scriptList = json.data || [];
  222. this.applicationJson.scriptList.each(function(script){
  223. script.application = this.applicationJson.application.id;
  224. var id = "";
  225. for (var i=0; i<scriptList.length; i++){
  226. if (scriptList[i].name==script.name){
  227. id = scriptList[i].id;
  228. break;
  229. }
  230. }
  231. if (id){
  232. script.id = id;
  233. this.actions.updateScript(script, function(){
  234. this.progressBarTextNode.set("text", "Import Process \""+script.name+"\" ...");
  235. this.checkExport();
  236. }.bind(this));
  237. }else{
  238. this.actions.addScript(script, function(){
  239. this.progressBarTextNode.set("text", "Import Process \""+script.name+"\" ...");
  240. this.checkExport();
  241. }.bind(this));
  242. }
  243. }.bind(this));
  244. }.bind(this));
  245. },
  246. checkExport: function(){
  247. this.status.complete = this.status.complete+1;
  248. var x = 358*(this.status.complete/this.status.count);
  249. this.progressBarPercent.setStyle("width", ""+x+"px");
  250. if (this.status.complete == this.status.count){
  251. this.progressBarNode.destroy();
  252. this.progressBarNode = null;
  253. this.progressBarTextNode = null;
  254. this.progressBar = null;
  255. this.progressBarPercent = null;
  256. this.close();
  257. }
  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. });