Merge branch 'ent-8606-Fallos-en-nuevas-bulk-operations' into 'develop'

fixed select2 multiple pandora_enterprise#8606

See merge request artica/pandorafms!4710
This commit is contained in:
Daniel Rodriguez 2022-02-22 11:46:57 +00:00
commit c1d5eb2d68
2 changed files with 82 additions and 5 deletions

View File

@ -961,7 +961,9 @@ function html_print_select(
}
$output .= '<script type="text/javascript">';
$output .= '$("#'.$id.'").select2();';
$output .= '$("#'.$id.'").select2({
closeOnSelect: '.(($select2_multiple_enable === true) ? 'false' : 'true').'
});';
if ($required !== false) {
$require_message = __('Please select an item from this list.');
@ -994,6 +996,79 @@ function html_print_select(
$output .= '$("#'.$id.'").trigger("change");';
$output .= 'var count_shift_'.$id.' = 0;';
$output .= 'var shift_array_'.$id.' = [];';
$output .= 'var options_selecteds_'.$id.' = [];';
$output .= '$("#'.$id.'").on("select2:select", function (e) {
if (event.shiftKey) {
shift_array_'.$id.'.push(e.params.data.element.index);
count_shift_'.$id.'++;
}
if(count_shift_'.$id.' == 2 ){
if(shift_array_'.$id.'[0] <= shift_array_'.$id.'[1]) {
for (var i = shift_array_'.$id.'[0]; i <= shift_array_'.$id.'[1]; i++) {
var option_value = $("#'.$id.' option").eq(i).val();
options_selecteds_'.$id.'.push(option_value);
}
} else {
for (var i = shift_array_'.$id.'[0]; i >= shift_array_'.$id.'[1]; i--) {
var option_value = $("#'.$id.' option").eq(i).val();
options_selecteds_'.$id.'.push(option_value);
}
}
$("#'.$id.'").val(
[
...$("#'.$id.'").val(),
...options_selecteds_'.$id.'
]
);
$("#'.$id.'").trigger("change");
$("#'.$id.'").select2("close");
count_shift_'.$id.' = 0;
shift_array_'.$id.' = [];
options_selecteds_'.$id.' = [];
}
});';
$output .= 'var delete_count_shift_'.$id.' = 0;';
$output .= 'var delete_shift_array_'.$id.' = [];';
$output .= 'var delete_options_selecteds_'.$id.' = [];';
$output .= '$("#'.$id.'").on("select2:unselect", function (e) {
if (event.shiftKey) {
delete_shift_array_'.$id.'.push(e.params.data.element.index);
delete_count_shift_'.$id.'++;
}
if(delete_count_shift_'.$id.' == 2 ){
if(delete_shift_array_'.$id.'[0] <= delete_shift_array_'.$id.'[1]) {
for (var i = delete_shift_array_'.$id.'[0]; i <= delete_shift_array_'.$id.'[1]; i++) {
var option_value = $("#'.$id.' option").eq(i).val();
delete_options_selecteds_'.$id.'.push(option_value);
}
} else {
for (var i = delete_shift_array_'.$id.'[0]; i >= delete_shift_array_'.$id.'[1]; i--) {
var option_value = $("#'.$id.' option").eq(i).val();
delete_options_selecteds_'.$id.'.push(option_value);
}
}
var result = [];
$("#'.$id.'").val().forEach(function(value) {
if (delete_options_selecteds_'.$id.'.includes(value) == false) {
result.push(value);
}
});
$("#'.$id.'").val(result);
$("#'.$id.'").trigger("change");
$("#'.$id.'").select2("close");
delete_count_shift_'.$id.' = 0;
delete_shift_array_'.$id.' = [];
delete_options_selecteds_'.$id.' = [];
}
});';
$output .= 'function checkMultipleAll(id){
if ($("#checkbox-"+id.id+"-check-all").is(":checked")) {
$("#"+id.id+" > option").prop("selected", "selected");

View File

@ -3726,7 +3726,7 @@ function get_modules_agents($id_module_group, $id_agents, $selection, $select_mo
*
* @return array
*/
function get_same_modules($agents, $modules)
function get_same_modules($agents, array $modules=[])
{
if (is_array($agents) === false || empty($agents) === true) {
return [];
@ -3791,7 +3791,8 @@ function get_same_modules_all($agents, $modules, $select_mode=true)
$carry[$explode[0]][] = $explode[1];
return $carry;
}
},
[]
);
if ($select_mode === true) {
@ -3802,7 +3803,8 @@ function get_same_modules_all($agents, $modules, $select_mode=true)
$carry[$explode[0]][] = $explode[1];
return $carry;
}
},
[]
);
} else {
$rows = db_get_all_rows_sql(
@ -3831,7 +3833,7 @@ function get_same_modules_all($agents, $modules, $select_mode=true)
$result = [];
foreach ($agents as $tserver => $id_agents) {
if (metaconsole_connect(null, $tserver) == NOERR) {
$same_modules = get_same_modules($id_agents, $modules[$tserver]);
$same_modules = get_same_modules($id_agents, ($modules[$tserver] ?? []));
foreach ($same_modules as $id_module) {
$result[] = $tserver.'|'.$id_module;
}