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