Added tags filter to mosule massive operations (agent selection first)

This commit is contained in:
Arturo Gonzalez 2017-05-17 10:41:30 +02:00
parent 4b94e7ce2b
commit d49f1f9916
3 changed files with 44 additions and 16 deletions

View File

@ -341,8 +341,12 @@ $table->data['form_agents_2'][1] = html_print_select($status_list,
'status_agents', 'selected', '', __('All'), AGENT_STATUS_ALL, true);
$table->data['form_agents_2'][3] = '';
$tags = tags_get_user_tags();
$table->rowstyle['form_agents_4'] = 'vertical-align: top;';
$table->rowclass['form_agents_4'] = 'select_agents_row select_agents_row_2';
$table->data['form_agents_4'][0] = __('Tags');
$table->data['form_agents_4'][1] = html_print_select ($tags, 'tags[]',
$tags_name, false, __('Any'), -1, true, true, true);
$table->rowstyle['form_agents_3'] = 'vertical-align: top;';
$table->rowclass['form_agents_3'] = 'select_agents_row select_agents_row_2';
@ -974,7 +978,6 @@ $(document).ready (function () {
$("#groups_select").change (
function () {
if (this.value < 0) {
clean_lists();
$(".select_agents_row_2").css('display', 'none');
@ -1059,14 +1062,12 @@ $(document).ready (function () {
});
$("#tags").change(function() {
selector = $("#form_edit input[name=selection_mode]:checked").val();
if(selector == 'agents') {
$("#id_agents").trigger("change");
}
else if(selector == 'modules') {
$("#module_type").trigger("change");
}
$("#module_type").trigger("change");
});
$("#tags1").change(function() {
selector = $("#form_edit input[name=selection_mode]:checked").val();
$("#id_agents").trigger("change");
});
});

View File

@ -175,7 +175,9 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
//val() because the var is same <option val="NNN"></option>
idAgents.push($(val).val());
});
var tags_to_search = $('#tags1').val();
//Hack to find only enabled modules
//Pass a flag as global var
find_modules = 'all';
@ -226,6 +228,7 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
"page": "operation/agentes/ver_agente",
"get_agent_modules_json_for_multiple_agents": 1,
"id_agent[]": idAgents,
"tags[]": tags_to_search,
"all": find_modules,
"module_types_excluded[]": module_types_excluded,
"name": module_name,
@ -401,8 +404,6 @@ function alert_templates_changed_by_multiple_agents_with_alerts (event, id_agent
templates.push($(val).val());
});
console.log(templates);
$('#module').attr ('disabled', 1);
$('#module').empty ();
$('#module').append ($('<option></option>').html ("Loading...").attr ("value", 0));
@ -1092,7 +1093,7 @@ function openURLTagWindow(url) {
window.open(url, '','width=300, height=300, toolbar=no, location=no, directories=no, status=no, menubar=no');
}
function removeTinyMCE(elementID) {console.log(elementID);
function removeTinyMCE(elementID) {
if (elementID.length > 0 && !isEmptyObject(tinyMCE))
tinyMCE.EditorManager.execCommand('mceRemoveControl', true, elementID);
}

View File

@ -301,6 +301,7 @@ if (is_ajax ()) {
if ($get_agent_modules_json_for_multiple_agents) {
$idAgents = get_parameter('id_agent');
$tags = get_parameter('tags', null);
$module_types_excluded = get_parameter('module_types_excluded', array());
$module_name = (string) get_parameter('name');
$selection_mode = get_parameter('selection_mode', 'common');
@ -491,7 +492,7 @@ if (is_ajax ()) {
}
else {
if(implode(',', $idAgents) < 0) {
$sql = 'SELECT DISTINCT(nombre) FROM tagente_modulo
$sql = 'SELECT DISTINCT nombre, id_agente_modulo FROM tagente_modulo
WHERE nombre IN (
SELECT nombre
FROM tagente_modulo
@ -499,7 +500,7 @@ if (is_ajax ()) {
HAVING count(nombre) = (SELECT count(nombre) FROM tagente_modulo))';
}
else {
$sql = 'SELECT DISTINCT(nombre)
$sql = 'SELECT DISTINCT nombre, id_agente_modulo
FROM tagente_modulo t1
WHERE ' . $filter . '
AND t1.delete_pending = 0
@ -521,6 +522,31 @@ if (is_ajax ()) {
$nameModules = db_get_all_rows_sql($sql);
if ($tags != null) {
if ((count($tags) >= 1) && ($tags[0] != "") && ($tags[0] != -1)) {
$implode_tags = implode(",", $tags);
$tag_modules = db_get_all_rows_sql("SELECT DISTINCT id_agente_modulo FROM ttag_module WHERE id_tag IN (" . $implode_tags . ")");
if ($tag_modules) {
$final_modules = array();
foreach ($nameModules as $key => $module) {
$in_array = false;
foreach ($tag_modules as $t_module) {
if ($module['id_agente_modulo'] == $t_module['id_agente_modulo']) {
$in_array = true;
}
}
if ($in_array) {
$final_modules[] = $module;
}
}
$nameModules = $final_modules;
}
else {
$nameModules = array();
}
}
}
if ($nameModules == false) {
$nameModules = array();
}