Main.js 11 KB

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