Delete modules with children message

This commit is contained in:
Calvo 2023-01-24 12:26:49 +01:00
parent 8c071532e9
commit 5d0826f412
2 changed files with 86 additions and 11 deletions

View File

@ -1284,12 +1284,11 @@ foreach ($modules as $module) {
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
// Check module relatonships to show warning message.
$module_children = json_encode(get_children_module($module['id_agente_modulo'], 'nombre'));
$url = htmlentities('index.php?sec=gagente&tab=module&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&delete_module='.$module['id_agente_modulo']);
// Delete module.
$data[9] = '<a href="#"
onClick="delete_module_warning(\''.htmlentities($module_children).'\',\''.$url.'\')">';
onClick="get_children_modules(false, \''.$module['id_agente_modulo'].'\', \''.$url.'\')">';
$data[9] .= html_print_image(
'images/cross.png',
@ -1314,8 +1313,7 @@ foreach ($modules as $module) {
}
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&tab=module"
onsubmit="if (! confirm (\''.__('Are you sure?').'\')) return false">';
echo '<form method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&tab=module" id="form_multiple_delete">';
}
html_print_table($table);
@ -1349,6 +1347,8 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
false,
'class="sub next"'
);
echo '</div>';
echo '</form>';
}
@ -1357,7 +1357,18 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
<script type="text/javascript">
$(document).ready (function () {
$("input[name=submit_modules_action]").click(function (event) {
event.preventDefault();
var module_action = $('#module_action').val();
if(module_action !== 'delete') {
$("#form_multiple_delete").submit();
} else {
get_children_modules(true);
}
});
$('[id^=checkbox-id_delete]').change(function(){
if($(this).parent().parent().hasClass('checkselected')){
$(this).parent().parent().removeClass('checkselected');
@ -1400,28 +1411,58 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
}
}
function delete_module_warning(children_json, url) {
function get_children_modules(multiple, id_module, url) {
var selected_modules = [];
if(typeof(id_module) === 'undefined' && multiple === true) {
$("input[id^='checkbox-id_delete']:checked").each(function () {
selected_modules.push(this.value);
});
} else {
selected_modules = [id_module];
}
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "json",
data: {
page: 'include/ajax/module',
get_children_modules: true,
parent_modulues: JSON.parse(JSON.stringify(selected_modules)),
},
success: function (data) {
delete_module_warning(data, multiple, id_module, url);
}
});
}
function delete_module_warning(children, multiple, id_module, url) {
var message = '<?php echo __('Are you sure?'); ?>';
var children = JSON.parse(children_json);
var ret = false;
if(children != false) {
message += '<br><strong>' + '<?php echo __('This module has children modules. Following modules will be also deleted: '); ?>' + '</strong><ul>';
message += '<br><strong>' + '<?php echo __('This module has children modules.The following modules will also be deleted: '); ?>' + '</strong><ul>';
$.each(children, function (key, value) {
message += '<li>' + value['nombre'] + '</li>';
});
message += '</ul>';
}
}
ret = confirmDialog({
confirmDialog({
title: "<?php echo __('Delete module'); ?>",
message: message,
onAccept: function() {
if(multiple === true) {
$("#form_multiple_delete").submit();
return true;
} else {
window.location.href = url;
}
}
});
return false;
return true;
}

View File

@ -61,6 +61,8 @@ if (check_login()) {
0
);
$get_children_modules = (bool) get_parameter('get_children_modules', false);
$get_data_dataMatrix = (bool) get_parameter(
'get_data_dataMatrix',
0
@ -1629,4 +1631,36 @@ if (check_login()) {
return;
}
if ($get_children_modules === true) {
$parent_modules = get_parameter('parent_modulues', false);
$children_selected = [];
if ($parent_modules === false) {
$children_selected = false;
} else {
foreach ($parent_modules as $parent) {
$child_modules = get_children_module($parent_modules, ['nombre', 'id_agente_modulo']);
if ((bool) $child_modules === false) {
continue;
}
foreach ($child_modules as $child) {
$module_exist = in_array($child['id_agente_modulo'], $children_selected);
$child_exist = in_array($child, $children_selected);
if ($module_exist === false && $child_exist === false) {
array_push($children_selected, $child);
}
}
}
}
if (empty($children_selected) === true) {
$children_selected = false;
}
echo json_encode($children_selected);
return;
}
}