AttributeRow.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Created by Jacky.gao on 2016/9/18.
  3. */
  4. import AttributeCell from './AttributeCell.js';
  5. import Row from './Row.js';
  6. import ConditionRow from './ConditionRow.js';
  7. import CustomCell from './CustomCell.js';
  8. export default class AttributeRow extends Row{
  9. constructor(table,rowData){
  10. super(table);
  11. this.rowData=rowData;
  12. this.conditionRows=[];
  13. this.tr=$(`<tr style="min-height: 25px"></tr>`);
  14. this.tr.append(this.newAttributeCell());
  15. this.tr.append(this.newConditionCell());
  16. this.tr.append(this.newScoreCell());
  17. this.initCustomCells();
  18. }
  19. addCustomCol(customCol){
  20. const cell=new CustomCell(this,customCol);
  21. this.tr.append(cell.td);
  22. customCol.customCells.push(cell);
  23. for(let row of this.conditionRows){
  24. row.addCustomCol(customCol);
  25. }
  26. }
  27. removeCustomCol(customCol){
  28. let posArray=[];
  29. for(let i=0;i<this.cells.length;i++){
  30. let cell=this.cells[i];
  31. if(cell.col===customCol){
  32. posArray.push(i);
  33. }
  34. }
  35. for(let pos of posArray){
  36. this.cells.splice(pos,1);
  37. }
  38. for(let row of this.conditionRows){
  39. row.removeCustomCol(customCol);
  40. }
  41. }
  42. initConditionRows(rowData){
  43. if(!rowData)return;
  44. const conditionRows=rowData.conditionRows || [];
  45. for(let conditionRowData of conditionRows){
  46. this.addConditionRow(conditionRowData);
  47. }
  48. }
  49. newAttributeCell() {
  50. let cellData=null;
  51. if(this.rowData){
  52. cellData=this.scoreCardTable.getCell(this.rowData.rowNumber,1);
  53. }
  54. this.attributeCell = new AttributeCell(this,this.scoreCardTable.attributeCol,cellData);
  55. return this.attributeCell.td;
  56. }
  57. remove(){
  58. const pos=this.scoreCardTable.attributeRows.indexOf(this);
  59. this.scoreCardTable.attributeRows.splice(pos,1);
  60. for(let row of this.conditionRows){
  61. row.tr.remove();
  62. }
  63. this.tr.remove();
  64. }
  65. removeConditionRow(conditionRow){
  66. const pos=this.conditionRows.indexOf(conditionRow);
  67. this.conditionRows.splice(pos,1);
  68. let rowSpan=this.attributeCell.td.prop("rowspan");
  69. if(!rowSpan){
  70. rowSpan=0;
  71. }else{
  72. rowSpan=parseInt(rowSpan)-1;
  73. }
  74. this.attributeCell.td.prop("rowspan",rowSpan);
  75. conditionRow.tr.remove();
  76. }
  77. addConditionRow(conditionRowData){
  78. const newConditionRow=new ConditionRow(this.scoreCardTable,this,conditionRowData);
  79. let rowSpan=this.attributeCell.td.prop("rowspan");
  80. if(!rowSpan){
  81. rowSpan=2;
  82. }else{
  83. rowSpan=parseInt(rowSpan)+1;
  84. }
  85. this.attributeCell.td.prop("rowspan",rowSpan);
  86. if(this.conditionRows.length>0){
  87. this.conditionRows[this.conditionRows.length-1].tr.after(newConditionRow.tr);
  88. }else{
  89. this.tr.after(newConditionRow.tr);
  90. }
  91. this.conditionRows.push(newConditionRow);
  92. }
  93. toXml(){
  94. let xml="<attribute-row row-number=\""+this.getRowNumber()+"\">";
  95. for(let row of this.conditionRows){
  96. xml+=row.toXml();
  97. }
  98. xml+="</attribute-row>";
  99. return xml;
  100. }
  101. }