Stat.js 22 KB

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