Table.js 8.7 KB

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