Main.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.QueryExplorer = MWF.xApplication.query.QueryExplorer || {};
  3. MWF.xDesktop.requireApp("process.ApplicationExplorer", "", null, false);
  4. MWF.xApplication.query.QueryExplorer.Main = new Class({
  5. Extends: MWF.xApplication.process.ApplicationExplorer.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "query.QueryExplorer",
  10. "mvcStyle": "style.css",
  11. "icon": "icon.png",
  12. "width": "1500",
  13. "height": "760",
  14. "isResize": true,
  15. "isMax": true,
  16. "title": MWF.xApplication.query.QueryExplorer.LP.title,
  17. "maxWidth": 840,
  18. "minWidth": 540
  19. },
  20. onQueryLoad: function(){
  21. this.lp = MWF.QueryLP;
  22. this.viewPath = this.path+this.options.style+"/view.html";
  23. this.restActions = MWF.Actions.get("x_query_assemble_designer");
  24. this.deleteElements = [];
  25. },
  26. loadControl: function(){
  27. this.control = {};
  28. this.control.canCreate = MWF.AC.isQueryPlatformCreator();
  29. this.control.canManage = !!(MWF.AC.isAdministrator() || MWF.AC.isQueryManager());
  30. },
  31. createApplicationItem: function(appData, where){
  32. var application = new MWF.xApplication.query.QueryExplorer.Query(this, appData, where);
  33. application.load();
  34. },
  35. okCreateApplication: function(e){
  36. var nameNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationName");
  37. var aliasNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationAlias");
  38. var descriptionNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationDescription");
  39. var typeNode = this.applicationCreateFormNode.getElement(".o2_process_AppExp_createApplicationType");
  40. var data = {
  41. "name": nameNode.get("value"),
  42. "alias": aliasNode.get("value"),
  43. "description": descriptionNode.get("value"),
  44. "queryCategory": typeNode.get("value")
  45. };
  46. if (data.name){
  47. this.restActions.saveApplication(data, function(json){
  48. this.applicationCreateMarkNode.destroy();
  49. this.applicationCreateAreaNode.destroy();
  50. this.restActions.getApplication(json.data.id, function(json){
  51. json.data.viewList = [];
  52. json.data.statList = [];
  53. this.createApplicationItem(json.data, "top");
  54. }.bind(this));
  55. this.notice(this.lp.application.createApplicationSuccess, "success");
  56. }.bind(this));
  57. }else{
  58. nameNode.setStyle("border-color", "red");
  59. nameNode.focus();
  60. this.notice(this.lp.application.inputApplicationName, "error");
  61. }
  62. },
  63. importApplication: function(e){
  64. MWF.xDesktop.requireApp("query.QueryExplorer", "Importer", function(){
  65. (new MWF.xApplication.query.QueryExplorer.Importer(this, e)).load();
  66. }.bind(this));
  67. },
  68. deleteSelectedElements: function(e){
  69. var _self = this;
  70. var applicationList = [];
  71. this.deleteElements.each(function(app){
  72. applicationList.push(app.data.name);
  73. });
  74. var confirmStr = this.lp.application.deleteElementsConfirm+" ("+applicationList.join("、")+") ";
  75. var check = "<div style='display: none'><br/><br/><input type=\"checkbox\" id=\"deleteApplicationAllCheckbox\" value=\"yes\">"+this.lp.application.deleteApplicationAllConfirm+"</div>";
  76. confirmStr += check;
  77. this.confirm("infor", e, this.lp.application.deleteElementsTitle, {"html":confirmStr}, 530, 250, function(){
  78. confirmStr = _self.lp.application.deleteElementsConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  79. var checkbox = this.content.getElement("#deleteApplicationAllCheckbox");
  80. var onlyRemoveNotCompleted = true;
  81. if (checkbox.checked){
  82. onlyRemoveNotCompleted = false;
  83. confirmStr = _self.lp.application.deleteElementsAllConfirmAgain+"<br/><br/><font style='color:red; font-size:14px; font-weight: bold'>"+applicationList.join("、")+"</font>";
  84. }
  85. this.close();
  86. _self.confirm("infor", e, _self.lp.application.deleteElementsTitle, {"html":confirmStr}, 500, 200, function(){
  87. var deleted = [];
  88. var doCount = 0;
  89. var readyCount = _self.deleteElements.length;
  90. var errorText = "";
  91. var complete = function(){
  92. if (doCount == readyCount){
  93. if (errorText){
  94. _self.app.notice(errorText, "error");
  95. }
  96. }
  97. };
  98. _self.deleteElements.each(function(application){
  99. application["delete"](onlyRemoveNotCompleted, function(){
  100. deleted.push(application);
  101. doCount++;
  102. if (_self.deleteElements.length==doCount){
  103. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  104. return !deleted.contains(item);
  105. });
  106. _self.checkDeleteApplication();
  107. }
  108. complete();
  109. }, function(error){
  110. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  111. doCount++;
  112. if (_self.deleteElements.length==doCount){
  113. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  114. return !deleted.contains(item);
  115. });
  116. _self.checkDeleteApplication();
  117. }
  118. complete();
  119. });
  120. });
  121. this.close();
  122. }, function(){
  123. this.close();
  124. });
  125. this.close();
  126. }, function(){
  127. this.close();
  128. });
  129. }
  130. });
  131. MWF.xApplication.query.QueryExplorer.Query = new Class({
  132. Extends: MWF.xApplication.process.ApplicationExplorer.Application,
  133. Implements: [Events],
  134. loadElements: function(){
  135. this.loadElementList("viewList", this.viewListNode, this.openView.bind(this), this.lp.noView, this.createNewView.bind(this));
  136. this.loadElementList("statList", this.statListNode, this.openStat.bind(this), this.lp.noStat, this.createNewStat.bind(this));
  137. },
  138. createNewView: function(e){
  139. this.openApplication(e, 0);
  140. },
  141. createNewStat: function(e){
  142. this.openApplication(e, 1);
  143. },
  144. openApplication: function(e, navi){
  145. var appId = "query.QueryManager"+this.data.id;
  146. if (this.app.desktop.apps[appId]){
  147. this.app.desktop.apps[appId].setCurrent();
  148. }else {
  149. this.app.desktop.openApplication(e, "query.QueryManager", {
  150. "application": this.data,
  151. "appId": appId,
  152. "onQueryLoad": function(){
  153. this.status = {"navi": navi || null};
  154. }
  155. });
  156. }
  157. },
  158. openView: function(id, e){
  159. if (id){
  160. var _self = this;
  161. var options = {
  162. "appId": "query.ViewDesigner"+id,
  163. "onQueryLoad": function(){
  164. this.actions = _self.app.actions;
  165. //this.category = _self;
  166. this.options.id = id;
  167. this.application = _self.data;
  168. }
  169. };
  170. this.app.desktop.openApplication(e, "query.ViewDesigner", options);
  171. }
  172. },
  173. openStat: function(id, e){
  174. if (id){
  175. var _self = this;
  176. var options = {
  177. "appId": "query.StatDesigner"+id,
  178. "onQueryLoad": function(){
  179. this.actions = _self.app.actions;
  180. //this.category = _self;
  181. this.options.id = id;
  182. this.application = _self.data;
  183. }
  184. };
  185. this.app.desktop.openApplication(e, "query.StatDesigner", options);
  186. }
  187. },
  188. setIconNode: function(){
  189. if (this.data.icon){
  190. this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.icon+")");
  191. }else{
  192. this.iconNode.setStyle("background-image", "url("+"/x_component_query_QueryExplorer/$Main/default/icon/application.png)")
  193. }
  194. this.iconNode.makeLnk({
  195. "par": this._getLnkPar()
  196. });
  197. },
  198. _getLnkPar: function(){
  199. var lnkIcon = "/x_component_query_QueryExplorer/$Main/default/lnk.png";
  200. if (this.data.icon) lnkIcon = "data:image/png;base64,"+this.data.icon;
  201. var appId = "query.QueryManager"+this.data.id;
  202. return {
  203. "icon": lnkIcon,
  204. "title": this.data.name,
  205. "par": "query.QueryManager#{\"application\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  206. };
  207. },
  208. exportApplication: function(){
  209. MWF.xDesktop.requireApp("query.QueryExplorer", "Exporter", function(){
  210. (new MWF.xApplication.query.QueryExplorer.Exporter(this.app, this.data)).load();
  211. }.bind(this));
  212. },
  213. _deleteElement: function(id, onlyRemoveNotCompleted, success, failure){
  214. this.app.restActions.deleteApplication(id, success, failure);
  215. }
  216. });