From 988eb2e257fdc7e3e2e0e937d475a2561f56762f Mon Sep 17 00:00:00 2001 From: Tatiana Llorente Date: Wed, 19 Jun 2019 17:36:55 +0200 Subject: [PATCH 1/2] Add module filter by text -#2094 --- .../godmode/massive/massive_edit_modules.php | 8 ++++ .../include/javascript/pandora_modules.js | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index a803fa4725..1a18b410d5 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -388,6 +388,11 @@ $table->data['form_modules_4'][1] = html_print_select( true ); +$table->rowstyle['form_modules_filter'] = 'vertical-align: top;'; +$table->rowclass['form_modules_filter'] = 'select_modules_row select_modules_row_2'; +$table->data['form_modules_filter'][0] = __('Filter Modules'); +$table->data['form_modules_filter'][1] = html_print_input_text('filter_modules', '', '', 20, 255, true); + $table->rowstyle['form_modules_2'] = 'vertical-align: top;'; $table->rowclass['form_modules_2'] = 'select_modules_row select_modules_row_2'; $table->data['form_modules_2'][0] = __('Modules'); @@ -1247,6 +1252,9 @@ $(document).ready (function () { }); $("#module_loading").hide (); $("#module_name").removeAttr ("disabled"); + //Filter modules. Call the function when the select is fully loaded. + var textNoData = ""; + filterByText($('#module_name'), $("#text-filter_modules"), textNoData); }, "json" ); diff --git a/pandora_console/include/javascript/pandora_modules.js b/pandora_console/include/javascript/pandora_modules.js index 0487923b38..049bb9e96b 100644 --- a/pandora_console/include/javascript/pandora_modules.js +++ b/pandora_console/include/javascript/pandora_modules.js @@ -1223,3 +1223,42 @@ function get_explanation_recon_script(id, id_rt, url) { taskManager.addTask(xhr); } + +// Filter modules in a select (bulk operations) +function filterByText(selectbox, textbox, textNoData) { + return selectbox.each(function() { + var select = selectbox; + var options = []; + $(select) + .find("option") + .each(function() { + options.push({ value: $(this).val(), text: $(this).text() }); + }); + $(select).data("options", options); + $(textbox).bind("change keyup", function() { + var options = $(select) + .empty() + .scrollTop(0) + .data("options"); + var search = $(this).val(); + var regex = new RegExp(search, "gi"); + $.each(options, function(i) { + var option = options[i]; + if (option.text.match(regex) !== null) { + $(select).append( + $("