groupcase.ui.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 == 'caseID' && row.data.hidden) result.push({outer: false, style: {alignItems: 'center', justifyContent: 'start'}})
  31. return result;
  32. }
  33. /**
  34. * 需求列合并单元格。
  35. * cell span in the story column.
  36. *
  37. * @param object cell
  38. * @access public
  39. * @return object
  40. */
  41. window.getCellSpan = function(cell)
  42. {
  43. if(cell.col.name == 'storyTitle' && cell.row.data.rowspan) return {rowSpan: cell.row.data.rowspan};
  44. if(cell.col.name == 'caseID' && cell.row.data.colspan) return {colSpan: cell.row.data.colspan};
  45. }
  46. window.deformation = function(event)
  47. {
  48. let newData = [];
  49. const options = zui.DTable.query().options;
  50. const story = $(event.target).closest('a').data('story');
  51. const oldOptions = $.extend(true, {}, initialOptions);
  52. if($(event.target).closest('a').find('span').hasClass('is-collapsed'))
  53. {
  54. $.each(options.data, function(index)
  55. {
  56. if(!options.data[index]) return;
  57. if(options.data[index].story == story)
  58. {
  59. $.each(oldOptions.data, function(key)
  60. {
  61. if(!oldOptions.data[key]) return;
  62. if(oldOptions.data[key].story == story) newData.push(oldOptions.data[key]);
  63. });
  64. }
  65. else
  66. {
  67. newData.push(options.data[index]);
  68. }
  69. });
  70. options.data = newData;
  71. $(event.target).closest('a').find('span').removeClass('is-collapsed').addClass('is-expanded');
  72. $('#groupCaseTable').zui('dtable').render(options);
  73. }
  74. else
  75. {
  76. options.data = options.data.filter(function(option){ return option.story != story || option.rowspan != 0; });
  77. $.each(options.data, function(index)
  78. {
  79. if(options.data[index] && options.data[index].story == story)
  80. {
  81. options.data[index].caseID = {html: '<span class="text-gray">' + allTestcases + ' ' + '<strong>' + options.data[index].rowspan + '</strong></span>'};
  82. options.data[index].rowspan = 1;
  83. options.data[index].colspan = 12;
  84. options.data[index].hidden = 1;
  85. }
  86. });
  87. $(event.target).closest('a').find('span').removeClass('is-expanded').addClass('is-collapsed');
  88. $('#groupCaseTable').zui('dtable').render();
  89. }
  90. }