TableExplorer.js 6.0 KB

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