Table.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. this.table.set("cellspacing", "0");
  47. this.table.setStyles({
  48. "border-top": this.json.styles.border,
  49. "border-left": this.json.styles.border
  50. });
  51. var ths = this.table.getElements("th");
  52. ths.setStyles({
  53. "border-bottom": this.json.styles.border,
  54. "border-right": this.json.styles.border
  55. });
  56. var tds = this.table.getElements("td");
  57. tds.setStyles({
  58. "border-bottom": this.json.styles.border,
  59. "border-right": this.json.styles.border,
  60. "background": "transparent"
  61. });
  62. }
  63. },
  64. _loadStyles: function(){
  65. Object.each(this.json.styles, function(value, key){
  66. var reg = /^border\w*/ig;
  67. if (!key.test(reg)){
  68. this.node.setStyle(key, value);
  69. }
  70. }.bind(this));
  71. this._loadBorderStyle();
  72. }
  73. });
  74. MWF.xApplication.process.Xform.Table$Td = MWF.APPTable$Td = new Class({
  75. Extends: MWF.APP$Module,
  76. _queryLoaded: function(){
  77. },
  78. _afterLoaded: function(){
  79. //this.form._loadModules(this.node);
  80. },
  81. _loadStyles: function(){
  82. var addStyles = {};
  83. if (this.json.cellType=="title"){
  84. addStyles = this.table.json.titleTdStyles
  85. }
  86. if (this.json.cellType=="content"){
  87. addStyles = this.table.json.contentTdStyles
  88. }
  89. if (this.json.cellType=="layout"){
  90. addStyles = this.table.json.layoutTdStyles
  91. }
  92. this.node.setStyles(addStyles);
  93. this.node.setStyles(this.json.styles);
  94. if (this.json.cellType=="content"){
  95. this.form.addEvent("postLoad", function(){
  96. var inputs = this.node.getElements("input");
  97. inputs.each(function(input){
  98. var inputType = input.get("type").toLowerCase();
  99. if (inputType!="radio" && inputType!="checkbox" && inputType!="submit" && inputType!="buttom" && inputType!="image"){
  100. input.setStyle("width", "100%");
  101. }
  102. }.bind(this));
  103. var textareas = this.node.getElements("textarea");
  104. textareas.each(function(textarea){
  105. textarea.setStyle("width", "100%");
  106. }.bind(this));
  107. }.bind(this))
  108. }
  109. }
  110. });