Main.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. MWF.xDesktop.requireApp("query.ViewDesigner", "", null, false);
  2. MWF.APPDSTD = MWF.xApplication.query.StatDesigner;
  3. MWF.APPDSTD.options = {
  4. "multitask": true,
  5. "executable": false
  6. };
  7. MWF.xDesktop.requireApp("query.StatDesigner", "Stat", null, false);
  8. MWF.xApplication.query.StatDesigner.Main = new Class({
  9. Extends: MWF.xApplication.query.ViewDesigner.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "query.StatDesigner",
  14. "icon": "icon.png",
  15. "title": MWF.APPDSTD.LP.title,
  16. "appTitle": MWF.APPDSTD.LP.title,
  17. "id": "",
  18. "tooltip": {
  19. "unCategory": MWF.APPDSTD.LP.unCategory
  20. },
  21. "actions": null,
  22. "category": null,
  23. "processData": null
  24. },
  25. onQueryLoad: function(){
  26. this.shortcut = true;
  27. if (this.status){
  28. this.options.application = this.status.applicationId;
  29. this.application = this.status.application;
  30. this.options.id = this.status.id;
  31. }
  32. if (!this.options.id){
  33. this.options.desktopReload = false;
  34. this.options.title = this.options.title + "-"+MWF.APPDSTD.LP.newStat;
  35. }
  36. if (!this.actions) this.actions = MWF.Actions.get("x_query_assemble_designer");
  37. this.lp = MWF.xApplication.query.StatDesigner.LP;
  38. this.addEvent("queryClose", function(e){
  39. if (this.explorer){
  40. this.explorer.reload();
  41. }
  42. }.bind(this));
  43. this.addEvent("postLoadWindowMax", function(e){
  44. this.loadWindowOk = true;
  45. if (this.loadApplicationOk && this.loadWindowOk) this.view.setViewWidth();
  46. }.bind(this));
  47. this.addEvent("postLoadApplication", function(e){
  48. this.loadApplicationOk = true;
  49. if (this.loadApplicationOk && this.loadWindowOk) this.view.setViewWidth();
  50. }.bind(this));
  51. },
  52. loadViewList: function(){
  53. this.actions.listStat(this.application.id, function (json) {
  54. json.data.each(function(view){
  55. this.createListViewItem(view);
  56. }.bind(this));
  57. }.bind(this), null, false);
  58. },
  59. //列示所有视图列表
  60. createListViewItem: function(view, isNew){
  61. var _self = this;
  62. var listViewItem = new Element("div", {"styles": this.css.listViewItem}).inject(this.viewListAreaNode, (isNew) ? "top": "bottom");
  63. var listViewItemIcon = new Element("div", {"styles": this.css.listViewItemIcon}).inject(listViewItem);
  64. var listViewItemText = new Element("div", {"styles": this.css.listViewItemText, "text": (view.name) ? view.name+" ("+view.alias+")" : this.lp.newStat}).inject(listViewItem);
  65. listViewItem.store("view", view);
  66. listViewItem.addEvents({
  67. "dblclick": function(e){_self.loadViewByData(this, e);},
  68. "mouseover": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem_over);},
  69. "mouseout": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem);}
  70. });
  71. },
  72. //打开视图
  73. loadViewByData: function(node, e){
  74. var view = node.retrieve("view");
  75. if (openNew){
  76. var _self = this;
  77. var options = {
  78. "onQueryLoad": function(){
  79. this.actions = _self.actions;
  80. this.category = _self;
  81. this.options.id = view.id;
  82. this.application = _self.application;
  83. this.explorer = _self.explorer;
  84. }
  85. };
  86. this.desktop.openApplication(e, "query.StatDesigner", options);
  87. }
  88. },
  89. //loadView------------------------------------------
  90. loadView: function(){
  91. this.getViewData(this.options.id, function(vdata){
  92. this.setTitle(this.options.appTitle + "-"+vdata.name);
  93. this.taskitem.setText(this.options.appTitle + "-"+vdata.name);
  94. this.options.appTitle = this.options.appTitle + "-"+vdata.name;
  95. this.view = new MWF.xApplication.query.StatDesigner.Stat(this, vdata);
  96. this.view.load();
  97. }.bind(this));
  98. },
  99. loadNewViewData: function(callback){
  100. var url = "/x_component_query_StatDesigner/$Stat/stat.json";
  101. MWF.getJSON(url, {
  102. "onSuccess": function(obj){
  103. this.actions.getUUID(function(id){
  104. obj.id=id;
  105. obj.isNewView = true;
  106. obj.application = this.application.id;
  107. this.createListViewItem(obj, true);
  108. if (callback) callback(obj);
  109. }.bind(this));
  110. }.bind(this),
  111. "onerror": function(text){
  112. this.notice(text, "error");
  113. }.bind(this),
  114. "onRequestFailure": function(xhr){
  115. this.notice(xhr.responseText, "error");
  116. }.bind(this)
  117. });
  118. },
  119. loadViewData: function(id, callback){
  120. this.actions.getStat(id, function(json){
  121. if (json){
  122. var data = json.data;
  123. data.data = JSON.decode(data.data);
  124. if (!this.application){
  125. this.actions.getApplication(data.application, function(json){
  126. this.application = {"name": json.data.name, "id": json.data.id};
  127. if (callback) callback(data);
  128. }.bind(this));
  129. }else{
  130. if (callback) callback(data);
  131. }
  132. }
  133. }.bind(this));
  134. },
  135. saveView: function(){
  136. this.view.save(function(){
  137. var name = this.view.data.name;
  138. this.setTitle(MWF.APPDSTD.LP.title + "-"+name);
  139. this.options.desktopReload = true;
  140. this.options.id = this.view.data.id;
  141. }.bind(this));
  142. },
  143. saveViewAs: function(){
  144. this.view.saveAs();
  145. },
  146. dictionaryExplode: function(){
  147. this.view.explode();
  148. },
  149. dictionaryImplode: function(){
  150. this.view.implode();
  151. }
  152. //recordStatus: function(){
  153. // return {"id": this.options.id};
  154. //},
  155. });
  156. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  157. MWF.xApplication.query.StatDesigner.Stat.NewNameForm = new Class({
  158. Extends: MPopupForm,
  159. Implements: [Options, Events],
  160. options: {
  161. "style": "design",
  162. "width": 700,
  163. //"height": 300,
  164. "height": "300",
  165. "hasTop": true,
  166. "hasIcon": false,
  167. "draggable": true,
  168. "title" : MWF.xApplication.query.StatDesigner.LP.copyStat
  169. },
  170. _createTableContent: function () {
  171. var html = "<table width='80%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin: 20px auto 0px auto; '>" +
  172. "<tr><td styles='formTableTitle' lable='selectQuery' width='25%'></td>" +
  173. " <td styles='formTableValue' item='selectQuery' colspan='3' width='75%'></td></tr>" +
  174. "<tr><td styles='formTableTitle' lable='view'></td>" +
  175. " <td styles='formTableValue' item='view' colspan='3'></td></tr>" +
  176. "<tr><td styles='formTableTitle' lable='name'></td>" +
  177. " <td styles='formTableValue' item='name' colspan='3'></td></tr>" +
  178. "</table>";
  179. this.formTableArea.set("html", html);
  180. MWF.xDesktop.requireApp("Template", "MForm", function () {
  181. this.form = new MForm(this.formTableArea, this.data || {}, {
  182. isEdited: true,
  183. style: "cms",
  184. hasColon: true,
  185. itemTemplate: {
  186. selectQuery : { text: MWF.xApplication.query.StatDesigner.LP.application , type : "org", orgType : "Query", defaultValue : this.data.queryName,
  187. orgWidgetOptions : {"canRemove" : false },
  188. event : {
  189. change : function(){ this.form.getItem("view").resetItemOptions( this.getViewIdList(), this.getViewNameList() ) }.bind(this)
  190. }
  191. },
  192. view : {
  193. text: MWF.xApplication.query.StatDesigner.LP.view , type : "select",
  194. selectValue : function(){ return this.getViewIdList(); }.bind(this),
  195. selectText : function(){ return this.getViewNameList(); }.bind(this)
  196. },
  197. name: {text: MWF.xApplication.query.StatDesigner.LP.name, notEmpty: true}
  198. }
  199. }, this.app);
  200. this.form.load();
  201. }.bind(this),null, true)
  202. },
  203. getViewIdList : function(){
  204. return this.getViews().idList;
  205. },
  206. getViewNameList : function(){
  207. return this.getViews().nameList;
  208. },
  209. getViews : function(){
  210. var id;
  211. var selectQuery = this.form.getItem("selectQuery").orgObject;
  212. if( selectQuery && selectQuery.length > 0 ){
  213. var queryData = selectQuery[0].data;
  214. id = queryData.id;
  215. }else{
  216. id = this.data.query;
  217. //data.query 和 data.queryName 还是传进来的值
  218. }
  219. var idList = [];
  220. var nameList = [];
  221. MWF.Actions.get("x_query_assemble_designer").listView( id, function(json){
  222. json.data.each( function(d){
  223. idList.push(d.id );
  224. nameList.push(d.name );
  225. })
  226. }.bind(this), null, false);
  227. return {
  228. idList : idList,
  229. nameList : nameList
  230. }
  231. },
  232. ok: function(){
  233. var data = this.form.getResult(true,null,true,false,true);
  234. if( data ){
  235. var selectQuery = this.form.getItem("selectQuery").orgObject;
  236. if( selectQuery && selectQuery.length > 0 ){
  237. var queryData = selectQuery[0].data;
  238. data.query = queryData.id;
  239. data.queryName = queryData.name;
  240. }else{
  241. //data.query 和 data.queryName 还是传进来的值
  242. }
  243. this.fireEvent("save", [data , function(){
  244. this.close();
  245. }.bind(this)])
  246. }
  247. }
  248. });