Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5dfe4be

Browse files
committedJun 18, 2023
Added autocomplete input field for assigning bulk default user
Closes #2510
1 parent 0a179f7 commit 5dfe4be

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed
 

‎tcms/static/js/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ $(() => {
8888
window.markdownEditor = initSimpleMDE(this, uploadField)
8989
})
9090

91+
$('.dropdown.dropdown-keep-open').on('hide.bs.dropdown', function (ev) {
92+
// Disable automatic closing of dropdown menu.
93+
// This is required for using typeahead fields in submenu options.
94+
return false
95+
})
96+
97+
$(document).on('click', function (ev) {
98+
if (!$(ev.target).parents('.dropdown.dropdown-keep-open').length) {
99+
// The target is not inside the dropdown element.
100+
// Close open dropdowns
101+
$('.dropdown.dropdown-keep-open.open').removeClass('open')
102+
}
103+
})
104+
91105
// for debugging in browser
92106
window.jsonRPC = jsonRPC
93107
})

‎tcms/testplans/static/testplans/js/get.js

+40-4
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,52 @@ function toolbarEvents (testPlanId, permissions) {
539539
return false
540540
})
541541

542-
$('#default-tester-button').click(function (ev) {
543-
$(this).parents('.dropdown').toggleClass('open')
542+
$('input.user-field.typeahead').on('focusin', function () {
543+
// Prevents sub-menu options from hidding when
544+
// selecting typeahead suggestion.
545+
$(this).parents('ul').css('display', 'block')
546+
})
547+
548+
$('input.user-field.typeahead').typeahead({
549+
minLength: 3,
550+
highlight: true
551+
}, {
552+
name: 'default-tester-autocomplete',
553+
// will display up to X results even if more were returned
554+
limit: 100,
555+
async: true,
556+
display: function (element) {
557+
return element.username
558+
},
559+
source: function (query, processSync, processAsync) {
560+
jsonRPC('User.filter', { username__icontains: query }, function (data) {
561+
return processAsync(data)
562+
})
563+
}
564+
})
565+
566+
$('#default-tester-button').click(function () {
567+
addDefaultTester()
568+
})
569+
570+
$('#id_tags').keyup(function (event) {
571+
if (event.keyCode === 13) {
572+
addDefaultTester()
573+
};
574+
})
575+
576+
function addDefaultTester () {
577+
$('#default-tester-button').parents('.dropdown').removeClass('open')
578+
// Closes the sub-menu option that contains input field
579+
$('#default-tester-button').parents('ul').css('display', '')
544580
const selectedCases = getSelectedTestCases()
545581

546582
if (!selectedCases.length) {
547583
alert($('#test_plan_pk').data('trans-no-testcases-selected'))
548584
return false
549585
}
550586

551-
const emailOrUsername = window.prompt($('#test_plan_pk').data('trans-username-email-prompt'))
587+
const emailOrUsername = $('input.typeahead.user-field.tt-input').val()
552588

553589
if (!emailOrUsername) {
554590
return false
@@ -558,7 +594,7 @@ function toolbarEvents (testPlanId, permissions) {
558594
testPlanId, permissions)
559595

560596
return false
561-
})
597+
}
562598

563599
$('#bulk-reviewer-button').click(function (ev) {
564600
$(this).parents('.dropdown').toggleClass('open')

‎tcms/testplans/templates/testplans/get.html

+11-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h2 class="card-pf-title">
106106
<div class="col-sm-12 toolbar-pf-filter" style="padding-left:0">
107107
<form class="toolbar-pf-actions">
108108
<div class="form-group" style="padding-left:10px; padding-right:0; border:0">
109-
<div class="dropdown btn-group">
109+
<div class="dropdown btn-group dropdown-keep-open" data-bs-auto-close="false">
110110
<button class="btn btn-link dropdown-toggle"
111111
type="button" id="testCaseActions"
112112
data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
@@ -168,14 +168,20 @@ <h2 class="card-pf-title">
168168
{% endfor %}
169169
</ul>
170170
</li>
171-
172-
<li>
173-
<a id="default-tester-button" href="#">
171+
<li class="dropdown-submenu">
172+
<a href="#">
174173
<span class="fa fa-search"></span>
175174
{% trans 'Default tester' %}
176175
</a>
176+
<ul class="dropdown-menu dropdown-menu-right js-toolbar-default-tester" style="min-width: 220px;padding: 5px;">
177+
<div style="display: inline-block;">
178+
<input type="text" class="form-control typeahead user-field">
179+
</div>
180+
<button class="btn btn-default" title="Apply" style="margin-left: 5px;" id="default-tester-button">
181+
<span class="fa fa-check"></span>
182+
</button>
183+
</ul>
177184
</li>
178-
179185
<li>
180186
<a id="bulk-reviewer-button" href="#">
181187
<span class="fa fa-history"></span>

0 commit comments

Comments
 (0)
Please sign in to comment.