Stat.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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.require("MWF.widget.Common", null, false);
  6. MWF.require("MWF.xScript.Macro", null, false);
  7. MWF.xDesktop.requireApp("query.StatDesigner", "lp."+MWF.language, null, false);
  8. //MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  9. MWF.xDesktop.requireApp("query.StatDesigner", "Property", null, false);
  10. MWF.xApplication.query.StatDesigner.Stat = new Class({
  11. //Extends: MWF.xApplication.query.ViewDesigner.View,
  12. Extends: MWF.widget.Common,
  13. Implements: [Options, Events],
  14. options: {
  15. "style": "default",
  16. "isView": false,
  17. "showTab": true,
  18. "propertyPath": "/x_component_query_StatDesigner/$Stat/stat.html"
  19. },
  20. initialize: function(designer, data, options){
  21. this.setOptions(options);
  22. this.path = "/x_component_query_StatDesigner/$Stat/";
  23. this.cssPath = "/x_component_query_StatDesigner/$Stat/"+this.options.style+"/css.wcss";
  24. this._loadCss();
  25. this.designer = designer;
  26. this.data = data;
  27. if (!this.data.data) this.data.data = {};
  28. this.parseData();
  29. this.node = this.designer.designNode;
  30. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  31. this.propertyListNode = this.designer.propertyDomArea;
  32. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  33. if(this.designer.application) this.data.application = this.designer.application.id;
  34. this.isNewView = (this.data.id) ? false : true;
  35. this.items = [];
  36. this.view = this;
  37. this.queryView = null;
  38. this.autoSave();
  39. this.designer.addEvent("queryClose", function(){
  40. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  41. }.bind(this));
  42. },
  43. changeViewSelected: function(){
  44. if (this.json.view){
  45. if (!this.queryView){
  46. this.designer.actions.getView(this.json.view, function(view){
  47. this.queryView = JSON.decode(view.data.data);
  48. this.items.each(function(item){
  49. item.changeViewSelected(this.queryView);
  50. }.bind(this));
  51. this.checkIsGroupRadioDisplay();
  52. }.bind(this));
  53. }else{
  54. this.items.each(function(item){
  55. item.changeViewSelected(this.queryView);
  56. }.bind(this));
  57. this.checkIsGroupRadioDisplay();
  58. }
  59. }else{
  60. //item.changeViewSelected();
  61. }
  62. },
  63. checkIsGroupRadioDisplay: function(){
  64. if (this.property){
  65. var groupNode = this.property.propertyContent.getElement(".MWFIsGroupArea");
  66. if (groupNode){
  67. if (this.queryView.group.column){
  68. groupNode.setStyle("display", "block");
  69. }else{
  70. this.json.data.calculate.isGroup = false;
  71. var radios = groupNode.getElements("input");
  72. for (var i=0; i<radios.length; i++){
  73. if (radios[i].value=="false"){
  74. radios[i].set("checked", true);
  75. break;
  76. }
  77. }
  78. this.hideGroupTitle();
  79. groupNode.setStyle("display", "none");
  80. }
  81. }
  82. }
  83. },
  84. checkIsGroupRadio: function(){
  85. if (!this.queryView){
  86. this.designer.actions.getView(this.json.view, function(view){
  87. this.queryView = JSON.decode(view.data.data);
  88. this.checkIsGroupRadioDisplay();
  89. }.bind(this));
  90. }else{
  91. this.checkIsGroupRadioDisplay();
  92. }
  93. },
  94. autoSave: function(){
  95. this.autoSaveTimerID = window.setInterval(function(){
  96. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFDictionaryAutoSaveCheck");
  97. if (this.autoSaveCheckNode){
  98. if (this.autoSaveCheckNode.get("checked")){
  99. this.save();
  100. }
  101. }
  102. }.bind(this), 60000);
  103. },
  104. parseData: function(){
  105. this.json = this.data;
  106. },
  107. showProperty: function(){
  108. if (!this.property){
  109. this.property = new MWF.xApplication.query.StatDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  110. "path": this.options.propertyPath,
  111. "onPostLoad": function(){
  112. this.property.show();
  113. }.bind(this)
  114. });
  115. this.property.load();
  116. }else{
  117. this.property.show();
  118. }
  119. },
  120. //getDataTr: function(ri){
  121. // var tr = null;
  122. // var trs = this.viewContentTableNode.getElements("tr");
  123. // if (trs.length) if (trs[ri]) tr = trs[ri];
  124. // return tr;
  125. //},
  126. //getDataTd: function(tr, ci){
  127. // var td = null;
  128. // var tds = tr.getElements("td");
  129. // if (tds.length) if (tds[ci]) td = tds[ci];
  130. // return td;
  131. //},
  132. //getDataLastColumnCell: function(ri, ci){
  133. // var trs = this.viewContentTableNode.getElements("tr");
  134. // if (trs.length) if (trs[ri]) tr = trs[ri];
  135. // var td = null;
  136. // var tds = tr.getElements("td");
  137. // if (tds.length) if (tds[ci]) td = tds[ci];
  138. // return td;
  139. //},
  140. hideProperty: function(){
  141. if (this.property) this.property.hide();
  142. },
  143. load : function(){
  144. this.setAreaNodeSize();
  145. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  146. this.areaNode.inject(this.node);
  147. this.designer.viewListAreaNode.getChildren().each(function(node){
  148. var view = node.retrieve("view");
  149. if (view.id==this.data.id){
  150. if (this.designer.currentListViewItem){
  151. this.designer.currentListViewItem.setStyles(this.designer.css.listViewItem);
  152. }
  153. node.setStyles(this.designer.css.listViewItem_current);
  154. this.designer.currentListViewItem = node;
  155. this.lisNode = node;
  156. }
  157. }.bind(this));
  158. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  159. this.loadView();
  160. this.selected();
  161. this.setEvent();
  162. //if (this.options.showTab) this.page.showTabIm();
  163. this.setViewWidth();
  164. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  165. },
  166. setEvent: function(){
  167. this.areaNode.addEvent("click", this.selected.bind(this));
  168. this.refreshNode.addEvent("click", function(e){
  169. this.loadViewData();
  170. e.stopPropagation();
  171. }.bind(this));
  172. this.addColumnNode.addEvent("click", function(e){
  173. this.addColumn();
  174. e.stopPropagation();
  175. }.bind(this));
  176. },
  177. loadViewData: function(){
  178. if (this.data.id){
  179. this.saveSilence(function(){
  180. this.viewContentBodyNode.empty();
  181. this.viewContentTableNode = new Element("table", {
  182. "styles": this.css.viewContentTableNode,
  183. "border": "0px",
  184. "cellPadding": "0",
  185. "cellSpacing": "0"
  186. }).inject(this.viewContentBodyNode);
  187. this.designer.actions.loadStat(this.data.id, null, function(json){
  188. var entries = {};
  189. json.data.calculate.calculateList.each(function(entry){entries[entry.id] = entry;}.bind(this));
  190. if (this.json.data.calculate.isGroup){
  191. if (json.data.calculateGrid.length){
  192. json.data.calculateGrid.each(function(d){
  193. // var groupColumn = null;
  194. // for (var c = 0; c<json.data.calculate.calculateList.length; c++){
  195. // if (json.data.calculate.calculateList[c].column === json.data.group.column){
  196. // groupColumn = json.data.calculate.calculateList[c];
  197. // break;
  198. // }
  199. // }
  200. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  201. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  202. // if (groupColumn){
  203. // td.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": d.group, "data": json.data}) : d.group);
  204. // }else{
  205. td.set("text", d.group);
  206. // }
  207. //td.set("text", d.group);
  208. td.setStyle("font-weight", "bold");
  209. d.list.each(function(c){
  210. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  211. td.set("text", (entries[c.column].code) ? MWF.Macro.exec(entries[c.column].code, {"value": c.value, "data": json.data}) : c.value);
  212. }.bind(this));
  213. }.bind(this));
  214. }
  215. if (json.data.calculateAmountGrid){
  216. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  217. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  218. td.set("text", this.designer.lp.amount);
  219. td.setStyles({"font-weight": "bold", "color": "#0000FF"});
  220. json.data.calculateAmountGrid.each(function(c){
  221. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  222. td.set("text", c.value);
  223. td.setStyles({"font-weight": "bold", "color": "#0000FF"});
  224. }.bind(this));
  225. }
  226. }else{
  227. if (json.data.calculateGrid.length){
  228. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  229. json.data.calculateGrid.each(function(d){
  230. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  231. td.set("text", d.value);
  232. }.bind(this));
  233. }
  234. }
  235. this.setContentColumnWidth();
  236. this.setContentHeight();
  237. }.bind(this));
  238. }.bind(this));
  239. }
  240. },
  241. setContentColumnWidth: function(){
  242. var titleTds = this.viewTitleTrNode.getElements("td");
  243. var widthList = [];
  244. titleTds.each(function(td){widthList.push(td.getSize().x);});
  245. var flag = false;
  246. if (this.viewContentTableNode){
  247. trs = this.viewContentTableNode.getElements("tr");
  248. for (var i=0; i<trs.length; i++){
  249. var tr = trs[i];
  250. var tds = tr.getElements("td");
  251. tds.each(function(contentTd, i){
  252. if (contentTd.get("colSpan")==1){
  253. contentTd.setStyle("width", ""+widthList[i]+"px");
  254. flag = true;
  255. }
  256. });
  257. if (flag) break;
  258. }
  259. //var tr = this.viewContentTableNode.getFirst("tr");
  260. //if (tr){
  261. // var tds = tr.getElements("td");
  262. // tds.each(function(contentTd, i){
  263. // if (!contentTd.get("colSpan")){
  264. // contentTd.setStyle("width", ""+widthList[i]+"px");
  265. // }
  266. // });
  267. //}
  268. }
  269. },
  270. addColumn: function(){
  271. MWF.require("MWF.widget.UUID", function(){
  272. var id = (new MWF.widget.UUID).id;
  273. var json = {
  274. "id": id,
  275. "column": "",
  276. "displayName": this.designer.lp.unnamed,
  277. "calculateType": "sum",
  278. "orderType": "original",
  279. "orderEffectType": "key"
  280. };
  281. if (!this.json.data.calculate.calculateList) this.json.data.calculate.calculateList = [];
  282. this.json.data.calculate.calculateList.push(json);
  283. var column = new MWF.xApplication.query.StatDesigner.Stat.Column(json, this);
  284. this.items.push(column);
  285. column.selected();
  286. if (this.property) this.property.loadStatColumnSelect();
  287. if (this.viewContentTableNode){
  288. var trs = this.viewContentTableNode.getElements("tr");
  289. trs.each(function(tr){
  290. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  291. }.bind(this));
  292. //this.setContentColumnWidth();
  293. }
  294. this.setViewWidth();
  295. this.addColumnNode.scrollIntoView(true);
  296. }.bind(this));
  297. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  298. },
  299. selected: function(){
  300. if (this.currentSelectedModule){
  301. if (this.currentSelectedModule==this){
  302. return true;
  303. }else{
  304. this.currentSelectedModule.unSelected();
  305. }
  306. }
  307. this.currentSelectedModule = this;
  308. this.showProperty();
  309. },
  310. unSelected: function(){
  311. this.currentSelectedModule = null;
  312. this.hideProperty();
  313. },
  314. loadViewNodes: function(){
  315. this.viewAreaNode = new Element("div#viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.areaNode);
  316. this.viewTitleNode = new Element("div#viewTitleNode", {"styles": this.css.viewTitleNode}).inject(this.viewAreaNode);
  317. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.viewTitleNode);
  318. this.addColumnNode = new Element("div", {"styles": this.css.addColumnNode}).inject(this.viewTitleNode);
  319. this.viewTitleContentNode = new Element("div", {"styles": this.css.viewTitleContentNode}).inject(this.viewTitleNode);
  320. this.viewTitleTableNode = new Element("table", {
  321. "styles": this.css.viewTitleTableNode,
  322. "border": "0px",
  323. "cellPadding": "0",
  324. "cellSpacing": "0"
  325. }).inject(this.viewTitleContentNode);
  326. this.viewTitleTrNode = new Element("tr", {"styles": this.css.viewTitleTrNode}).inject(this.viewTitleTableNode);
  327. this.viewContentScrollNode = new Element("div", {"styles": this.css.viewContentScrollNode}).inject(this.viewAreaNode);
  328. this.viewContentNode = new Element("div", {"styles": this.css.viewContentNode}).inject(this.viewContentScrollNode);
  329. MWF.require("MWF.widget.ScrollBar", function(){
  330. new MWF.widget.ScrollBar(this.viewContentScrollNode, {"style": "view", "distance": 100, "indent": false});
  331. }.bind(this));
  332. this.contentLeftNode = new Element("div", {"styles": this.css.contentLeftNode}).inject(this.viewContentNode);
  333. this.contentRightNode = new Element("div", {"styles": this.css.contentRightNode}).inject(this.viewContentNode);
  334. this.viewContentBodyNode = new Element("div", {"styles": this.css.viewContentBodyNode}).inject(this.viewContentNode);
  335. this.viewContentTableNode = new Element("table", {
  336. "styles": this.css.viewContentTableNode,
  337. "border": "0px",
  338. "cellPadding": "0",
  339. "cellSpacing": "0"
  340. }).inject(this.viewContentBodyNode);
  341. },
  342. setContentHeight: function(){
  343. var size = this.areaNode.getSize();
  344. var titleSize = this.viewTitleNode.getSize();
  345. var height = size.y-titleSize.y-2;
  346. this.viewContentScrollNode.setStyle("height", height);
  347. var contentSize = this.viewContentBodyNode.getSize();
  348. if (height<contentSize.y) height = contentSize.y+10;
  349. this.viewContentNode.setStyle("height", height);
  350. this.contentLeftNode.setStyle("height", height);
  351. this.contentRightNode.setStyle("height", height);
  352. //this.viewContentBodyNode.setStyle("min-height", height);
  353. },
  354. loadViewColumns: function(){
  355. // for (var i=0; i<10; i++){
  356. if (this.json.data.calculate.calculateList) {
  357. this.json.data.calculate.calculateList.each(function (json) {
  358. this.items.push(new MWF.xApplication.query.StatDesigner.Stat.Column(json, this));
  359. }.bind(this));
  360. }
  361. // }
  362. },
  363. loadView: function(){
  364. this.loadViewNodes();
  365. this.loadViewColumns();
  366. // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this));
  367. },
  368. setViewWidth: function(){
  369. this.viewAreaNode.setStyle("width", "auto");
  370. this.viewTitleNode.setStyle("width", "auto");
  371. var s1 = this.viewTitleTableNode.getSize();
  372. var s2 = this.refreshNode.getSize();
  373. var s3 = this.addColumnNode.getSize();
  374. var width = s1.x+s2.x+s2.x;
  375. var size = this.areaNode.getSize();
  376. if (width>size.x){
  377. this.viewTitleNode.setStyle("width", ""+width+"px");
  378. this.viewAreaNode.setStyle("width", ""+width+"px");
  379. }else{
  380. this.viewTitleNode.setStyle("width", ""+size.x+"px");
  381. this.viewAreaNode.setStyle("width", ""+size.x+"px");
  382. }
  383. this.setContentColumnWidth();
  384. this.setContentHeight();
  385. },
  386. //setPropertyContent: function(){
  387. // this.designer.propertyIdNode.set("text", this.data.id);
  388. // this.designer.propertyNameNode.set("value", this.data.name);
  389. // this.designer.propertyAliasNode.set("value", this.data.alias);
  390. // this.designer.propertyDescriptionNode.set("value", this.data.description);
  391. //
  392. // this.designer.jsonDomNode.empty();
  393. // MWF.require("MWF.widget.JsonParse", function(){
  394. // this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode);
  395. // window.setTimeout(function(){
  396. // this.jsonParse.load();
  397. // }.bind(this), 1);
  398. // }.bind(this));
  399. //},
  400. setAreaNodeSize: function(){
  401. //var size = this.node.getSize();
  402. ////var tabSize = this.tab.tabNodeContainer.getSize();
  403. //var tabSize = this.node.getSize();
  404. //var y = size.y - tabSize.y;
  405. //this.areaNode.setStyle("height", ""+y+"px");
  406. //if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  407. },
  408. // createRootItem: function() {
  409. // this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  410. // },
  411. saveSilence: function(callback){
  412. if (!this.data.name){
  413. this.designer.notice(this.designer.lp.notice.inputName, "error");
  414. return false;
  415. }
  416. // if (!this.data.view){
  417. // this.designer.notice(this.designer.lp.notice.inputView, "error");
  418. // return false;
  419. // }
  420. if (!this.checkViewAndColumn()){
  421. this.designer.notice(this.designer.lp.notice.errorViewColumn, "error");
  422. return false;
  423. }
  424. this.designer.actions.saveStat(this.data, function(json){
  425. this.data.id = json.data.id;
  426. if (this.lisNode) {
  427. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  428. }
  429. if (callback) callback();
  430. }.bind(this));
  431. },
  432. save: function(callback){
  433. //if (this.designer.tab.showPage==this.page){
  434. if (!this.data.name){
  435. this.designer.notice(this.designer.lp.notice.inputName, "error");
  436. return false;
  437. }
  438. // if (!this.data.view){
  439. // this.designer.notice(this.designer.lp.notice.inputView, "error");
  440. // return false;
  441. // }
  442. if (!this.checkViewAndColumn()){
  443. this.designer.notice(this.designer.lp.notice.errorViewColumn, "error");
  444. return false;
  445. }
  446. //}
  447. this.designer.actions.saveStat(this.data, function(json){
  448. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  449. this.data.id = json.data.id;
  450. if (this.lisNode) {
  451. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  452. }
  453. if (callback) callback();
  454. }.bind(this));
  455. },
  456. checkViewAndColumn: function(){
  457. // if (this.json.view){
  458. var flag = true;
  459. for (var i = 0; i<this.items.length; i++){
  460. if (!this.items[i].checkColumn()) flag = false;
  461. }
  462. return flag;
  463. // }else{
  464. // return false;
  465. // }
  466. },
  467. explode: function(){},
  468. implode: function(){},
  469. _setEditStyle: function(name, input, oldValue){
  470. // if (name=="view"){
  471. // if (this.data.view!=oldValue){
  472. // this.viewContentBodyNode.empty();
  473. // this.designer.actions.getView(this.json.view, function(view){
  474. // this.queryView = JSON.decode(view.data.data);
  475. // }.bind(this), null, false);
  476. //
  477. // this.changeViewSelected();
  478. // this.checkViewAndColumn();
  479. // }
  480. // }
  481. if (name=="data.calculate.isGroup"){
  482. this.viewContentBodyNode.empty();
  483. if (this.data.data.calculate.isGroup){
  484. this.showGroupTitle();
  485. }else{
  486. this.hideGroupTitle();
  487. }
  488. }
  489. if (name=="data.calculate.title"){
  490. if (!this.data.data.calculate.title){
  491. this.data.data.calculate.title = this.designer.lp.category;
  492. }
  493. if (this.data.data.calculate.title!= oldValue){
  494. if (this.groupTitleNode){
  495. this.groupTitleNode.getFirst().getFirst().set("text", this.data.data.calculate.title);
  496. }
  497. }
  498. }
  499. },
  500. showGroupTitle: function(){
  501. if (!this.groupTitleNode) this.createGroupTitltNode();
  502. },
  503. hideGroupTitle: function(){
  504. if (this.groupTitleNode){
  505. this.groupTitleNode.destroy();
  506. this.groupTitleNode = null;
  507. }
  508. },
  509. createGroupTitltNode: function(){
  510. this.data.data.calculate.title = this.data.data.calculate.title || this.designer.lp.category;
  511. this.groupTitleNode = new Element("td", {"styles": this.css.viewGroupTitleNode});
  512. var node = new Element("div", {
  513. "styles": this.css.viewGroupTitleColumnNode
  514. }).inject(this.groupTitleNode);
  515. var textNode = new Element("div", {
  516. "styles": this.css.viewGroupTitleColumnTextNode,
  517. "text": this.data.data.calculate.title
  518. }).inject(node);
  519. if (this.items.length){
  520. this.groupTitleNode.inject(this.items[0].areaNode, "before");
  521. }else{
  522. this.groupTitleNode.inject(this.viewTitleTrNode);
  523. }
  524. },
  525. saveAs: function(){
  526. var form = new MWF.xApplication.query.StatDesigner.Stat.NewNameForm(this, {
  527. name : this.data.name + "_" + MWF.xApplication.query.StatDesigner.LP.copy,
  528. view : this.data.view,
  529. query : this.data.query || this.data.application,
  530. queryName : this.data.queryName || this.data.applicationName
  531. }, {
  532. onSave : function( data, callback ){
  533. this._saveAs( data, callback );
  534. }.bind(this)
  535. }, {
  536. app: this.designer
  537. });
  538. form.edit()
  539. },
  540. cloneObject : function( obj ){
  541. if (null == obj || "object" != typeof obj) return obj;
  542. if ( typeof obj.length==='number'){ //数组
  543. //print( "array" );
  544. var copy = [];
  545. for (var i = 0, len = obj.length; i < len; ++i) {
  546. copy[i] = this.cloneObject(obj[i]);
  547. }
  548. return copy;
  549. }else{
  550. var copy = {};
  551. for (var attr in obj) {
  552. copy[attr] = this.cloneObject(obj[attr]);
  553. }
  554. return copy;
  555. }
  556. },
  557. _saveAs : function( data , callback){
  558. var _self = this;
  559. var d = Object.clone( this.data );
  560. d.isNewView = true;
  561. d.id = this.designer.actions.getUUID();
  562. d.name = data.name;
  563. d.alias = "";
  564. d.query = data.query;
  565. d.queryName = data.queryName;
  566. d.application = data.query;
  567. d.applicationName = data.queryName;
  568. d.view = data.view;
  569. //d.pid = d.id + d.id;
  570. //delete d[this.data.id+"viewFilterType"];
  571. //d[d.id+"viewFilterType"]="custom";
  572. if( d.data.calculate && d.data.calculate.calculateList ){
  573. d.data.calculate.calculateList.each( function( entry ){
  574. entry.id = (new MWF.widget.UUID).id;
  575. }.bind(this));
  576. }
  577. this.designer.actions.saveStat(d, function(json){
  578. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  579. if (callback) callback();
  580. }.bind(this));
  581. }
  582. //_setEditStyle: function(){}
  583. });
  584. MWF.xApplication.query.StatDesigner.Stat.Column = new Class({
  585. //Extends:MWF.xApplication.query.ViewDesigner.View.Column,
  586. initialize: function(json, view, next){
  587. this.propertyPath = "/x_component_query_StatDesigner/$Stat/column.html";
  588. this.view = view;
  589. this.json = json;
  590. this.next = next;
  591. this.css = this.view.css;
  592. this.content = this.view.viewTitleTrNode;
  593. this.domListNode = this.view.domListNode;
  594. this.load();
  595. },
  596. load: function(){
  597. this.areaNode = new Element("td", {"styles": this.css.viewTitleColumnAreaNode});
  598. this.areaNode.store("column", this);
  599. if (this.next){
  600. this.areaNode.inject(this.next.areaNode, "before");
  601. }else{
  602. this.areaNode.inject(this.content);
  603. }
  604. this.node = new Element("div", {
  605. "styles": this.css.viewTitleColumnNode
  606. }).inject(this.areaNode);
  607. this.textNode = new Element("div", {
  608. "styles": this.css.viewTitleColumnTextNode,
  609. "text": this.json.displayName
  610. }).inject(this.node);
  611. this.createDomListItem();
  612. this._createIconAction();
  613. //if (!this.json.export) this.hideMode();
  614. this.setEvent();
  615. },
  616. createDomListItem: function(){
  617. this.listNode = new Element("div", {"styles": this.css.cloumnListNode});
  618. if (this.next){
  619. this.listNode.inject(this.next.listNode, "before");
  620. }else{
  621. this.listNode.inject(this.domListNode);
  622. }
  623. var listIconNode = new Element("div", {"styles": this.css.cloumnListIconNode}).inject(this.listNode);
  624. var listTextNode = new Element("div", {"styles": this.css.cloumnListTextNode}).inject(this.listNode);
  625. this.resetTextNode();
  626. },
  627. setEvent: function(){
  628. this.node.addEvents({
  629. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  630. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  631. "mouseout": function(){if (!this.isSelected) if (this.isError){
  632. this.node.setStyles(this.css.viewTitleColumnNode_error)
  633. }else{
  634. this.node.setStyles(this.css.viewTitleColumnNode)
  635. }}.bind(this)
  636. });
  637. this.listNode.addEvents({
  638. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  639. "mouseover": function(){debugger; if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode_over)}.bind(this),
  640. "mouseout": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode)}.bind(this)
  641. });
  642. },
  643. _createIconAction: function(){
  644. if (!this.actionArea){
  645. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  646. this._createAction({
  647. "name": "move",
  648. "icon": "move1.png",
  649. "event": "mousedown",
  650. "action": "move",
  651. "title": MWF.APPDVD.LP.action.move
  652. });
  653. this._createAction({
  654. "name": "add",
  655. "icon": "add.png",
  656. "event": "click",
  657. "action": "addColumn",
  658. "title": MWF.APPDVD.LP.action.add
  659. });
  660. this._createAction({
  661. "name": "delete",
  662. "icon": "delete1.png",
  663. "event": "click",
  664. "action": "delete",
  665. "title": MWF.APPDVD.LP.action["delete"]
  666. });
  667. }
  668. },
  669. _createAction: function(action){
  670. var actionNode = new Element("div", {
  671. "styles": this.css.actionNodeStyles,
  672. "title": action.title
  673. }).inject(this.actionArea);
  674. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  675. actionNode.addEvent(action.event, function(e){
  676. this[action.action](e);
  677. }.bind(this));
  678. actionNode.addEvents({
  679. "mouseover": function(e){
  680. e.target.setStyle("border", "1px solid #999");
  681. }.bind(this),
  682. "mouseout": function(e){
  683. e.target.setStyle("border", "1px solid #F1F1F1");
  684. }.bind(this)
  685. });
  686. },
  687. _setActionAreaPosition: function(){
  688. var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  689. var y = p.y-25;
  690. var x = p.x;
  691. this.actionArea.setPosition({"x": x, "y": y});
  692. },
  693. _showActions: function(){
  694. if (this.actionArea){
  695. this._setActionAreaPosition();
  696. this.actionArea.setStyle("display", "block");
  697. }
  698. },
  699. _hideActions: function(){
  700. if (this.actionArea) this.actionArea.setStyle("display", "none");
  701. },
  702. selected: function(){
  703. if (this.view.currentSelectedModule){
  704. if (this.view.currentSelectedModule==this){
  705. return true;
  706. }else{
  707. this.view.currentSelectedModule.unSelected();
  708. }
  709. }
  710. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  711. this.listNode.setStyles(this.css.cloumnListNode_selected);
  712. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  713. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  714. this.view.currentSelectedModule = this;
  715. this.isSelected = true;
  716. this._showActions();
  717. this.showProperty();
  718. },
  719. unSelected: function(){
  720. this.view.currentSelectedModule = null;
  721. //this.node.setStyles(this.css.viewTitleColumnNode);
  722. if (this.isError){
  723. this.node.setStyles(this.css.viewTitleColumnNode_error)
  724. }else{
  725. this.node.setStyles(this.css.viewTitleColumnNode)
  726. }
  727. this.listNode.setStyles(this.css.cloumnListNode);
  728. this.isSelected = false;
  729. this._hideActions();
  730. this.hideProperty();
  731. },
  732. showProperty: function(){
  733. if (!this.property){
  734. this.property = new MWF.xApplication.query.StatDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  735. "path": this.propertyPath,
  736. "onPostLoad": function(){
  737. this.property.show();
  738. this.changeViewSelected();
  739. }.bind(this)
  740. });
  741. this.property.load();
  742. }else{
  743. this.property.show();
  744. }
  745. },
  746. hideProperty: function(){
  747. if (this.property) this.property.hide();
  748. },
  749. _setEditStyle: function(name, input, oldValue){
  750. //if (name=="displayName") this.resetTextNode();
  751. //if (name=="selectType") this.resetTextNode();
  752. //if (name=="attribute") this.resetTextNode();
  753. //if (name=="path") this.resetTextNode();
  754. if (name=="displayName") this.resetTextNode();
  755. if (name=="column") this.checkColumn();
  756. if (name=="view"){
  757. if (this.json.view!=oldValue){
  758. this.view.viewContentBodyNode.empty();
  759. this.view.designer.actions.getView(this.json.view, function(view){
  760. this.queryView = JSON.decode(view.data.data);
  761. }.bind(this), null, false);
  762. this.changeViewSelected();
  763. //this.checkViewAndColumn();
  764. }
  765. }
  766. },
  767. resetTextNode: function(){
  768. var listText = this.json.displayName+"("+this.json.calculateType+")";
  769. this.textNode.set("text", this.json.displayName);
  770. this.listNode.getLast().set("text", listText);
  771. if (this.view.property) this.view.property.loadStatColumnSelect();
  772. },
  773. "delete": function(e){
  774. var _self = this;
  775. if (!e) e = this.node;
  776. this.view.designer.confirm("warn", e, MWF.APPDSTD.LP.notice.deleteColumnTitle, MWF.APPDSTD.LP.notice.deleteColumn, 300, 120, function(){
  777. _self.destroy();
  778. this.close();
  779. }, function(){
  780. this.close();
  781. }, null);
  782. },
  783. destroy: function(){
  784. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  785. if (this.actionArea) this.actionArea.destroy();
  786. if (this.listNode) this.listNode.destroy();
  787. if (this.property) this.property.propertyContent.destroy();
  788. var idx = this.view.items.indexOf(this);
  789. if (this.view.viewContentTableNode){
  790. var trs = this.view.viewContentTableNode.getElements("tr");
  791. trs.each(function(tr){
  792. tr.deleteCell(idx);
  793. }.bind(this));
  794. }
  795. if (this.view.json.data.selectList) this.view.json.data.selectList.erase(this.json);
  796. if (this.view.json.data.calculate) if (this.view.json.data.calculate.calculateList) this.view.json.data.calculate.calculateList.erase(this.json);
  797. this.view.items.erase(this);
  798. if (this.view.property) this.view.property.loadStatColumnSelect();
  799. this.areaNode.destroy();
  800. this.view.selected();
  801. this.view.setViewWidth();
  802. MWF.release(this);
  803. delete this;
  804. },
  805. addColumn: function(e, data){
  806. MWF.require("MWF.widget.UUID", function(){
  807. var json;
  808. if (data){
  809. json = Object.clone(data);
  810. json.id = (new MWF.widget.UUID).id;
  811. json.column = (new MWF.widget.UUID).id;
  812. }else{
  813. var id = (new MWF.widget.UUID).id;
  814. json = {
  815. "id": id,
  816. "column": "",
  817. "displayName": this.view.designer.lp.unnamed,
  818. "calculateType": "sum",
  819. "orderType": "original",
  820. "orderEffectType": "key"
  821. };
  822. }
  823. var idx = this.view.json.data.calculate.calculateList.indexOf(this.json);
  824. this.view.json.data.calculate.calculateList.splice(idx, 0, json);
  825. var column = new MWF.xApplication.query.StatDesigner.Stat.Column(json, this.view, this);
  826. this.view.items.splice(idx, 0, column);
  827. column.selected();
  828. if (this.view.property) this.view.property.loadStatColumnSelect();
  829. if (this.view.viewContentTableNode){
  830. var trs = this.view.viewContentTableNode.getElements("tr");
  831. trs.each(function(tr){
  832. var td = tr.insertCell(idx);
  833. td.setStyles(this.css.viewContentTdNode);
  834. }.bind(this));
  835. }
  836. this.view.setViewWidth();
  837. }.bind(this));
  838. },
  839. move: function(e){
  840. var columnNodes = [];
  841. this.view.items.each(function(item){
  842. if (item!=this){
  843. columnNodes.push(item.areaNode);
  844. }
  845. }.bind(this));
  846. this._createMoveNode();
  847. this._setNodeMove(columnNodes, e);
  848. },
  849. _createMoveNode: function(){
  850. this.moveNode = new Element("div", {"text": this.node.get("text")});
  851. this.moveNode.inject(this.view.designer.content);
  852. this.moveNode.setStyles({
  853. "border": "2px dashed #ffa200",
  854. "opacity": 0.7,
  855. "height": "30px",
  856. "line-height": "30px",
  857. "padding": "0px 10px",
  858. "position": "absolute"
  859. });
  860. },
  861. _setMoveNodePosition: function(e){
  862. var x = e.page.x+2;
  863. var y = e.page.y+2;
  864. this.moveNode.positionTo(x, y);
  865. },
  866. createMoveFlagNode: function(){
  867. this.moveFlagNode = new Element("td", {"styles": this.css.moveFlagNode});
  868. },
  869. _setNodeMove: function(droppables, e){
  870. this._setMoveNodePosition(e);
  871. var movePosition = this.moveNode.getPosition();
  872. var moveSize = this.moveNode.getSize();
  873. var contentPosition = this.content.getPosition();
  874. var contentSize = this.content.getSize();
  875. var nodeDrag = new Drag.Move(this.moveNode, {
  876. "droppables": droppables,
  877. "limit": {
  878. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  879. "y": [movePosition.y, movePosition.y+moveSize.y]
  880. },
  881. "onEnter": function(dragging, inObj){
  882. if (!this.moveFlagNode) this.createMoveFlagNode();
  883. this.moveFlagNode.inject(inObj, "before");
  884. }.bind(this),
  885. "onLeave": function(dragging, inObj){
  886. if (this.moveFlagNode){
  887. this.moveFlagNode.dispose();
  888. }
  889. }.bind(this),
  890. "onDrop": function(dragging, inObj){
  891. if (inObj){
  892. this.areaNode.inject(inObj, "before");
  893. var column = inObj.retrieve("column");
  894. this.listNode.inject(column.listNode, "before");
  895. var idx = this.view.json.data.calculate.calculateList.indexOf(column.json);
  896. this.view.json.data.calculate.calculateList.erase(this.json);
  897. this.view.items.erase(this);
  898. this.view.json.data.calculate.calculateList.splice(idx, 0, this.json);
  899. this.view.items.splice(idx, 0, this);
  900. if (this.moveNode) this.moveNode.destroy();
  901. if (this.moveFlagNode) this.moveFlagNode.destroy();
  902. this._setActionAreaPosition();
  903. }else{
  904. if (this.moveNode) this.moveNode.destroy();
  905. if (this.moveFlagNode) this.moveFlagNode.destroy();
  906. }
  907. }.bind(this),
  908. "onCancel": function(dragging){
  909. if (this.moveNode) this.moveNode.destroy();
  910. if (this.moveFlagNode) this.moveFlagNode.destroy();
  911. }.bind(this)
  912. });
  913. nodeDrag.start(e);
  914. },
  915. changeViewSelected: function(json){
  916. if (json){
  917. this.changeViewColumnOptions(json);
  918. }else{
  919. if (this.json.view){
  920. if (!this.queryView){
  921. this.view.designer.actions.getView(this.json.view, function(view){
  922. this.queryView = JSON.decode(view.data.data);
  923. this.changeViewColumnOptions(this.queryView);
  924. }.bind(this));
  925. }else{
  926. this.changeViewColumnOptions(this.queryView);
  927. }
  928. }else{
  929. this.changeViewColumnOptions(json);
  930. }
  931. }
  932. },
  933. changeViewColumnOptions: function(json){
  934. if (this.property){
  935. var nodes = this.property.propertyContent.getElements(".MWFViewColumnSelect");
  936. nodes.each(function(node){
  937. node.empty();
  938. if (json){
  939. new Element("option", {
  940. "value": "",
  941. "text": "(none)",
  942. "selected": (!this.json.column)
  943. }).inject(node);
  944. json.selectList.each(function(col){
  945. var o = new Element("option", {
  946. "value": col.column,
  947. "text": col.displayName,
  948. "selected": (col.column==this.json.column)
  949. }).inject(node);
  950. }.bind(this));
  951. }else{
  952. this.json.column = "";
  953. }
  954. }.bind(this));
  955. }
  956. },
  957. checkColumn: function(){
  958. var flag = true;
  959. if (!this.queryView){
  960. if (this.json.view){
  961. this.view.designer.actions.getView(this.json.view, function(view){
  962. this.queryView = JSON.decode(view.data.data);
  963. }.bind(this), null, false);
  964. }else{
  965. this.errorMark();
  966. return false;
  967. }
  968. }
  969. var col = this.queryView.selectList.filter(function(c){
  970. return (c.column==this.json.column);
  971. }.bind(this));
  972. if (!col.length){
  973. this.errorMark();
  974. flag = false;
  975. }else{
  976. this.errorMark(true);
  977. }
  978. return flag;
  979. },
  980. errorMark: function(flag){
  981. if (flag){
  982. this.isError = false;
  983. if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode);
  984. }else{
  985. this.isError = true;
  986. if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_error);
  987. }
  988. }
  989. });