Table.js 27 KB

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