groupcase.ui.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. let initialOptions = {};
  2. $(function()
  3. {
  4. const options = zui.evalValue($('[zui-create-dtable]').attr('zui-create-dtable'));
  5. initialOptions = $.extend(true, {}, options);
  6. });
  7. /**
  8. * 需求列显示展开收起的图标。
  9. * Display show icon in the story column.
  10. *
  11. * @param object result
  12. * @param object info
  13. * @access public
  14. * @return object
  15. */
  16. window.onRenderCell = function(result, {row, col})
  17. {
  18. if(result && col.name == 'storyTitle')
  19. {
  20. if(row.data.hidden)
  21. {
  22. result.unshift({html: '<a class="dtable-nested-toggle state" data-on="click" data-story=' + row.data.story + ' data-call="deformation" data-params="event")><span class="toggle-icon is-collapsed"></span></a>'});
  23. }
  24. else
  25. {
  26. result.unshift({html: '<a class="dtable-nested-toggle state" data-on="click" data-story=' + row.data.story + ' data-call="deformation" data-params="event")><span class="toggle-icon is-expanded"></span></a>'});
  27. result.push({outer: false, style: {alignItems: 'start', 'padding-top': '8px'}})
  28. }
  29. }
  30. if(result && col.name == 'id' && row.data.hidden)
  31. {
  32. result.push({outer: false, style: {alignItems: 'center', justifyContent: 'start'}})
  33. }
  34. return result;
  35. }
  36. /**
  37. * 需求列合并单元格。
  38. * cell span in the story column.
  39. *
  40. * @param object cell
  41. * @access public
  42. * @return object
  43. */
  44. window.getCellSpan = function(cell)
  45. {
  46. if(cell.col.name == 'storyTitle' && cell.row.data.rowspan)
  47. {
  48. return {rowSpan: cell.row.data.rowspan};
  49. }
  50. if(cell.col.name == 'id' && cell.row.data.colspan)
  51. {
  52. return {colSpan: cell.row.data.colspan};
  53. }
  54. }
  55. window.deformation = function(event)
  56. {
  57. let newData = [];
  58. const options = zui.DTable.query().options;
  59. const story = $(event.target).closest('a').data('story');
  60. const oldOptions = $.extend(true, {}, initialOptions);
  61. if($(event.target).closest('a').find('span').hasClass('is-collapsed'))
  62. {
  63. $.each(options.data, function(index)
  64. {
  65. if(!options.data[index]) return;
  66. if(options.data[index].story == story)
  67. {
  68. $.each(oldOptions.data, function(key)
  69. {
  70. if(!oldOptions.data[key]) return;
  71. if(oldOptions.data[key].story == story) newData.push(oldOptions.data[key]);
  72. });
  73. }
  74. else
  75. {
  76. newData.push(options.data[index]);
  77. }
  78. });
  79. options.data = newData;
  80. $(event.target).closest('a').find('span').removeClass('is-collapsed').addClass('is-expanded');
  81. $('#groupCaseTable').zui('dtable').render(options);
  82. }
  83. else
  84. {
  85. options.data = options.data.filter(function(option)
  86. {
  87. return option.story != story || option.rowspan != 0;
  88. });
  89. $.each(options.data, function(index)
  90. {
  91. if(options.data[index] && options.data[index].story == story)
  92. {
  93. options.data[index].id = {html: '<span class="text-gray">' + allTestcases + ' ' + '<strong>' + options.data[index].rowspan + '</strong></span>'};
  94. options.data[index].rowspan = 1;
  95. options.data[index].colspan = 12;
  96. options.data[index].hidden = 1;
  97. }
  98. });
  99. $(event.target).closest('a').find('span').removeClass('is-expanded').addClass('is-collapsed');
  100. $('#groupCaseTable').zui('dtable').render();
  101. }
  102. }