Main.js 11 KB

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