massive services

This commit is contained in:
fbsanchez 2020-07-07 19:10:24 +02:00
parent 1944b644a1
commit 3d493f14da
4 changed files with 244 additions and 4 deletions

View File

@ -794,7 +794,7 @@ function html_print_select_multiple_filtered(
}
// Main container.
$output .= '<div class="multi-select flex-row-vcenter '.$class.'">';
$output = '<div class="multi-select flex-row-vcenter '.$class.'">';
// Left box.
$output .= '<div class="multi-select-container flex-column">';
@ -941,7 +941,7 @@ function html_print_select_multiple_filtered(
$output .= '</div>';
// Left box.
// Right box.
$output .= '<div class="multi-select-container flex-column">';
// Filtering.
@ -1062,6 +1062,151 @@ function html_print_select_multiple_filtered(
}
/**
* Form multiple inputs for slect groups.
*
* @param array $data Data inputs.
*
* @return string Html output.
*/
function html_print_select_multiple_modules_filtered(array $data):string
{
if (is_ajax() === true) {
ui_require_javascript_file(
'multiselect_filtered',
'include/javascript/',
true
);
} else {
ui_require_javascript_file('multiselect_filtered');
}
$uniqId = $data['uniqId'];
// Group.
$output = '<div>';
$output .= html_print_input(
[
'label' => __('Group'),
'name' => 'filtered-module-group-'.$uniqId,
'returnAllGroup' => true,
'privilege' => 'AR',
'type' => 'select_groups',
'return' => true,
'script' => 'fmAgentChange(\''.$uniqId.'\')',
'selected' => $data['mGroup'],
]
);
// Recursion.
$output .= html_print_input(
[
'label' => __('Recursion'),
'type' => 'switch',
'name' => 'filtered-module-recursion-'.$uniqId,
'value' => (empty($data['mRecursion']) === true) ? false : true,
'checked' => (empty($data['mRecursion']) === true) ? false : true,
'return' => true,
'id' => 'filtered-module-recursion-'.$uniqId,
'onchange' => 'fmAgentChange(\''.$uniqId.'\')',
]
);
// Groups module.
$module_groups = db_get_all_rows_sql(
'SELECT * FROM tmodule_group ORDER BY name'
);
$module_groups = array_reduce(
$module_groups,
function ($carry, $item) {
$carry[$item['id_mg']] = $item['name'];
return $carry;
}
);
$output .= html_print_input(
[
'label' => __('Module group'),
'type' => 'select',
'fields' => $module_groups,
'name' => 'filtered-module-module-group-'.$uniqId,
'selected' => $data['mModuleGroup'],
'return' => true,
'nothing' => __('All'),
'nothing_value' => 0,
'script' => 'fmModuleChange(\''.$uniqId.'\')',
]
);
$output .= '</div>';
$output .= '<div>';
// Agent.
$agents = agents_get_group_agents($data['mGroup']);
if ((empty($agents)) === true || $agents == -1) {
$agents = [];
}
$output .= html_print_input(
[
'label' => __('Agents'),
'type' => 'select',
'fields' => $agents,
'name' => 'filtered-module-agents-'.$uniqId,
'selected' => explode(',', $data['mAgents']),
'return' => true,
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
'script' => 'fmModuleChange(\''.$uniqId.'\')',
]
);
// Show common modules.
$selection = [
0 => __('Show common modules'),
1 => __('Show all modules'),
];
$output .= html_print_input(
[
'label' => __('Show common modules'),
'type' => 'select',
'fields' => $selection,
'name' => 'filtered-module-show-common-modules-'.$uniqId,
'selected' => $data['mShowCommonModules'],
'return' => true,
'script' => 'fmModuleChange(\''.$uniqId.'\')',
]
);
$all_modules = select_modules_for_agent_group(
$data['mModuleGroup'],
explode(',', $data['mAgents']),
$data['mShowCommonModules'],
false
);
$output .= html_print_input(
[
'label' => __('Modules'),
'type' => 'select',
'fields' => $all_modules,
'name' => 'filtered-module-modules-'.$uniqId,
'selected' => explode(',', $data['mModules']),
'return' => true,
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
]
);
$output .= '</div>';
if ($data['return'] === false) {
echo $output;
}
return $output;
}
/**
* Prints an array of fields in a popup menu of a form based on a SQL query.
* The first and second columns of the query will be used.
@ -4339,7 +4484,7 @@ function html_print_input($data, $wrapper='div', $input_only=false)
0 => __('Select an Agent first'),
];
} else {
$string_filter .= '';
$string_filter = '';
if ($data['get_only_string_modules'] === true) {
$string_filter = 'AND id_tipo_modulo IN (17,23,3,10,33,36)';
}
@ -4425,6 +4570,10 @@ function html_print_input($data, $wrapper='div', $input_only=false)
);
break;
case 'select_multiple_modules_filtered':
$output .= html_print_select_multiple_modules_filtered($data);
break;
default:
// Ignore.
break;

View File

@ -1,8 +1,9 @@
/* global $ */
/* global $, jQuery*/
/**
* Add modules from available to selected.
*/
// eslint-disable-next-line no-unused-vars
function addItems(id, noneStr) {
$("#available-select-" + id + " :selected")
.toArray()
@ -17,6 +18,7 @@ function addItems(id, noneStr) {
/**
* Mark all options for given id.
*/
// eslint-disable-next-line no-unused-vars
function markAll(id) {
$("#" + id + " option").prop("selected", true);
}
@ -24,6 +26,7 @@ function markAll(id) {
/**
* Remove modules from selected back to available.
*/
// eslint-disable-next-line no-unused-vars
function removeItems(id, noneStr) {
$("#selected-select-" + id + " :selected")
.toArray()
@ -69,16 +72,19 @@ function filterItems(id, str) {
});
}
// eslint-disable-next-line no-unused-vars
function filterAvailableItems(txt, id, noneStr) {
filterItems("available-select-" + id, txt);
keepSelectClean("available-select-" + id, noneStr);
}
// eslint-disable-next-line no-unused-vars
function filterSelectedItems(txt, id, noneStr) {
filterItems("selected-select-" + id, txt);
keepSelectClean("selected-select-" + id, noneStr);
}
// eslint-disable-next-line no-unused-vars
function disableFilters(id) {
$("#id-group-selected-select-" + id).prop("disabled", true);
$("#checkbox-id-group-recursion-selected-select-" + id).prop(
@ -87,6 +93,7 @@ function disableFilters(id) {
);
}
// eslint-disable-next-line no-unused-vars
function reloadContent(id, url, options, side, noneStr) {
var current;
var opposite;
@ -155,3 +162,65 @@ $(document).submit(function() {
.keyup();
$("[id^=selected-select-] option").prop("selected", true);
});
// eslint-disable-next-line no-unused-vars
function fmAgentChange(uniqId) {
var idGroup = $("#filtered-module-group-" + uniqId).val();
var recursion = $("#filtered-module-recursion-" + uniqId).is(":checked");
jQuery.post(
"ajax.php",
{
page: "operation/agentes/ver_agente",
get_agents_group_json: 1,
id_group: idGroup,
privilege: "AW",
keys_prefix: "_",
recursion: recursion
},
function(data) {
$("#filtered-module-agents-" + uniqId).html("");
$("#filtered-module-modules-" + uniqId).html("");
jQuery.each(data, function(id, value) {
// Remove keys_prefix from the index
id = id.substring(1);
var option = $("<option></option>")
.attr("value", value["id_agente"])
.html(value["alias"]);
$("#filtered-module-agents-" + uniqId).append(option);
});
},
"json"
);
}
// eslint-disable-next-line no-unused-vars
function fmModuleChange(uniqId) {
var idModuleGroup = $("#filtered-module-module-group-" + uniqId).val();
var idAgents = $("#filtered-module-agents-" + uniqId).val();
var showCommonModules = $(
"#filtered-module-show-common-modules-" + uniqId
).val();
jQuery.post(
"ajax.php",
{
page: "operation/agentes/ver_agente",
get_modules_group_json: 1,
id_module_group: idModuleGroup,
id_agents: idAgents,
selection: showCommonModules
},
function(data) {
$("#filtered-module-modules-" + uniqId).html("");
if (data) {
jQuery.each(data, function(id, value) {
var option = $("<option></option>")
.attr("value", value["id_agente_modulo"])
.html(value["nombre"]);
$("#filtered-module-modules-" + uniqId).append(option);
});
}
},
"json"
);
}

View File

@ -285,6 +285,11 @@ class Module extends Entity
return $this->{$methodName}($params);
}
if (is_array($this->fields) === false) {
// Element deleted.
return null;
}
if (array_key_exists($methodName, $this->fields) === true) {
if (empty($params) === false) {
if ($this->is_local() === true) {

View File

@ -716,6 +716,23 @@ p.center {
text-align: center;
}
.center {
text-align: center;
}
.margin-top-10 {
margin-top: 10px;
}
.margin-bottom-10 {
margin-bottom: 10px;
}
.margin-tb-10 {
margin-top: 10px;
margin-bottom: 10px;
}
.img_help {
cursor: help;
}