StatementExplorer.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. MWF.xDesktop.requireApp("query.QueryManager", "StatExplorer", null, false);
  2. MWF.xApplication.query.QueryManager.StatementExplorer = new Class({
  3. Extends: MWF.xApplication.query.QueryManager.StatExplorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "tooltip": {
  8. "create": MWF.xApplication.query.QueryManager.LP.statement.create,
  9. "search": MWF.xApplication.query.QueryManager.LP.statement.search,
  10. "searchText": MWF.xApplication.query.QueryManager.LP.statement.searchText,
  11. "noElement": MWF.xApplication.query.QueryManager.LP.statement.noStatNoticeText
  12. }
  13. },
  14. initialize: function(node, actions, options){
  15. this.setOptions(options);
  16. this.setTooltip();
  17. this.path = "/x_component_query_QueryManager/$Explorer/";
  18. this.cssPath = "/x_component_query_QueryManager/$Explorer/"+this.options.style+"/css.wcss";
  19. this._loadCss();
  20. this.actions = actions;
  21. this.node = $(node);
  22. this.initData();
  23. },
  24. saveItemAsUpdate: function(someItem, data, success, failure){
  25. var item = this.app.options.application;
  26. var id = item.id;
  27. var name = item.name;
  28. data.id = someItem.id;
  29. data.isNewStatement = false;
  30. data.application = id;
  31. data.applicationName = name;
  32. this.app.restActions.saveStatement(data, function(){
  33. if (success) success();
  34. }.bind(this), function(){
  35. if (failure) failure();
  36. }.bind(this));
  37. },
  38. saveItemAsNew: function(dJson, data, success, failure){
  39. var item = this.app.options.application;
  40. var id = item.id;
  41. var name = item.name;
  42. var oldName = data.name;
  43. var i=1;
  44. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  45. data.name = oldName+"_copy"+i;
  46. data.alias = oldName+"_copy"+i;
  47. i++;
  48. }
  49. data.id = "";
  50. data.isNewStatement = true;
  51. data.application = id;
  52. data.applicationName = name;
  53. this.app.restActions.saveStatement(data, function(){
  54. if (success) success();
  55. }.bind(this), function(){
  56. if (failure) failure();
  57. }.bind(this));
  58. },
  59. _createElement: function(e){
  60. var _self = this;
  61. var options = {
  62. "onQueryLoad": function(){
  63. this.actions = _self.app.restActions;
  64. this.application = _self.app.options.application;
  65. this.explorer = _self;
  66. }
  67. };
  68. this.app.desktop.openApplication(e, "query.StatementDesigner", options);
  69. },
  70. _loadItemDataList: function(callback){
  71. this.app.restActions.listStatement(this.app.options.application.id,callback);
  72. },
  73. _getItemObject: function(item){
  74. return new MWF.xApplication.query.QueryManager.StatementExplorer.Statement(this, item);
  75. },
  76. deleteItems: function(){
  77. this.hideDeleteAction();
  78. while (this.deleteMarkItems.length){
  79. var item = this.deleteMarkItems.shift();
  80. if (this.deleteMarkItems.length){
  81. item.deleteStatement();
  82. }else{
  83. item.deleteStatement(function(){
  84. //this.reloadItems();
  85. //this.hideDeleteAction();
  86. }.bind(this));
  87. }
  88. }
  89. }
  90. });
  91. MWF.xApplication.query.QueryManager.StatementExplorer.Statement= new Class({
  92. Extends: MWF.xApplication.query.QueryManager.StatExplorer.Stat,
  93. _open: function(e){
  94. var _self = this;
  95. var options = {
  96. "appId": "query.StatementDesigner"+_self.data.id,
  97. "onQueryLoad": function(){
  98. this.actions = _self.explorer.actions;
  99. this.category = _self;
  100. this.options.id = _self.data.id;
  101. this.application = _self.explorer.app.options.application;
  102. }
  103. };
  104. this.explorer.app.desktop.openApplication(e, "query.StatementDesigner", options);
  105. },
  106. _getIcon: function(){
  107. var x = (Math.random()*49).toInt();
  108. return "process_icon_"+x+".png";
  109. },
  110. _getLnkPar: function(){
  111. return {
  112. "icon": this.explorer.path+this.explorer.options.style+"/statementIcon/lnk.png",
  113. "title": this.data.name,
  114. "par": "query.StatementDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.data.query+"\"}"
  115. };
  116. },
  117. deleteStatement: function(callback){
  118. this.explorer.actions.deleteStatement(this.data.id, function(){
  119. this.node.destroy();
  120. if (callback) callback();
  121. }.bind(this));
  122. },
  123. saveas: function(){
  124. MWF.xDesktop.requireApp("Selector", "package", function(){
  125. var selector = new MWF.O2Selector(this.explorer.app.content, {
  126. "title": this.explorer.app.lp.copyto,
  127. "type": "Query",
  128. "values": [this.explorer.app.options.application],
  129. "onComplete": function(items){
  130. items.each(function(item){
  131. this.saveItemAs(item.data);
  132. }.bind(this));
  133. }.bind(this),
  134. });
  135. }.bind(this));
  136. },
  137. saveItemAs: function(item){
  138. var id = item.id;
  139. var name = item.name;
  140. this.explorer.app.restActions.getTable(this.data.id, function(json){
  141. var data = json.data;
  142. var dataJson = (data.data) ? JSON.decode(data.data): "";
  143. data.data = dataJson;
  144. data.data.id = "";
  145. var oldName = data.name;
  146. this.explorer.app.restActions.listTable(id, function(dJson){
  147. var i=1;
  148. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  149. data.name = oldName+"_copy"+i;
  150. data.alias = oldName+"_copy"+i;
  151. i++;
  152. }
  153. data.id = "";
  154. data.isNewTable = true;
  155. data.application = id;
  156. data.applicationName = name;
  157. this.explorer.app.restActions.saveTable(data, function(){
  158. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  159. }.bind(this));
  160. }.bind(this));
  161. }.bind(this));
  162. }
  163. });