Table.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class Table 表格组件。
  3. * @example
  4. * //可以在脚本中获取该组件
  5. * //方法1:
  6. * var table = this.form.get("fieldId"); //获取组件
  7. * //方法2
  8. * var table = this.target; //在组件本身的脚本中获取
  9. * @extends MWF.xApplication.process.Xform.$Module
  10. * @category FormComponents
  11. * @hideconstructor
  12. */
  13. MWF.xApplication.process.Xform.Table = MWF.APPTable = new Class(
  14. /** @lends MWF.xApplication.process.Xform.Table# */
  15. {
  16. Extends: MWF.APP$Module,
  17. _afterLoaded: function(){
  18. /**
  19. * @summary table,DOM对象
  20. * @member {Element} table
  21. * @memberOf MWF.xApplication.process.Xform.Table#
  22. * @example
  23. * //可以在脚本中获取该组件
  24. * var table = this.form.get("fieldId").table; //获取组件对象
  25. */
  26. if (!this.table) this.table = this.node.getElement("table");
  27. //var tds = this.node.getElements("td");
  28. var rows = this.table.rows;
  29. for (var i=0; i<rows.length; i++){
  30. var row = rows[i];
  31. for (var j=0; j<row.cells.length; j++){
  32. var td = row.cells[j];
  33. var json = this.form._getDomjson(td);
  34. if (json){
  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. }
  42. }
  43. // this.table.rows.each(function(row){
  44. // row.cells.each(function(td){
  45. // var json = this.form._getDomjson(td);
  46. // var table = this;
  47. // var module = this.form._loadModule(json, td, function(){
  48. // this.table = table;
  49. // });
  50. //
  51. // this.form.modules.push(module);
  52. // }.bind(this));
  53. // }.bind(this));
  54. // tds.each(function(td){
  55. // var json = this.form._getDomjson(td);
  56. // var table = this;
  57. // var module = this.form._loadModule(json, td, function(){
  58. // this.table = table;
  59. // });
  60. //
  61. // this.form.modules.push(module);
  62. // }.bind(this));
  63. },
  64. _loadBorderStyle: function(){
  65. if (this.json.styles && this.json.styles.border){
  66. if (!this.table) this.table = this.node.getElement("table");
  67. if( this.json.styles["table-layout"] ){
  68. this.table.setStyle("table-layout",this.json.styles["table-layout"]);
  69. }
  70. this.table.set("cellspacing", "0");
  71. this.table.setStyles({
  72. "border-top": this.json.styles.border,
  73. "border-left": this.json.styles.border
  74. });
  75. var ths = this.table.getElements("th");
  76. ths.setStyles({
  77. "border-bottom": this.json.styles.border,
  78. "border-right": this.json.styles.border
  79. });
  80. var tds = this.table.getElements("td");
  81. tds.setStyles({
  82. "border-bottom": this.json.styles.border,
  83. "border-right": this.json.styles.border,
  84. //"background": "transparent"
  85. });
  86. }
  87. },
  88. _loadStyles: function(){
  89. Object.each(this.json.styles, function(value, key){
  90. var reg = /^border\w*/ig;
  91. if (!key.test(reg)){
  92. this.node.setStyle(key, value);
  93. }
  94. }.bind(this));
  95. if (this.form.json["$version"]!=="5.2") this._loadBorderStyle();
  96. }
  97. });
  98. /** @class Table$Td 单元格组件。
  99. * @example
  100. * //可以在脚本中获取该组件
  101. * //方法1:
  102. * var td = this.form.get("fieldId"); //获取组件
  103. * //方法2
  104. * var td = this.target; //在组件本身的脚本中获取
  105. * @extends MWF.xApplication.process.Xform.$Module
  106. * @category FormComponents
  107. * @hideconstructor
  108. */
  109. MWF.xApplication.process.Xform.Table$Td = MWF.APPTable$Td = new Class({
  110. Extends: MWF.APP$Module,
  111. _queryLoaded: function(){
  112. },
  113. _afterLoaded: function(){
  114. //this.form._loadModules(this.node);
  115. },
  116. _loadStyles: function(){
  117. var addStyles = {};
  118. if (this.json.cellType=="title"){
  119. addStyles = this.table.json.titleTdStyles;
  120. }
  121. if (this.json.cellType=="content"){
  122. addStyles = this.table.json.contentTdStyles;
  123. }
  124. if (this.json.cellType=="layout"){
  125. addStyles = this.table.json.layoutTdStyles;
  126. }
  127. Object.each(addStyles, function(value, key){
  128. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  129. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  130. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  131. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  132. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  133. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  134. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  135. }
  136. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  137. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  138. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  139. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  140. }
  141. value = o2.filterUrl(value);
  142. this.node.setStyle(key, value);
  143. }else{
  144. if (!this.json.preprocessing) this.node.setStyle(key, value);
  145. }
  146. }.bind(this));
  147. Object.each(this.json.styles, function(value, key){
  148. if ((value.indexOf("x_processplatform_assemble_surface")!==-1 || value.indexOf("x_portal_assemble_surface")!==-1)){
  149. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  150. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  151. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  152. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  153. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  154. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  155. }
  156. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  157. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  158. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  159. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  160. }
  161. value = o2.filterUrl(value);
  162. }
  163. this.node.setStyle(key, value);
  164. }.bind(this));
  165. if (this.json.cellType=="content"){
  166. this.form.addEvent("postLoad", function(){
  167. var inputs = this.node.getElements("input");
  168. inputs.each(function(input){
  169. var inputType = input.get("type").toLowerCase();
  170. if (inputType!="radio" && inputType!="checkbox" && inputType!="submit" && inputType!="buttom" && inputType!="image"){
  171. input.setStyle("width", "100%");
  172. }
  173. }.bind(this));
  174. var textareas = this.node.getElements("textarea");
  175. textareas.each(function(textarea){
  176. textarea.setStyle("width", "100%");
  177. }.bind(this));
  178. }.bind(this))
  179. }
  180. }
  181. });