WIP:Added searchbar to select multiple modules

This commit is contained in:
Calvo 2022-01-25 20:15:40 +01:00
parent 96d0194009
commit f383586dcc
4 changed files with 92 additions and 9 deletions

View File

@ -333,10 +333,10 @@ echo "<table width='100%' cellpadding='4' cellpadding='4' class='databox filters
echo '<tr>';
echo '<td class="w50p" id="select_multiple_modules_filtered">'.html_print_input(
[
'type' => 'select_multiple_modules_filtered',
'uniqId' => 'modules',
'class' => 'flex flex-row',
'type' => 'select_multiple_modules_filtered',
'uniqId' => 'modules',
'class' => 'flex flex-row',
'searchBar' => true,
]
).'</td>';
echo '</tr><tr>';

View File

@ -1480,11 +1480,43 @@ function html_print_select_multiple_modules_filtered(array $data):string
'return' => true,
'nothing' => __('All'),
'nothing_value' => 0,
'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
]
);
$output .= '</div>';
if (empty($data['searchBar']) === false && $data['searchBar'] === true) {
$output .= '<div>';
$output .= '<div>';
$output .= html_print_input(
[
'type' => 'text',
'name' => 'agent-searchBar-'.$uniqId,
'onKeyUp' => 'searchAgent(\''.$uniqId.'\')',
'value' => __('Type for search...'),
'return' => true,
]
);
$output .= '</div>';
$output .= '<div>';
$output .= html_print_input(
[
'type' => 'text',
'name' => 'module-searchBar-'.$uniqId,
'onKeyUp' => 'searchModule(\''.$uniqId.'\')',
'return' => true,
'value' => 'test',
]
);
$output .= '</div>';
$output .= '</div>';
}
$output .= '<div>';
// Agent.
$agents = agents_get_group_agents(
@ -1533,7 +1565,7 @@ function html_print_select_multiple_modules_filtered(array $data):string
'return' => true,
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
]
);
@ -1550,7 +1582,7 @@ function html_print_select_multiple_modules_filtered(array $data):string
'name' => 'filtered-module-show-common-modules-'.$uniqId,
'selected' => $data['mShowCommonModules'],
'return' => true,
'script' => 'fmModuleChange(\''.$uniqId.'\', '.is_metaconsole().')',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
]
);

View File

@ -231,7 +231,7 @@ function fmModuleChange(uniqId, isMeta) {
if (data) {
jQuery.each(data, function(id, value) {
var option = $("<option></option>");
if (isMeta === true) {
if (isMeta === 1) {
option
.attr(
"value",
@ -251,3 +251,50 @@ function fmModuleChange(uniqId, isMeta) {
"json"
);
}
// Function to search in agents select.
function searchAgent(uniqId) {
// Declare variables
var agents = $("#filtered-module-agents-" + uniqId + " option");
// Loop through all list items, and hide those who don't match the search query
agents.each(function() {
var filter = $("#text-agent-searchBar-modules")
.val()
.toUpperCase();
if (
$(this)
.text()
.toUpperCase()
.indexOf(filter) > -1
) {
$(this).show();
} else {
$(this).hide();
}
});
}
// Function to search in modules select.
function searchModule(uniqId) {
// Declare variables
var modules = $("#filtered-module-modules-" + uniqId + " option");
// Loop through all list items, and hide those who don't match the search query
modules.each(function() {
var filter = $("#text-module-searchBar-modules")
.val()
.toUpperCase();
if (
$(this)
.text()
.toUpperCase()
.indexOf(filter) > -1
) {
$(this).show();
} else {
$(this).hide();
}
});
}

View File

@ -8473,7 +8473,7 @@ div#err_msg_centralised {
#select_multiple_modules_filtered > div {
display: flex;
flex-direction: row;
justify-content: space-around;
justify-content: space-between;
align-items: center;
margin: 5px;
flex-wrap: wrap;
@ -8500,3 +8500,7 @@ div#err_msg_centralised {
#select_multiple_modules_filtered > div > div > .select2 {
min-width: 250px !important;
}
#select_multiple_modules_filtered > div > div > select {
max-width: 250px !important;
}