TableExplorer.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. MWF.xDesktop.requireApp("query.QueryManager", "StatExplorer", null, false);
  2. MWF.xApplication.query.QueryManager.TableExplorer = 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.table.create,
  9. "search": MWF.xApplication.query.QueryManager.LP.table.search,
  10. "searchText": MWF.xApplication.query.QueryManager.LP.table.searchText,
  11. "noElement": MWF.xApplication.query.QueryManager.LP.table.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. //var dataJson = (data.data) ? JSON.decode(data.data): "";
  29. var draftDataJson = (data.draftData) ? JSON.decode(data.draftData): "";
  30. data.status = "draft";
  31. data.draftData = draftDataJson;
  32. data.data.id = someItem.id;
  33. data.id = someItem.id;
  34. data.isNewTable = false;
  35. data.application = id;
  36. data.applicationName = name;
  37. this.app.restActions.saveTable(data, function(){
  38. if (success) success();
  39. }.bind(this), function(){
  40. if (failure) failure();
  41. }.bind(this));
  42. },
  43. saveItemAsNew: function(dJson, data, success, failure){
  44. var item = this.app.options.application;
  45. var id = item.id;
  46. var name = item.name;
  47. var oldName = data.name;
  48. var i=1;
  49. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  50. data.name = oldName+"_copy"+i;
  51. data.alias = oldName+"_copy"+i;
  52. i++;
  53. }
  54. var dataJson = (data.data) ? JSON.decode(data.data): "";
  55. data.data = dataJson;
  56. data.data.id = "";
  57. data.id = "";
  58. data.isNewTable = true;
  59. data.application = id;
  60. data.applicationName = name;
  61. this.app.restActions.saveTable(data, function(){
  62. if (success) success();
  63. }.bind(this), function(){
  64. if (failure) failure();
  65. }.bind(this));
  66. },
  67. _createElement: function(e){
  68. var _self = this;
  69. var options = {
  70. "onQueryLoad": function(){
  71. this.actions = _self.app.restActions;
  72. this.application = _self.app.options.application;
  73. this.explorer = _self;
  74. }
  75. };
  76. this.app.desktop.openApplication(e, "query.TableDesigner", options);
  77. },
  78. _loadItemDataList: function(callback){
  79. this.app.restActions.listTable(this.app.options.application.id,callback);
  80. },
  81. _getItemObject: function(item){
  82. return new MWF.xApplication.query.QueryManager.TableExplorer.Table(this, item);
  83. },
  84. deleteItems: function(){
  85. this.hideDeleteAction();
  86. while (this.deleteMarkItems.length){
  87. var item = this.deleteMarkItems.shift();
  88. if (this.deleteMarkItems.length){
  89. item.deleteTable();
  90. }else{
  91. item.deleteTable(function(){
  92. //this.reloadItems();
  93. //this.hideDeleteAction();
  94. }.bind(this));
  95. }
  96. }
  97. }
  98. });
  99. MWF.xApplication.query.QueryManager.TableExplorer.Table= new Class({
  100. Extends: MWF.xApplication.query.QueryManager.StatExplorer.Stat,
  101. _open: function(e){
  102. var _self = this;
  103. var options = {
  104. "appId": "query.TableDesigner"+_self.data.id,
  105. "onQueryLoad": function(){
  106. this.actions = _self.explorer.actions;
  107. this.category = _self;
  108. this.options.id = _self.data.id;
  109. this.application = _self.explorer.app.options.application;
  110. }
  111. };
  112. this.explorer.app.desktop.openApplication(e, "query.TableDesigner", options);
  113. },
  114. _getIcon: function(){
  115. var x = (Math.random()*49).toInt();
  116. return "process_icon_"+x+".png";
  117. },
  118. _getLnkPar: function(){
  119. return {
  120. "icon": this.explorer.path+this.explorer.options.style+"/tableIcon/lnk.png",
  121. "title": this.data.name,
  122. "par": "query.TableDesigner#{\"appId\": \"query.TableDesigner"+this.data.id+"\", \"id\": \""+this.data.id+"\", \"applicationId\": \""+this.data.query+"\"}"
  123. };
  124. },
  125. deleteTable: function(callback){
  126. this.explorer.actions.deleteTable(this.data.id, function(){
  127. this.node.destroy();
  128. if (callback) callback();
  129. }.bind(this));
  130. },
  131. saveas: function(){
  132. MWF.xDesktop.requireApp("Selector", "package", function(){
  133. var selector = new MWF.O2Selector(this.explorer.app.content, {
  134. "title": this.explorer.app.lp.copyto,
  135. "type": "Query",
  136. "values": [this.explorer.app.options.application],
  137. "onComplete": function(items){
  138. items.each(function(item){
  139. this.saveItemAs(item.data);
  140. }.bind(this));
  141. }.bind(this),
  142. });
  143. }.bind(this));
  144. },
  145. saveItemAs: function(item){
  146. var id = item.id;
  147. var name = item.name;
  148. this.explorer.app.restActions.getTable(this.data.id, function(json){
  149. var data = json.data;
  150. var dataJson = (data.data) ? JSON.decode(data.data): "";
  151. data.data = dataJson;
  152. data.data.id = "";
  153. var oldName = data.name;
  154. this.explorer.app.restActions.listTable(id, function(dJson){
  155. var i=1;
  156. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  157. data.name = oldName+"_copy"+i;
  158. data.alias = oldName+"_copy"+i;
  159. i++;
  160. }
  161. data.id = "";
  162. data.isNewTable = true;
  163. data.application = id;
  164. data.applicationName = name;
  165. this.explorer.app.restActions.saveTable(data, function(){
  166. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  167. }.bind(this));
  168. }.bind(this));
  169. }.bind(this));
  170. }
  171. });