Stat.js 23 KB

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