Table.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Table = MWF.APPTable = new Class({
  3. Extends: MWF.APP$Module,
  4. _afterLoaded: function(){
  5. if (!this.table) this.table = this.node.getElement("table");
  6. //var tds = this.node.getElements("td");
  7. var rows = this.table.rows;
  8. for (var i=0; i<rows.length; i++){
  9. var row = rows[i];
  10. for (var j=0; j<row.cells.length; j++){
  11. var td = row.cells[j];
  12. var json = this.form._getDomjson(td);
  13. if (json){
  14. var table = this;
  15. var module = this.form._loadModule(json, td, function(){
  16. this.table = table;
  17. });
  18. }
  19. this.form.modules.push(module);
  20. }
  21. }
  22. // this.table.rows.each(function(row){
  23. // row.cells.each(function(td){
  24. // var json = this.form._getDomjson(td);
  25. // var table = this;
  26. // var module = this.form._loadModule(json, td, function(){
  27. // this.table = table;
  28. // });
  29. //
  30. // this.form.modules.push(module);
  31. // }.bind(this));
  32. // }.bind(this));
  33. // tds.each(function(td){
  34. // var json = this.form._getDomjson(td);
  35. // var table = this;
  36. // var module = this.form._loadModule(json, td, function(){
  37. // this.table = table;
  38. // });
  39. //
  40. // this.form.modules.push(module);
  41. // }.bind(this));
  42. },
  43. _loadBorderStyle: function(){
  44. if (this.json.styles.border){
  45. if (!this.table) this.table = this.node.getElement("table");
  46. if( this.json.styles["table-layout"] ){
  47. this.table.setStyle("table-layout",this.json.styles["table-layout"]);
  48. }
  49. this.table.set("cellspacing", "0");
  50. this.table.setStyles({
  51. "border-top": this.json.styles.border,
  52. "border-left": this.json.styles.border
  53. });
  54. var ths = this.table.getElements("th");
  55. ths.setStyles({
  56. "border-bottom": this.json.styles.border,
  57. "border-right": this.json.styles.border
  58. });
  59. var tds = this.table.getElements("td");
  60. tds.setStyles({
  61. "border-bottom": this.json.styles.border,
  62. "border-right": this.json.styles.border,
  63. "background": "transparent"
  64. });
  65. }
  66. },
  67. _loadStyles: function(){
  68. Object.each(this.json.styles, function(value, key){
  69. var reg = /^border\w*/ig;
  70. if (!key.test(reg)){
  71. this.node.setStyle(key, value);
  72. }
  73. }.bind(this));
  74. this._loadBorderStyle();
  75. }
  76. });
  77. MWF.xApplication.process.Xform.Table$Td = MWF.APPTable$Td = new Class({
  78. Extends: MWF.APP$Module,
  79. _queryLoaded: function(){
  80. },
  81. _afterLoaded: function(){
  82. //this.form._loadModules(this.node);
  83. },
  84. _loadStyles: function(){
  85. var addStyles = {};
  86. if (this.json.cellType=="title"){
  87. addStyles = this.table.json.titleTdStyles
  88. }
  89. if (this.json.cellType=="content"){
  90. addStyles = this.table.json.contentTdStyles
  91. }
  92. if (this.json.cellType=="layout"){
  93. addStyles = this.table.json.layoutTdStyles
  94. }
  95. this.node.setStyles(addStyles);
  96. this.node.setStyles(this.json.styles);
  97. if (this.json.cellType=="content"){
  98. this.form.addEvent("postLoad", function(){
  99. var inputs = this.node.getElements("input");
  100. inputs.each(function(input){
  101. var inputType = input.get("type").toLowerCase();
  102. if (inputType!="radio" && inputType!="checkbox" && inputType!="submit" && inputType!="buttom" && inputType!="image"){
  103. input.setStyle("width", "100%");
  104. }
  105. }.bind(this));
  106. var textareas = this.node.getElements("textarea");
  107. textareas.each(function(textarea){
  108. textarea.setStyle("width", "100%");
  109. }.bind(this));
  110. }.bind(this))
  111. }
  112. }
  113. });