Merge branch 'ent-10055-introducir-aviso-de-borrado-de-modulos-hijos' into 'develop'

Added child module delete warning

See merge request artica/pandorafms!5429
This commit is contained in:
Rafael Ameijeiras 2023-01-26 12:53:03 +00:00
commit 7bdfb1a096
3 changed files with 128 additions and 10 deletions

View File

@ -1283,9 +1283,13 @@ foreach ($modules as $module) {
}
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
// Check module relatonships to show warning message.
$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="index.php?sec=gagente&tab=module&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&delete_module='.$module['id_agente_modulo'].'"
onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
$data[9] = '<a href="#"
onClick="get_children_modules(false, \''.$module['id_agente_modulo'].'\', \''.$url.'\')">';
$data[9] .= html_print_image(
'images/cross.png',
true,
@ -1309,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);
@ -1344,6 +1347,8 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
false,
'class="sub next"'
);
echo '</div>';
echo '</form>';
}
@ -1353,6 +1358,17 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
$(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');
@ -1394,4 +1410,60 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
window.location = window.location + "&checked=true";
}
}
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 ret = false;
if(children != false) {
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>';
}
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 true;
}
</script>

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'], true);
if ((bool) $child_modules === false) {
continue;
}
foreach ($child_modules as $child) {
$module_exist = in_array($child['id_agente_modulo'], $parent_modules);
$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;
}
}

View File

@ -3992,16 +3992,28 @@ function recursive_get_dt_from_modules_tree(&$f_modules, $modules, $deep)
* Get the module data from a children
*
* @param integer $id_module Id module
* @param boolean $recursive Recursive children search.
* @return array Children module data
*/
function get_children_module($id_module)
function get_children_module($id_module, $fields=false, $recursion=false)
{
$children_module_data = db_get_all_rows_sql(
'SELECT *
FROM tagente_modulo
WHERE parent_module_id = '.$id_module
$children_module_data = db_get_all_rows_filter(
'tagente_modulo',
['parent_module_id' => $id_module],
$fields
);
if ($children_module_data !== false && $recursion === true) {
foreach ($children_module_data as $child) {
$niece = get_children_module($child['id_agente_modulo'], $fields, false);
if ((bool) $niece === false) {
continue;
} else {
$children_module_data = array_merge($children_module_data, $niece);
}
}
}
return $children_module_data;
}