Table.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 && 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. if (this.form.json["$version"]!=="5.2") 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. Object.each(addStyles, function(value, key){
  96. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  97. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  98. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  99. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  100. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  101. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  102. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  103. }
  104. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  105. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  106. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  107. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  108. }
  109. this.node.setStyle(key, value);
  110. }else{
  111. if (!this.json.preprocessing) this.node.setStyle(key, value);
  112. }
  113. }.bind(this));
  114. Object.each(this.json.styles, function(value, key){
  115. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  116. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  117. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  118. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  119. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  120. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  121. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  122. }
  123. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  124. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  125. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  126. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  127. }
  128. }
  129. this.node.setStyle(key, value);
  130. }.bind(this));
  131. if (this.json.cellType=="content"){
  132. this.form.addEvent("postLoad", function(){
  133. var inputs = this.node.getElements("input");
  134. inputs.each(function(input){
  135. var inputType = input.get("type").toLowerCase();
  136. if (inputType!="radio" && inputType!="checkbox" && inputType!="submit" && inputType!="buttom" && inputType!="image"){
  137. input.setStyle("width", "100%");
  138. }
  139. }.bind(this));
  140. var textareas = this.node.getElements("textarea");
  141. textareas.each(function(textarea){
  142. textarea.setStyle("width", "100%");
  143. }.bind(this));
  144. }.bind(this))
  145. }
  146. }
  147. });