Table.js 7.9 KB

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