Stat.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.StatDesigner = MWF.xApplication.query.StatDesigner || {};
  4. MWF.APPDSTD = MWF.xApplication.query.StatDesigner;
  5. MWF.xDesktop.requireApp("query.StatDesigner", "lp."+MWF.language, null, false);
  6. MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  7. MWF.xDesktop.requireApp("query.StatDesigner", "Property", null, false);
  8. MWF.xApplication.query.StatDesigner.Stat = new Class({
  9. Extends: MWF.xApplication.query.ViewDesigner.View,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "isView": false,
  14. "showTab": true,
  15. "propertyPath": "/x_component_query_StatDesigner/$Stat/stat.html"
  16. },
  17. initialize: function(designer, data, options){
  18. this.setOptions(options);
  19. this.path = "/x_component_query_StatDesigner/$Stat/";
  20. this.cssPath = "/x_component_query_StatDesigner/$Stat/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.designer = designer;
  23. this.data = data;
  24. if (!this.data.data) this.data.data = {};
  25. this.parseData();
  26. this.node = this.designer.designNode;
  27. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  28. this.propertyListNode = this.designer.propertyDomArea;
  29. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  30. if(this.designer.application) this.data.application = this.designer.application.id;
  31. this.isNewView = (this.data.id) ? false : true;
  32. this.items = [];
  33. this.view = this;
  34. this.queryView = null;
  35. this.autoSave();
  36. this.designer.addEvent("queryClose", function(){
  37. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  38. }.bind(this));
  39. },
  40. changeViewSelected: function(){
  41. if (this.json.view){
  42. if (!this.queryView){
  43. this.designer.actions.getView(this.json.view, function(view){
  44. this.queryView = JSON.decode(view.data.data);
  45. this.items.each(function(item){
  46. item.changeViewSelected(this.queryView);
  47. }.bind(this));
  48. this.checkIsGroupRadioDisplay();
  49. }.bind(this));
  50. }else{
  51. this.items.each(function(item){
  52. item.changeViewSelected(this.queryView);
  53. }.bind(this));
  54. this.checkIsGroupRadioDisplay();
  55. }
  56. }else{
  57. //item.changeViewSelected();
  58. }
  59. },
  60. checkIsGroupRadioDisplay: function(){
  61. debugger;
  62. if (this.property){
  63. var groupNode = this.property.propertyContent.getElement(".MWFIsGroupArea");
  64. if (groupNode){
  65. if (this.queryView.group.column){
  66. groupNode.setStyle("display", "block");
  67. }else{
  68. this.json.data.calculate.isGroup = false;
  69. var radios = groupNode.getElements("input");
  70. for (var i=0; i<radios.length; i++){
  71. if (radios[i].value=="false"){
  72. radios[i].set("checked", true);
  73. break;
  74. }
  75. }
  76. this.hideGroupTitle();
  77. groupNode.setStyle("display", "none");
  78. }
  79. }
  80. }
  81. },
  82. checkIsGroupRadio: function(){
  83. if (!this.queryView){
  84. this.designer.actions.getView(this.json.view, function(view){
  85. this.queryView = JSON.decode(view.data.data);
  86. this.checkIsGroupRadioDisplay();
  87. }.bind(this));
  88. }else{
  89. this.checkIsGroupRadioDisplay();
  90. }
  91. },
  92. showProperty: function(){
  93. debugger;
  94. if (!this.property){
  95. this.property = new MWF.xApplication.query.StatDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  96. "path": this.options.propertyPath,
  97. "onPostLoad": function(){
  98. this.property.show();
  99. }.bind(this)
  100. });
  101. this.property.load();
  102. }else{
  103. this.property.show();
  104. }
  105. },
  106. //getDataTr: function(ri){
  107. // var tr = null;
  108. // var trs = this.viewContentTableNode.getElements("tr");
  109. // if (trs.length) if (trs[ri]) tr = trs[ri];
  110. // return tr;
  111. //},
  112. //getDataTd: function(tr, ci){
  113. // var td = null;
  114. // var tds = tr.getElements("td");
  115. // if (tds.length) if (tds[ci]) td = tds[ci];
  116. // return td;
  117. //},
  118. //getDataLastColumnCell: function(ri, ci){
  119. // var trs = this.viewContentTableNode.getElements("tr");
  120. // if (trs.length) if (trs[ri]) tr = trs[ri];
  121. // var td = null;
  122. // var tds = tr.getElements("td");
  123. // if (tds.length) if (tds[ci]) td = tds[ci];
  124. // return td;
  125. //},
  126. loadViewData: function(){
  127. debugger;
  128. if (this.data.id){
  129. this.saveSilence(function(){
  130. this.viewContentBodyNode.empty();
  131. this.viewContentTableNode = new Element("table", {
  132. "styles": this.css.viewContentTableNode,
  133. "border": "0px",
  134. "cellPadding": "0",
  135. "cellSpacing": "0"
  136. }).inject(this.viewContentBodyNode);
  137. this.designer.actions.loadStat(this.data.id, null, function(json){
  138. var entries = {};
  139. json.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  140. if (this.json.data.calculate.isGroup){
  141. if (json.data.calculateGrid.length){
  142. json.data.calculateGrid.each(function(d){
  143. var groupColumn = null;
  144. for (var c = 0; c<json.data.selectList.length; c++){
  145. if (json.data.selectList[c].column === json.data.group.column){
  146. groupColumn = json.data.selectList[c];
  147. break;
  148. }
  149. }
  150. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  151. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  152. if (groupColumn){
  153. td.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": d.group, "data": json.data}) : d.group);
  154. }else{
  155. td.set("text", d.group);
  156. }
  157. //td.set("text", d.group);
  158. td.setStyle("font-weight", "bold");
  159. d.list.each(function(c){
  160. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  161. td.set("text", (entries[c.column].code) ? MWF.Macro.exec(entries[c.column].code, {"value": c.value, "data": json.data}) : c.value);
  162. }.bind(this));
  163. }.bind(this));
  164. }
  165. if (json.data.calculateAmountGrid){
  166. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  167. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  168. td.set("text", this.designer.lp.amount);
  169. td.setStyles({"font-weight": "bold", "color": "#0000FF"});
  170. json.data.calculateAmountGrid.each(function(c){
  171. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  172. td.set("text", c.value);
  173. td.setStyles({"font-weight": "bold", "color": "#0000FF"});
  174. }.bind(this));
  175. }
  176. }else{
  177. if (json.data.calculateGrid.length){
  178. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  179. json.data.calculateGrid.each(function(d){
  180. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  181. td.set("text", d.value);
  182. }.bind(this));
  183. }
  184. }
  185. this.setContentColumnWidth();
  186. this.setContentHeight();
  187. }.bind(this));
  188. }.bind(this));
  189. }
  190. },
  191. addColumn: function(){
  192. debugger;
  193. MWF.require("MWF.widget.UUID", function(){
  194. var id = (new MWF.widget.UUID).id;
  195. var json = {
  196. "id": id,
  197. "column": "",
  198. "displayName": this.designer.lp.unnamed,
  199. "calculateType": "sum",
  200. "orderType": "original",
  201. "orderEffectType": "key"
  202. };
  203. if (!this.json.data.calculate.calculateList) this.json.data.calculate.calculateList = [];
  204. this.json.data.calculate.calculateList.push(json);
  205. var column = new MWF.xApplication.query.StatDesigner.Stat.Column(json, this);
  206. this.items.push(column);
  207. column.selected();
  208. if (this.viewContentTableNode){
  209. var trs = this.viewContentTableNode.getElements("tr");
  210. trs.each(function(tr){
  211. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  212. }.bind(this));
  213. //this.setContentColumnWidth();
  214. }
  215. this.setViewWidth();
  216. this.addColumnNode.scrollIntoView(true);
  217. }.bind(this));
  218. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  219. },
  220. loadViewColumns: function(){
  221. // for (var i=0; i<10; i++){
  222. if (this.json.data.calculate.calculateList) {
  223. this.json.data.calculate.calculateList.each(function (json) {
  224. this.items.push(new MWF.xApplication.query.StatDesigner.Stat.Column(json, this));
  225. }.bind(this));
  226. }
  227. // }
  228. },
  229. saveSilence: function(callback){
  230. if (!this.data.name){
  231. this.designer.notice(this.designer.lp.notice.inputName, "error");
  232. return false;
  233. }
  234. if (!this.data.view){
  235. this.designer.notice(this.designer.lp.notice.inputView, "error");
  236. return false;
  237. }
  238. if (!this.checkViewAndColumn()){
  239. this.designer.notice(this.designer.lp.notice.errorViewColumn, "error");
  240. return false;
  241. }
  242. this.designer.actions.saveStat(this.data, function(json){
  243. this.data.id = json.data.id;
  244. if (this.lisNode) {
  245. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  246. }
  247. if (callback) callback();
  248. }.bind(this));
  249. },
  250. save: function(callback){
  251. //if (this.designer.tab.showPage==this.page){
  252. debugger;
  253. if (!this.data.name){
  254. this.designer.notice(this.designer.lp.notice.inputName, "error");
  255. return false;
  256. }
  257. if (!this.data.view){
  258. this.designer.notice(this.designer.lp.notice.inputView, "error");
  259. return false;
  260. }
  261. if (!this.checkViewAndColumn()){
  262. this.designer.notice(this.designer.lp.notice.errorViewColumn, "error");
  263. return false;
  264. }
  265. //}
  266. this.designer.actions.saveStat(this.data, function(json){
  267. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  268. this.data.id = json.data.id;
  269. if (this.lisNode) {
  270. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  271. }
  272. if (callback) callback();
  273. }.bind(this));
  274. },
  275. checkViewAndColumn: function(){
  276. if (this.json.view){
  277. var flag = true;
  278. for (var i = 0; i<this.items.length; i++){
  279. if (!this.items[i].checkColumn()) flag = false;
  280. }
  281. return flag;
  282. }else{
  283. return false;
  284. }
  285. },
  286. _setEditStyle: function(name, input, oldValue){
  287. debugger;
  288. if (name=="view"){
  289. if (this.data.view!=oldValue){
  290. this.viewContentBodyNode.empty();
  291. this.designer.actions.getView(this.json.view, function(view){
  292. this.queryView = JSON.decode(view.data.data);
  293. }.bind(this), null, false);
  294. this.changeViewSelected();
  295. this.checkViewAndColumn();
  296. }
  297. }
  298. if (name=="data.calculate.isGroup"){
  299. this.viewContentBodyNode.empty();
  300. if (this.data.data.calculate.isGroup){
  301. this.showGroupTitle();
  302. }else{
  303. this.hideGroupTitle();
  304. }
  305. }
  306. if (name=="data.calculate.title"){
  307. if (!this.data.data.calculate.title){
  308. this.data.data.calculate.title = this.designer.lp.category;
  309. }
  310. if (this.data.data.calculate.title!= oldValue){
  311. if (this.groupTitleNode){
  312. this.groupTitleNode.getFirst().getFirst().set("text", this.data.data.calculate.title);
  313. }
  314. }
  315. }
  316. },
  317. showGroupTitle: function(){
  318. if (!this.groupTitleNode) this.createGroupTitltNode();
  319. },
  320. hideGroupTitle: function(){
  321. if (this.groupTitleNode){
  322. this.groupTitleNode.destroy();
  323. this.groupTitleNode = null;
  324. }
  325. },
  326. createGroupTitltNode: function(){
  327. this.data.data.calculate.title = this.data.data.calculate.title || this.designer.lp.category;
  328. this.groupTitleNode = new Element("td", {"styles": this.css.viewGroupTitleNode});
  329. var node = new Element("div", {
  330. "styles": this.css.viewGroupTitleColumnNode
  331. }).inject(this.groupTitleNode);
  332. var textNode = new Element("div", {
  333. "styles": this.css.viewGroupTitleColumnTextNode,
  334. "text": this.data.data.calculate.title
  335. }).inject(node);
  336. if (this.items.length){
  337. this.groupTitleNode.inject(this.items[0].areaNode, "before");
  338. }else{
  339. this.groupTitleNode.inject(this.viewTitleTrNode);
  340. }
  341. },
  342. saveAs: function(){
  343. debugger;
  344. var form = new MWF.xApplication.query.StatDesigner.Stat.NewNameForm(this, {
  345. name : this.data.name + "_" + MWF.xApplication.query.StatDesigner.LP.copy,
  346. view : this.data.view,
  347. query : this.data.query || this.data.application,
  348. queryName : this.data.queryName || this.data.applicationName
  349. }, {
  350. onSave : function( data, callback ){
  351. this._saveAs( data, callback );
  352. }.bind(this)
  353. }, {
  354. app: this.designer
  355. });
  356. form.edit()
  357. },
  358. explode: function(){},
  359. implode: function(){},
  360. _saveAs : function( data , callback){
  361. var _self = this;
  362. var d = Object.clone( this.data );
  363. d.isNewView = true;
  364. d.id = this.designer.actions.getUUID();
  365. d.name = data.name;
  366. d.alias = "";
  367. d.query = data.query;
  368. d.queryName = data.queryName;
  369. d.application = data.query;
  370. d.applicationName = data.queryName;
  371. d.view = data.view;
  372. //d.pid = d.id + d.id;
  373. //delete d[this.data.id+"viewFilterType"];
  374. //d[d.id+"viewFilterType"]="custom";
  375. if( d.data.calculate && d.data.calculate.calculateList ){
  376. d.data.calculate.calculateList.each( function( entry ){
  377. entry.id = (new MWF.widget.UUID).id;
  378. }.bind(this));
  379. }
  380. this.designer.actions.saveStat(d, function(json){
  381. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  382. if (callback) callback();
  383. }.bind(this));
  384. }
  385. //_setEditStyle: function(){}
  386. });
  387. MWF.xApplication.query.StatDesigner.Stat.Column = new Class({
  388. Extends:MWF.xApplication.query.ViewDesigner.View.Column,
  389. initialize: function(json, view, next){
  390. this.propertyPath = "/x_component_process_StatDesigner/$Stat/column.html";
  391. this.view = view;
  392. this.json = json;
  393. this.next = next;
  394. this.css = this.view.css;
  395. this.content = this.view.viewTitleTrNode;
  396. this.domListNode = this.view.domListNode;
  397. this.load();
  398. },
  399. showProperty: function(){
  400. if (!this.property){
  401. this.property = new MWF.xApplication.query.StatDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  402. "path": this.propertyPath,
  403. "onPostLoad": function(){
  404. this.property.show();
  405. }.bind(this)
  406. });
  407. this.property.load();
  408. }else{
  409. this.property.show();
  410. }
  411. },
  412. _setEditStyle: function(name, input, oldValue){
  413. //if (name=="displayName") this.resetTextNode();
  414. //if (name=="selectType") this.resetTextNode();
  415. //if (name=="attribute") this.resetTextNode();
  416. //if (name=="path") this.resetTextNode();
  417. if (name=="displayName") this.resetTextNode();
  418. if (name=="column") this.checkColumn();
  419. },
  420. resetTextNode: function(){
  421. var listText = this.json.displayName+"("+this.json.calculateType+")";
  422. this.textNode.set("text", this.json.displayName);
  423. this.listNode.getLast().set("text", listText);
  424. },
  425. "delete": function(e){
  426. var _self = this;
  427. if (!e) e = this.node;
  428. this.view.designer.confirm("warn", e, MWF.APPDSTD.LP.notice.deleteColumnTitle, MWF.APPDSTD.LP.notice.deleteColumn, 300, 120, function(){
  429. _self.destroy();
  430. this.close();
  431. }, function(){
  432. this.close();
  433. }, null);
  434. },
  435. addColumn: function(e, data){
  436. MWF.require("MWF.widget.UUID", function(){
  437. var json;
  438. if (data){
  439. json = Object.clone(data);
  440. json.id = (new MWF.widget.UUID).id;
  441. json.column = (new MWF.widget.UUID).id;
  442. }else{
  443. var id = (new MWF.widget.UUID).id;
  444. json = {
  445. "id": id,
  446. "column": "",
  447. "displayName": this.view.designer.lp.unnamed,
  448. "calculateType": "sum",
  449. "orderType": "original",
  450. "orderEffectType": "key"
  451. };
  452. }
  453. var idx = this.view.json.data.calculate.calculateList.indexOf(this.json);
  454. this.view.json.data.calculate.calculateList.splice(idx, 0, json);
  455. var column = new MWF.xApplication.query.StatDesigner.Stat.Column(json, this.view, this);
  456. this.view.items.splice(idx, 0, column);
  457. column.selected();
  458. if (this.view.viewContentTableNode){
  459. var trs = this.view.viewContentTableNode.getElements("tr");
  460. trs.each(function(tr){
  461. var td = tr.insertCell(idx);
  462. td.setStyles(this.css.viewContentTdNode);
  463. }.bind(this));
  464. }
  465. this.view.setViewWidth();
  466. }.bind(this));
  467. },
  468. _setNodeMove: function(droppables, e){
  469. this._setMoveNodePosition(e);
  470. var movePosition = this.moveNode.getPosition();
  471. var moveSize = this.moveNode.getSize();
  472. var contentPosition = this.content.getPosition();
  473. var contentSize = this.content.getSize();
  474. var nodeDrag = new Drag.Move(this.moveNode, {
  475. "droppables": droppables,
  476. "limit": {
  477. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  478. "y": [movePosition.y, movePosition.y+moveSize.y]
  479. },
  480. "onEnter": function(dragging, inObj){
  481. if (!this.moveFlagNode) this.createMoveFlagNode();
  482. this.moveFlagNode.inject(inObj, "before");
  483. }.bind(this),
  484. "onLeave": function(dragging, inObj){
  485. if (this.moveFlagNode){
  486. this.moveFlagNode.dispose();
  487. }
  488. }.bind(this),
  489. "onDrop": function(dragging, inObj){
  490. if (inObj){
  491. this.areaNode.inject(inObj, "before");
  492. var column = inObj.retrieve("column");
  493. this.listNode.inject(column.listNode, "before");
  494. var idx = this.view.json.data.calculate.calculateList.indexOf(column.json);
  495. this.view.json.data.calculate.calculateList.erase(this.json);
  496. this.view.items.erase(this);
  497. this.view.json.data.calculate.calculateList.splice(idx, 0, this.json);
  498. this.view.items.splice(idx, 0, this);
  499. if (this.moveNode) this.moveNode.destroy();
  500. if (this.moveFlagNode) this.moveFlagNode.destroy();
  501. this._setActionAreaPosition();
  502. }else{
  503. if (this.moveNode) this.moveNode.destroy();
  504. if (this.moveFlagNode) this.moveFlagNode.destroy();
  505. }
  506. }.bind(this),
  507. "onCancel": function(dragging){
  508. if (this.moveNode) this.moveNode.destroy();
  509. if (this.moveFlagNode) this.moveFlagNode.destroy();
  510. }.bind(this)
  511. });
  512. nodeDrag.start(e);
  513. },
  514. changeViewSelected: function(json){
  515. debugger;
  516. if (json){
  517. this.changeViewColumnOptions(json);
  518. }else{
  519. if (this.view.json.view){
  520. if (!this.view.queryView){
  521. this.view.designer.actions.getView(this.view.json.view, function(view){
  522. this.view.queryView = JSON.decode(view.data.data);
  523. this.changeViewColumnOptions(this.view.queryView);
  524. }.bind(this));
  525. }else{
  526. this.changeViewColumnOptions(this.view.queryView);
  527. }
  528. }else{
  529. this.changeViewColumnOptions(json);
  530. }
  531. }
  532. },
  533. changeViewColumnOptions: function(json){
  534. if (this.property){
  535. var nodes = this.property.propertyContent.getElements(".MWFViewColumnSelect");
  536. nodes.each(function(node){
  537. node.empty();
  538. if (json){
  539. new Element("option", {
  540. "value": "",
  541. "text": "(none)",
  542. "selected": (!this.json.column)
  543. }).inject(node);
  544. json.selectList.each(function(col){
  545. var o = new Element("option", {
  546. "value": col.column,
  547. "text": col.displayName,
  548. "selected": (col.column==this.json.column)
  549. }).inject(node);
  550. }.bind(this));
  551. }else{
  552. this.json.column = "";
  553. }
  554. }.bind(this));
  555. }
  556. },
  557. checkColumn: function(){
  558. var flag = true;
  559. if (!this.view.queryView){
  560. this.designer.actions.getView(this.view.json.view, function(view){
  561. this.view.queryView = JSON.decode(view.data.data);
  562. }.bind(this), null, false);
  563. }
  564. var col = this.view.queryView.selectList.filter(function(c){
  565. return (c.column==this.json.column);
  566. }.bind(this));
  567. if (!col.length){
  568. this.errorMark();
  569. flag = false;
  570. }else{
  571. this.errorMark(true);
  572. }
  573. return flag;
  574. },
  575. errorMark: function(flag){
  576. if (flag){
  577. this.isError = false;
  578. if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode);
  579. }else{
  580. this.isError = true;
  581. if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_error);
  582. }
  583. }
  584. });