Added filter for components. Also wiped dirty code

This commit is contained in:
Jose Gonzalez 2020-04-02 12:48:25 +02:00
parent 933bdef165
commit 6a7e9ba400
1 changed files with 30 additions and 25 deletions

View File

@ -314,11 +314,11 @@ class ModuleTemplates extends HTML
public function processData() public function processData()
{ {
// Only needed if process data. // Only needed if process data.
$modules_submit = get_parameter('add-modules-submit', ''); $modulesToAdd = get_parameter('add-modules-components', '');
// Success variable.
$success = false;
// Evaluate the modules allowed. // Evaluate the modules allowed.
if (!empty($this->action)) { if (!empty($this->action)) {
// Success variable.
$success = false;
$this->name = get_parameter('name', ''); $this->name = get_parameter('name', '');
$this->description = get_parameter('description', ''); $this->description = get_parameter('description', '');
$this->pen = get_parameter('pen', ''); $this->pen = get_parameter('pen', '');
@ -494,10 +494,8 @@ class ModuleTemplates extends HTML
} else { } else {
ui_print_success_message($msg); ui_print_success_message($msg);
} }
} else if ($modules_submit != '') { } else if ($modulesToAdd != '') {
$modulesToAdd = get_parameter('add-modules-components', '');
$modulesToAddList = explode(',', $modulesToAdd); $modulesToAddList = explode(',', $modulesToAdd);
foreach ($modulesToAddList as $module) { foreach ($modulesToAddList as $module) {
db_process_sql_insert( db_process_sql_insert(
'tnetwork_profile_component', 'tnetwork_profile_component',
@ -591,8 +589,8 @@ class ModuleTemplates extends HTML
'return' => true, 'return' => true,
], ],
]; ];
/*
$inputs[] = [ $inputs[] = [
'id' => 'add-modules-components-values', 'id' => 'add-modules-components-values',
'arguments' => [ 'arguments' => [
'name' => 'add-modules-components-values', 'name' => 'add-modules-components-values',
@ -600,39 +598,28 @@ class ModuleTemplates extends HTML
'value' => '', 'value' => '',
'return' => true, 'return' => true,
], ],
]; ];
*/
$inputs[] = [ $inputs[] = [
'label' => __('Filter'), 'label' => __('Filter'),
'id' => 'txt-add-modules-filter', 'id' => 'txt-add-modules-filter',
'arguments' => [ 'arguments' => [
'name' => 'add-modules-filter',
'input_class' => 'flex-row', 'input_class' => 'flex-row',
'type' => 'text', 'type' => 'text',
'size' => '57',
'onKeyDown' => 'filterTextComponents(event);',
'value' => '', 'value' => '',
'return' => true, 'return' => true,
], ],
]; ];
$inputs[] = [
'arguments' => [
'label' => __('Filter'),
'name' => 'add-modules-submit',
'type' => 'button',
'script' => 'this.form.submit()',
'attributes' => 'class="sub search"',
'return' => true,
],
];
$inputs[] = [ $inputs[] = [
'label' => __('Group'), 'label' => __('Group'),
'id' => 'add-modules-group', 'id' => 'add-modules-group',
'arguments' => [ 'arguments' => [
'name' => 'add-modules-group',
'input_class' => 'flex-row', 'input_class' => 'flex-row',
'type' => 'select', 'type' => 'select',
'script' => 'this.form.submit()', 'script' => '',
'fields' => $groups_compound, 'fields' => $groups_compound,
'nothing' => $groups_compound[$this->ncGroup], 'nothing' => $groups_compound[$this->ncGroup],
'return' => true, 'return' => true,
@ -645,6 +632,7 @@ class ModuleTemplates extends HTML
'arguments' => [ 'arguments' => [
'name' => 'add-modules-components', 'name' => 'add-modules-components',
'input_class' => 'flex-row', 'input_class' => 'flex-row',
'style' => 'width:100%;',
'type' => 'select', 'type' => 'select',
'multiple' => true, 'multiple' => true,
'fields' => $components, 'fields' => $components,
@ -1099,6 +1087,22 @@ class ModuleTemplates extends HTML
$('#module_template_form').submit(); $('#module_template_form').submit();
} }
/**
* Filter with text the components form
*/
function filterTextComponents(e){
var text_search = e.target.value;
text_search = text_search.toLowerCase();
$('#add-modules-components').children().each(function(){
var name = $(this).text().toLowerCase();
if (name.indexOf(text_search) === -1) {
$(this).css('display','none');
} else {
$(this).css('display','block');
}
});
}
/** /**
* Show the modal with list of entire components * Show the modal with list of entire components
*/ */
@ -1132,6 +1136,7 @@ class ModuleTemplates extends HTML
method: "processData" method: "processData"
} }
}); });
} }
/** /**
@ -1242,7 +1247,7 @@ class ModuleTemplates extends HTML
var valores = $("#add-modules-components") var valores = $("#add-modules-components")
.val() .val()
.join(","); .join(",");
$("#hidden-add-modules-components-values").val(valores); //$("#hidden-add-modules-components-values").val(valores);
}); });
}); });