StatExplorer.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.Application = MWF.xApplication.process.Application || {};
  3. MWF.require("MWF.widget.Mask", null, false);
  4. MWF.xDesktop.requireApp("process.Application", "ViewExplorer", null, false);
  5. MWF.xApplication.process.Application.StatExplorer = new Class({
  6. Extends: MWF.xApplication.process.Application.ViewExplorer,
  7. Implements: [Options, Events],
  8. initialize: function(node, actions, options){
  9. this.setOptions(options);
  10. this.setTooltip();
  11. this.path = "/x_component_process_Application/$WorkExplorer/";
  12. this.cssPath = "/x_component_process_Application/$WorkExplorer/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.actions = actions;
  15. this.node = $(node);
  16. this.items=[];
  17. },
  18. loadContentNode: function(){
  19. this.filterNode.setStyles(this.css.statListNode);
  20. this.elementContentNode = new Element("div", {
  21. "styles": this.css.elementContentNode
  22. }).inject(this.node);
  23. this.elementContentListNode = new Element("div", {
  24. "styles": this.css.elementContentListNode
  25. }).inject(this.elementContentNode);
  26. this.createWorkListHead();
  27. this.setContentSize();
  28. this.setContentSizeFun = this.setContentSize.bind(this);
  29. this.app.addEvent("resize", this.setContentSizeFun);
  30. },
  31. setContentSize: function(){
  32. //var toolbarSize = this.toolbarNode.getSize();
  33. var nodeSize = this.node.getSize();
  34. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  35. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  36. var filterSize = this.filterNode.getSize();
  37. var height = nodeSize.y-pt-pb-filterSize.y;
  38. this.elementContentNode.setStyle("height", ""+height+"px");
  39. this.pageCount = (height/40).toInt()+5;
  40. },
  41. showMask: function(){
  42. if (!this.mask){
  43. this.mask = new MWF.widget.Mask({"style": "desktop"});
  44. this.mask.loadNode(this.node);
  45. }
  46. },
  47. hideMask: function(){
  48. if (this.mask){
  49. this.mask.hide();
  50. this.mask = null;
  51. }
  52. },
  53. loadViewList: function(){
  54. this.actions.listStat(this.app.options.id, function(json){
  55. if (json.data.length){
  56. json.data.each(function(process){
  57. this.loadViewListNode(process);
  58. }.bind(this));
  59. this.hideMask();
  60. if (this.currentView){
  61. this.currentView.click();
  62. }else{
  63. this.items[0].click();
  64. }
  65. }else{
  66. this.filterNode.destroy();
  67. var noElementNode = new Element("div", {
  68. "styles": this.css.noElementNode,
  69. "text": this.app.lp.noStat
  70. }).inject(this.elementContentListNode);
  71. this.hideMask();
  72. }
  73. }.bind(this));
  74. },
  75. _getLnkPar: function(view){
  76. return {
  77. "icon": this.path+this.options.style+"/statIcon/lnk.png",
  78. "title": view.name,
  79. "par": "process.Application#{\"navi\": 3, \"id\": \""+this.app.options.id+"\", \"viewName\": \""+view.name+"\", \"hideMenu\": true}"
  80. };
  81. },
  82. loadViewData: function(node){
  83. this.showMask();
  84. this.items.each(function(item){
  85. item.setStyles(this.css.filterViewNode);
  86. }.bind(this));
  87. node.setStyles(this.css.filterViewNode_current);
  88. this.elementContentListNode.empty();
  89. if (this.stat){
  90. this.stat.destroy();
  91. this.stat = null;
  92. }
  93. var view = node.retrieve("view");
  94. this.actions.loadStat(view.id, this.app.options.id, null, function(json){
  95. if (json.data.calculate.isGroup){
  96. this.stat = new MWF.xApplication.process.Application.StatExplorer.GroupStat(this, json.data);
  97. }else{
  98. this.stat = new MWF.xApplication.process.Application.StatExplorer.Stat(this, json.data);
  99. }
  100. //this.showViewData(json.data);
  101. this.hideMask();
  102. }.bind(this));
  103. },
  104. destroy: function(){
  105. if (this.stat){
  106. this.stat.destroy();
  107. }
  108. this.node.destroy();
  109. MWF.release(this);
  110. }
  111. });
  112. MWF.xApplication.process.Application.StatExplorer.Stat = new Class({
  113. initialize: function(explorer, data){
  114. this.explorer = explorer;
  115. this.data = data;
  116. this.css = this.explorer.css;
  117. this.lp = this.explorer.app.lp;
  118. this.node = this.explorer.elementContentListNode;
  119. this.load();
  120. },
  121. load: function(){
  122. this.chartAreaNode = new Element("div", {"styles": this.css.statChartAreaNode}).inject(this.node);
  123. this.tableAreaNode = new Element("div", {"styles": this.css.statTableAreaNode}).inject(this.node);
  124. this.loadData();
  125. this.createTable();
  126. this.createChart();
  127. },
  128. loadData: function(){
  129. var entries = {};
  130. this.data.selectEntryList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  131. },
  132. createChart: function(){
  133. //this.chartFlagNode = new Element("div", {"styles": this.css.statChartFlagAreaNode}).inject(this.chartAreaNode);
  134. this.chartNode = new Element("div", {"styles": this.css.statChartNode}).inject(this.chartAreaNode);
  135. this.loadChart();
  136. this.resizeChartFun = this.resizeChart.bind(this);
  137. this.explorer.app.addEvent("resizeCompleted", this.resizeChartFun);
  138. this.explorer.app.addEvent("postMaxSize", this.resizeChartFun);
  139. this.explorer.app.addEvent("postRestoreSize", this.resizeChartFun);
  140. },
  141. resizeChart: function(){
  142. if (this.bar) this.bar.destroy();
  143. this.bar = null;
  144. this.chartNode.empty();
  145. this.loadChart();
  146. },
  147. loadChart: function(){
  148. MWF.require("MWF.widget.chart.Bar", function(){
  149. this.bar = new MWF.widget.chart.Bar(this.chartNode, this.data.calculateGrid, "displayName", {"delay": 0, "style": "monthly"});
  150. this.bar.addBar("value");
  151. //bar.addBar("value");
  152. this.bar.addEvents({
  153. "mouseover": function(rects, texts, d, i){
  154. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  155. var rect = rects.filter(function(data, idx){return (idx==i);});
  156. var color = rect.attr("fill");
  157. rect.node().store("color", color);
  158. rect.attr("fill", "brown");
  159. }.bind(this),
  160. "mouseout": function(rects, texts, d, i){
  161. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  162. var rect = rects.filter(function(data, idx){return (idx==i);});
  163. var color = rect.node().retrieve("color");
  164. rect.attr("fill", color);
  165. }.bind(this)
  166. });
  167. this.bar.load();
  168. }.bind(this));
  169. },
  170. createTable: function(){
  171. this.createTableHead();
  172. this.createTableData();
  173. },
  174. createTableHead: function(){
  175. this.table = new Element("table", {
  176. "styles": this.css.statTableNode,
  177. "width": "100%",
  178. "border": "0",
  179. "cellPadding": "0",
  180. "cellSpacing": "0"
  181. }).inject(this.node);
  182. this.headTr = new Element("tr").inject(this.table);
  183. this.data.calculate.calculateEntryList.each(function(title){
  184. var th = new Element("th", {
  185. "styles": this.css.statHeadTh,
  186. "text": title.displayName
  187. }).inject(this.headTr);
  188. }.bind(this));
  189. },
  190. createTableData: function(){
  191. if (this.data.calculateGrid.length){
  192. var tr = new Element("tr").inject(this.table);
  193. this.data.calculateGrid.each(function(d){
  194. var td = new Element("td", {"styles": this.css.statContentTdNode}).inject(tr);
  195. td.set("text", d.value);
  196. }.bind(this));
  197. }
  198. },
  199. destroy: function(){
  200. if (this.bar) this.bar.destroy();
  201. if (this.resizeChartFun){
  202. this.explorer.app.removeEvent("resizeCompleted", this.resizeChartFun);
  203. this.explorer.app.removeEvent("postMaxSize", this.resizeChartFun);
  204. this.explorer.app.removeEvent("postRestoreSize", this.resizeChartFun);
  205. }
  206. MWF.release(this);
  207. }
  208. });
  209. MWF.xApplication.process.Application.StatExplorer.GroupStat = new Class({
  210. Extends: MWF.xApplication.process.Application.StatExplorer.Stat,
  211. loadData: function(){
  212. var entries = {};
  213. var groupColumn = null;
  214. this.data.selectEntryList.each(function(entry){
  215. entries[entry.column] = entry;
  216. if (entry.column === this.data.groupEntry.column){
  217. groupColumn = entry;
  218. }
  219. }.bind(this));
  220. this.data.calculateGrid.each(function(dd){
  221. if (groupColumn){
  222. dd.group = (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": dd.group, "data": this.data}) : dd.group;
  223. }
  224. dd.list.each(function(c){
  225. c.value = (entries[c.column].code) ? MWF.Macro.exec(entries[c.column].code, {"value": c.value, "data": this.data}) : c.value
  226. }.bind(this));
  227. }.bind(this));
  228. },
  229. createChart: function(){
  230. this.chartFlagNode = new Element("div", {"styles": this.css.statChartFlagAreaNode}).inject(this.chartAreaNode);
  231. this.chartNode = new Element("div", {"styles": this.css.statChartNode}).inject(this.chartAreaNode);
  232. this.loadChart();
  233. this.resizeChartFun = this.resizeChart.bind(this);
  234. this.explorer.app.addEvent("resizeCompleted", this.resizeChartFun);
  235. this.explorer.app.addEvent("postMaxSize", this.resizeChartFun);
  236. this.explorer.app.addEvent("postRestoreSize", this.resizeChartFun);
  237. },
  238. resizeChart: function(){
  239. if (this.bar) this.bar.destroy();
  240. this.bar = null;
  241. this.chartFlagNode.empty();
  242. this.chartNode.empty();
  243. this.loadChart();
  244. },
  245. loadChart: function(){
  246. if (!this.selectedData) this.selectedData = this.data.calculateGrid;
  247. if (!this.selectedData.length) this.selectedData = this.data.calculateGrid;
  248. MWF.require("MWF.widget.chart.Bar", function(){
  249. this.flag = [];
  250. this.bar = new MWF.widget.chart.Bar(this.chartNode, this.selectedData, "group", {"delay": 0, "style": "monthly"});
  251. if (this.selectedData.length){
  252. this.selectedData[0].list.each(function(d, i){
  253. this.flag.push({"name":d.displayName, "color": this.bar.colors[i]});
  254. this.bar.addBar(function(v){return v.list[i].value});
  255. }.bind(this));
  256. }
  257. this.bar.addEvents({
  258. "mouseover": function(rects, texts, d, i){
  259. texts.filter(function(data, idx){return (idx==i);}).attr("display", "block");
  260. var rect = rects.filter(function(data, idx){return (idx==i);});
  261. var color = rect.attr("fill");
  262. rect.node().store("color", color);
  263. rect.attr("fill", "brown");
  264. }.bind(this),
  265. "mouseout": function(rects, texts, d, i){
  266. texts.filter(function(data, idx){return (idx==i);}).attr("display", "none");
  267. var rect = rects.filter(function(data, idx){return (idx==i);});
  268. var color = rect.node().retrieve("color");
  269. rect.attr("fill", color);
  270. }.bind(this)
  271. });
  272. this.bar.load();
  273. this.loadFlags();
  274. }.bind(this));
  275. },
  276. loadFlags: function(){
  277. this.flag.each(function(f, i){
  278. this.loadFlag(f, i);
  279. }.bind(this));
  280. },
  281. loadFlag: function(f, i){
  282. var flagNode = new Element("div", {"styles": this.css.ststChartFlagNode}).inject(this.chartFlagNode);
  283. var flagColorNode = new Element("div", {"styles": this.css.ststChartFlagColorNode}).inject(flagNode);
  284. flagColorNode.setStyle("background-color", f.color);
  285. var flagNameNode = new Element("div", {"styles": this.css.ststChartFlagNameNode}).inject(flagNode);
  286. flagNameNode.set("text", f.name);
  287. flagNameNode.set("title", f.name);
  288. flagNode.store("idx", i);
  289. flagNode.store("barColor", f.color);
  290. var _self = this;
  291. flagNode.addEvents({
  292. "mouseover": function(){
  293. this.getFirst().setStyles(_self.css.ststChartFlagColorNode_over);
  294. var idx = this.retrieve("idx");
  295. _self.highlightBar(idx);
  296. },
  297. "mouseout": function(){
  298. this.getFirst().setStyles(_self.css.ststChartFlagColorNode);
  299. var idx = this.retrieve("idx");
  300. var barColor = this.retrieve("barColor");
  301. _self.unHighlightBar(idx, barColor);
  302. }
  303. });
  304. },
  305. createDefs: function(node, data){
  306. var svgNode = node.append(data.tag);
  307. Object.each(data.attrs, function(v,k){svgNode.attr(k,v);});
  308. if (data.subs) {
  309. data.subs.each(function(v){
  310. this.createDefs(svgNode, v);
  311. }.bind(this));
  312. }
  313. },
  314. createHighlightDefs: function(id){
  315. //this.defssvg = this.bar.createDefs;
  316. var node = this.bar.svg.append("defs");
  317. var data = this.bar.css["rect_over_defs"];
  318. this.createDefs(node, data);
  319. node.select(function(){ return this.getFirst(); }).attr("id", id);
  320. node.attr("id", "defs_"+id);
  321. },
  322. unHighlightBar: function(i, barColor){
  323. var id = "rect_over_defs"+i;
  324. var def = d3.select("#defs_"+id);
  325. def.remove();
  326. var rects = this.bar.rectCluster[i];
  327. rects.attr(this.bar.css["rect_over_defs"].urlAttr, null);
  328. var texts = this.bar.textCluster[i];
  329. texts.attr("display", "none");
  330. texts.attr("font-weight", "normal");
  331. },
  332. highlightBar: function(i){
  333. this.bar.rectCluster[i].remove();
  334. var rects = this.recreateBars(i);
  335. var id = "rect_over_defs"+i;
  336. this.createHighlightDefs(id);
  337. rects.attr(this.bar.css["rect_over_defs"].urlAttr, "url(#"+id+")");
  338. var texts = this.bar.textCluster[i];
  339. texts.attr("display", "block");
  340. texts.attr("font-weight", "bold");
  341. },
  342. recreateBars: function(i){
  343. var data = this.data.calculateGrid.map(function(d, idx) {
  344. return {"name": d["group"], "data": d.list[i].value};
  345. }.bind(this));
  346. this.bar.rectClass = Math.round(Math.random()*100);
  347. var barWidth = this.bar.xScale.bandwidth()/this.bar.barsData.length;
  348. var rects = this.bar.group.selectAll(".MWFBar_"+this.bar.rectClass+"_"+i)
  349. .data(data)
  350. .enter().append("rect")
  351. .attr("class", ".MWFBar_"+this.bar.rectClass+"_"+i)
  352. .attr("x", function(d) { return this.xScale(d.name)+(i*barWidth); }.bind(this.bar))
  353. .attr("width", barWidth)
  354. .attr("height", function(d) { return this.size.y - this.yScale(d.data); }.bind(this.bar))
  355. .attr("y", function(d) { return this.yScale(d.data); }.bind(this.bar))
  356. .attr("fill", this.bar.colors[i]);
  357. this.bar.rectCluster[i] = rects;
  358. this.bar.setEvents();
  359. return rects;
  360. },
  361. createTableHead: function(){
  362. this.selectedCols = [];
  363. this.selectedRows = [];
  364. this.table = new Element("table", {
  365. "styles": this.css.statTableNode,
  366. "width": "100%",
  367. "border": "0",
  368. "cellPadding": "0",
  369. "cellSpacing": "0"
  370. }).inject(this.node);
  371. _self = this;
  372. this.headTr = this.table.insertRow();
  373. this.selectAllTd = this.headTr.insertCell().setStyles(this.css.statAllSelectTd).set("title", this.explorer.app.lp.selecteAll);
  374. this.selectAllTd.addEvent("click", function(){
  375. _self.selectAll(this);
  376. });
  377. this.selectEntryTd = this.headTr.insertCell().setStyles(this.css.statAllColSelectTd).set("title", this.explorer.app.lp.selecteAllCol);
  378. this.selectEntryTd.addEvent("click", function(){
  379. _self.selectAllCol(this);
  380. });
  381. this.data.calculate.calculateEntryList.each(function(title){
  382. selectTd = this.headTr.insertCell().setStyles(this.css.statColSelectTd);
  383. selectTd.addEvent("click", function(){
  384. _self.selectCol(this);
  385. });
  386. }.bind(this));
  387. this.titleTr = this.table.insertRow();
  388. this.selectGroupTd = this.titleTr.insertCell().setStyles(this.css.statAllRowSelectTd).set("title", this.explorer.app.lp.selecteAllRow);
  389. this.categoryTitleTd = new Element("th", {
  390. "styles": this.css.statHeadTh,
  391. "text": this.data.calculate.title || this.explorer.app.lp.category
  392. }).inject(this.titleTr);
  393. this.categoryTitleTd.setStyle("width", "160px");
  394. this.data.calculate.calculateEntryList.each(function(title){
  395. var th = new Element("th", {
  396. "styles": this.css.statHeadTh,
  397. "text": title.displayName
  398. }).inject(this.titleTr);
  399. }.bind(this));
  400. },
  401. createTableData: function(){
  402. if (this.data.calculateGrid.length){
  403. var _self = this;
  404. var groupColumn = null;
  405. for (var c = 0; c<this.data.selectEntryList.length; c++){
  406. if (this.data.selectEntryList[c].column === this.data.groupEntry.column){
  407. groupColumn = this.data.selectEntryList[c];
  408. break;
  409. }
  410. }
  411. this.data.calculateGrid.each(function(d){
  412. var tr = this.table.insertRow();
  413. var selectTd = tr.insertCell().setStyles(this.css.statRowSelectTd);
  414. selectTd.addEvent("click", function(){
  415. _self.selectRow(this);
  416. });
  417. var text = d.group;
  418. if (groupColumn){
  419. text = (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": d.group, "data": this.data}) : d.group;
  420. }
  421. var categoryTh = new Element("th", {"styles": this.css.statHeadTh, "text": text}).inject(tr);
  422. d.list.each(function(l){
  423. var td = new Element("td", {"styles": this.css.statContentTdNode}).inject(tr);
  424. td.set("text", l.value);
  425. this.setDragEvent(td);
  426. }.bind(this));
  427. }.bind(this));
  428. }
  429. },
  430. setDragEvent: function(td){
  431. new Drag(td, {
  432. "onStart": function(dragged, e){
  433. this.cellDragStart(dragged, e);
  434. }.bind(this),
  435. "onDrag": function(dragged, e){
  436. this.cellDrag(dragged, e);
  437. }.bind(this),
  438. "onComplete": function(dragged, e){
  439. this.completeDrag(dragged, e);
  440. }.bind(this)
  441. });
  442. var _self = this;
  443. td.addEvent("click", function(){
  444. var cellIndex = td.cellIndex-2;
  445. var rowIndex = td.getParent("tr").rowIndex-2;
  446. if (_self.checkIsSelected(cellIndex, rowIndex)){
  447. }else{
  448. if (_self.selectedCols.length || _self.selectedRows.length){
  449. _self.selectAll();
  450. }
  451. }
  452. });
  453. },
  454. cellDragStart: function(td, e){
  455. //if (_self.selectedCols.length || _self.selectedRows.length){
  456. // _self.selectAll();
  457. //}
  458. var p = td.getPosition();
  459. var size = td.getSize();
  460. td.store("start", {"x": p.x, "y": p.y});
  461. td.store("start2", {"x": p.x+size.x, "y": p.y+size.y});
  462. },
  463. getSelectedCells: function(td, start, e){
  464. var ox = e.page.x-start.x;
  465. var oy = e.page.y-start.y;
  466. var tdSize = td.getSize();
  467. var cols = (ox/tdSize.x).toInt();
  468. var rows = (oy/tdSize.y).toInt();
  469. return {"cols": cols, "rows": rows};
  470. },
  471. cellDrag: function(td, e){
  472. this.selectedRows = [];
  473. this.selectedCols = [];
  474. this.selectedData = [];
  475. var start = td.retrieve("start");
  476. var start2 = td.retrieve("start2");
  477. var c1 = this.getSelectedCells(td, start, e);
  478. var c2 = this.getSelectedCells(td, start2, e);
  479. var cols = (Math.abs(c1.cols)>Math.abs(c2.cols)) ? c1.cols : c2.cols;
  480. var rows = (Math.abs(c1.rows)>Math.abs(c2.rows)) ? c1.rows : c2.rows;
  481. var cellIndex = td.cellIndex-2;
  482. var rowIndex = td.getParent("tr").rowIndex-2;
  483. if (!cellIndex || cellIndex<0) cellIndex = 0;
  484. if (!rowIndex || rowIndex<0) rowIndex = 0;
  485. var toCellIndex = cellIndex+cols;
  486. var toRowIndex = rowIndex+rows;
  487. if (toRowIndex>rowIndex){
  488. for (var i=rowIndex; i<=toRowIndex; i++) this.selectedRows.push(i);
  489. }else{
  490. for (var i=toRowIndex; i<=rowIndex; i++) this.selectedRows.push(i);
  491. }
  492. if (toCellIndex>cellIndex){
  493. for (var i=cellIndex; i<=toCellIndex; i++) this.selectedCols.push(i);
  494. }else{
  495. for (var i=toCellIndex; i<=cellIndex; i++) this.selectedCols.push(i);
  496. }
  497. this.checkSelectedCells();
  498. },
  499. completeDrag: function(td, e){
  500. var trs = this.table.getElements("tr");
  501. var tds = trs[0].getElements("td");
  502. this.selectedCols.each(function(i){
  503. tds[i+2].setStyles(this.css.statTableSelectedTd);
  504. }.bind(this));
  505. this.selectedRows.each(function(i){
  506. trs[i+2].getElement("td").setStyles(this.css.statTableSelectedTd);
  507. }.bind(this));
  508. this.reloadChart();
  509. },
  510. selectCol: function(td){
  511. var i = td.cellIndex;
  512. var dataIndex = i-2;
  513. if (this.selectedCols.indexOf(dataIndex)!=-1){
  514. td.setStyles(this.css.statTableSelectTd);
  515. this.selectedCols.erase(dataIndex);
  516. }else{
  517. td.setStyles(this.css.statTableSelectedTd);
  518. this.selectedCols.push(dataIndex);
  519. }
  520. this.checkSelectedCells();
  521. this.reloadChart();
  522. },
  523. selectRow: function(td){
  524. var tr = td.getParent("tr");
  525. var i = tr.rowIndex;
  526. var dataIndex = i-2;
  527. if (this.selectedRows.indexOf(dataIndex)!=-1){
  528. td.setStyles(this.css.statTableSelectTd);
  529. this.selectedRows.erase(dataIndex);
  530. }else{
  531. td.setStyles(this.css.statTableSelectedTd);
  532. this.selectedRows.push(dataIndex);
  533. }
  534. this.checkSelectedCells();
  535. this.reloadChart();
  536. },
  537. selectAllCol: function(){
  538. if (this.selectedCols.length){
  539. this.selectedCols = [];
  540. var trs = this.table.getElements("tr");
  541. var tds = trs[0].getElements("td");
  542. for (var i=2; i<tds.length; i++){
  543. tds[i].setStyles(this.css.statTableSelectTd);
  544. }
  545. //for (var n=2; n<trs.length; n++){
  546. // trs[n].getElement("td").setStyles(this.css.statTableSelectTd);
  547. //}
  548. }else{
  549. var seltrs = this.table.getElements("tr");
  550. var seltds = seltrs[0].getElements("td");
  551. for (var n=2; n<seltds.length; n++){
  552. this.selectedCols.push(n-2);
  553. seltds[n].setStyles(this.css.statTableSelectedTd);
  554. }
  555. }
  556. this.checkSelectedCells();
  557. this.reloadChart();
  558. },
  559. selectAll: function(){
  560. if (this.selectedRows.length || this.selectedCols.length){
  561. this.selectedRows = [];
  562. this.selectedCols = [];
  563. var trs = this.table.getElements("tr");
  564. var tds = trs[0].getElements("td");
  565. for (var i=2; i<tds.length; i++){
  566. tds[i].setStyles(this.css.statTableSelectTd);
  567. }
  568. for (var n=2; n<trs.length; n++){
  569. trs[n].getElement("td").setStyles(this.css.statTableSelectTd);
  570. }
  571. }else{
  572. var seltrs = this.table.getElements("tr");
  573. var seltds = seltrs[0].getElements("td");
  574. for (var seli=2; seli<seltds.length; seli++){
  575. this.selectedCols.push(seli-2);
  576. seltds[seli].setStyles(this.css.statTableSelectedTd);
  577. }
  578. for (var seln=2; seln<seltrs.length; seln++){
  579. this.selectedRows.push(seln-2);
  580. seltrs[seln].getElement("td").setStyles(this.css.statTableSelectedTd);
  581. }
  582. }
  583. this.checkSelectedCells();
  584. this.reloadChart();
  585. },
  586. checkIsSelected: function(ci, ri){
  587. if (!this.selectedCols.length && !this.selectedRows.length) return false;
  588. var colSelect = (!this.selectedCols.length) || this.selectedCols.indexOf(ci)!=-1;
  589. var rowSelect = (!this.selectedRows.length) || this.selectedRows.indexOf(ri)!=-1;
  590. return (colSelect && rowSelect);
  591. },
  592. checkSelectedCells: function(){
  593. this.selectedData = [];
  594. var rows = this.table.getElements("tr");
  595. for (var rowIdx = 2; rowIdx<rows.length; rowIdx++){
  596. var o = {
  597. "group": this.data.calculateGrid[rowIdx-2].group,
  598. "list": []
  599. };
  600. var cols = rows[rowIdx].getElements("td");
  601. for (var colIdx = 1; colIdx<cols.length; colIdx++){
  602. if (this.checkIsSelected(colIdx-1, rowIdx-2)){
  603. cols[colIdx].setStyles(this.css.statContentTdNode_selected);
  604. o.list.push({
  605. "column": this.data.calculateGrid[rowIdx-2].list[colIdx-1].column,
  606. "displayName": this.data.calculateGrid[rowIdx-2].list[colIdx-1].displayName,
  607. "value": this.data.calculateGrid[rowIdx-2].list[colIdx-1].value
  608. });
  609. }else{
  610. cols[colIdx].setStyles(this.css.statContentTdNode);
  611. }
  612. }
  613. if (o.list.length) this.selectedData.push(o);
  614. }
  615. },
  616. reloadChart: function(){
  617. if (this.bar) this.bar.destroy();
  618. this.bar = null;
  619. this.chartFlagNode.empty();
  620. this.chartNode.empty();
  621. this.loadChart();
  622. }
  623. });
  624. MWF.xApplication.process.Application.StatExplorer.GroupStat.Select = new Class({
  625. //Extends: MWF.xApplication.process.Application.StatExplorer.Stat
  626. });