Importer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. //MWF.xDesktop.requireApp("cms.Column", "Actions.RestActions", null, false);
  2. MWF.xApplication.cms.Column.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_cms_Column/$Importer/";
  15. this.cssPath = "../x_component_cms_Column/$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. this.actions.listProcess(this.applicationJson.application.id, function(json){
  126. var processList = json.data || [];
  127. this.applicationJson.processList.each(function(process){
  128. var id = "";
  129. process.application = this.applicationJson.application.id;
  130. for (var i=0; i<processList.length; i++){
  131. if (processList[i].name==process.name){
  132. id = processList[i].id;
  133. break;
  134. }
  135. }
  136. if (id) {
  137. process.id = id;
  138. process.begin.process = id;
  139. process.agentList.each(function(a){a.process = id;});
  140. process.cancelList.each(function(a){a.process = id;});
  141. process.choiceList.each(function(a){a.process = id;});
  142. process.embedList.each(function(a){a.process = id;});
  143. process.endList.each(function(a){a.process = id;});
  144. process.invokeList.each(function(a){a.process = id;});
  145. process.manualList.each(function(a){a.process = id;});
  146. process.mergeList.each(function(a){a.process = id;});
  147. process.messageList.each(function(a){a.process = id;});
  148. process.routeList.each(function(a){a.process = id;});
  149. process.parallelList.each(function(a){a.process = id;});
  150. process.serviceList.each(function(a){a.process = id;});
  151. process.splitList.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. });