Chris@0
|
1 /**
|
Chris@0
|
2 * @file
|
Chris@0
|
3 * Simpletest behaviors.
|
Chris@0
|
4 */
|
Chris@0
|
5
|
Chris@17
|
6 (function($, Drupal, drupalSettings) {
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Collapses table rows followed by group rows on the test listing page.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @type {Drupal~behavior}
|
Chris@0
|
11 *
|
Chris@0
|
12 * @prop {Drupal~behaviorAttach} attach
|
Chris@0
|
13 * Attach collapse behavior on the test listing page.
|
Chris@0
|
14 */
|
Chris@0
|
15 Drupal.behaviors.simpleTestGroupCollapse = {
|
Chris@0
|
16 attach(context) {
|
Chris@17
|
17 $(context)
|
Chris@17
|
18 .find('.simpletest-group')
|
Chris@17
|
19 .once('simpletest-group-collapse')
|
Chris@17
|
20 .each(function() {
|
Chris@17
|
21 const $group = $(this);
|
Chris@17
|
22 const $image = $group.find('.simpletest-image');
|
Chris@17
|
23 $image.html(drupalSettings.simpleTest.images[0]).on('click', () => {
|
Chris@0
|
24 const $tests = $group.nextUntil('.simpletest-group');
|
Chris@0
|
25 const expand = !$group.hasClass('expanded');
|
Chris@0
|
26 $group.toggleClass('expanded', expand);
|
Chris@0
|
27 $tests.toggleClass('js-hide', !expand);
|
Chris@0
|
28 $image.html(drupalSettings.simpleTest.images[+expand]);
|
Chris@0
|
29 });
|
Chris@17
|
30 });
|
Chris@0
|
31 },
|
Chris@0
|
32 };
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Toggles test checkboxes to match the group checkbox.
|
Chris@0
|
36 *
|
Chris@0
|
37 * @type {Drupal~behavior}
|
Chris@0
|
38 *
|
Chris@0
|
39 * @prop {Drupal~behaviorAttach} attach
|
Chris@0
|
40 * Attaches behavior for selecting all tests in a group.
|
Chris@0
|
41 */
|
Chris@0
|
42 Drupal.behaviors.simpleTestSelectAll = {
|
Chris@0
|
43 attach(context) {
|
Chris@17
|
44 $(context)
|
Chris@17
|
45 .find('.simpletest-group')
|
Chris@17
|
46 .once('simpletest-group-select-all')
|
Chris@17
|
47 .each(function() {
|
Chris@17
|
48 const $group = $(this);
|
Chris@17
|
49 const $cell = $group.find('.simpletest-group-select-all');
|
Chris@17
|
50 const $groupCheckbox = $(
|
Chris@17
|
51 `<input type="checkbox" id="${$cell.attr(
|
Chris@17
|
52 'id',
|
Chris@17
|
53 )}-group-select-all" class="form-checkbox" />`,
|
Chris@17
|
54 );
|
Chris@17
|
55 const $testCheckboxes = $group
|
Chris@17
|
56 .nextUntil('.simpletest-group')
|
Chris@17
|
57 .find('input[type=checkbox]');
|
Chris@17
|
58 $cell.append($groupCheckbox);
|
Chris@0
|
59
|
Chris@17
|
60 // Toggle the test checkboxes when the group checkbox is toggled.
|
Chris@17
|
61 $groupCheckbox.on('change', function() {
|
Chris@17
|
62 const checked = $(this).prop('checked');
|
Chris@17
|
63 $testCheckboxes.prop('checked', checked);
|
Chris@17
|
64 });
|
Chris@17
|
65
|
Chris@17
|
66 // Update the group checkbox when a test checkbox is toggled.
|
Chris@17
|
67 function updateGroupCheckbox() {
|
Chris@17
|
68 let allChecked = true;
|
Chris@17
|
69 $testCheckboxes.each(function() {
|
Chris@17
|
70 if (!$(this).prop('checked')) {
|
Chris@17
|
71 allChecked = false;
|
Chris@17
|
72 return false;
|
Chris@17
|
73 }
|
Chris@17
|
74 });
|
Chris@17
|
75 $groupCheckbox.prop('checked', allChecked);
|
Chris@17
|
76 }
|
Chris@17
|
77
|
Chris@17
|
78 $testCheckboxes.on('change', updateGroupCheckbox);
|
Chris@0
|
79 });
|
Chris@0
|
80 },
|
Chris@0
|
81 };
|
Chris@0
|
82
|
Chris@0
|
83 /**
|
Chris@0
|
84 * Filters the test list table by a text input search string.
|
Chris@0
|
85 *
|
Chris@0
|
86 * Text search input: input.table-filter-text
|
Chris@0
|
87 * Target table: input.table-filter-text[data-table]
|
Chris@0
|
88 * Source text: .table-filter-text-source
|
Chris@0
|
89 *
|
Chris@0
|
90 * @type {Drupal~behavior}
|
Chris@0
|
91 *
|
Chris@0
|
92 * @prop {Drupal~behaviorAttach} attach
|
Chris@0
|
93 * Attaches the filter behavior to the text input element.
|
Chris@0
|
94 */
|
Chris@0
|
95 Drupal.behaviors.simpletestTableFilterByText = {
|
Chris@0
|
96 attach(context) {
|
Chris@0
|
97 const $input = $('input.table-filter-text').once('table-filter-text');
|
Chris@0
|
98 const $table = $($input.attr('data-table'));
|
Chris@0
|
99 let $rows;
|
Chris@0
|
100 let searched = false;
|
Chris@0
|
101
|
Chris@0
|
102 function filterTestList(e) {
|
Chris@17
|
103 const query = $(e.target)
|
Chris@17
|
104 .val()
|
Chris@17
|
105 .toLowerCase();
|
Chris@0
|
106
|
Chris@0
|
107 function showTestRow(index, row) {
|
Chris@0
|
108 const $row = $(row);
|
Chris@0
|
109 const $sources = $row.find('.table-filter-text-source');
|
Chris@17
|
110 const textMatch =
|
Chris@17
|
111 $sources
|
Chris@17
|
112 .text()
|
Chris@17
|
113 .toLowerCase()
|
Chris@17
|
114 .indexOf(query) !== -1;
|
Chris@0
|
115 $row.closest('tr').toggle(textMatch);
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@0
|
118 // Filter if the length of the query is at least 3 characters.
|
Chris@0
|
119 if (query.length >= 3) {
|
Chris@0
|
120 // Indicate that a search has been performed, and hide the
|
Chris@0
|
121 // "select all" checkbox.
|
Chris@0
|
122 searched = true;
|
Chris@0
|
123 $('#simpletest-form-table thead th.select-all input').hide();
|
Chris@0
|
124
|
Chris@0
|
125 $rows.each(showTestRow);
|
Chris@0
|
126 }
|
Chris@0
|
127 // Restore to the original state if any searching has occurred.
|
Chris@0
|
128 else if (searched) {
|
Chris@0
|
129 searched = false;
|
Chris@0
|
130 $('#simpletest-form-table thead th.select-all input').show();
|
Chris@0
|
131 // Restore all rows to their original display state.
|
Chris@0
|
132 $rows.css('display', '');
|
Chris@0
|
133 }
|
Chris@0
|
134 }
|
Chris@0
|
135
|
Chris@0
|
136 if ($table.length) {
|
Chris@0
|
137 $rows = $table.find('tbody tr');
|
Chris@17
|
138 $input
|
Chris@17
|
139 .trigger('focus')
|
Chris@17
|
140 .on('keyup', Drupal.debounce(filterTestList, 200));
|
Chris@0
|
141 }
|
Chris@0
|
142 },
|
Chris@0
|
143 };
|
Chris@17
|
144 })(jQuery, Drupal, drupalSettings);
|