Skip to content
Snippets Groups Projects
Commit a5835e4d authored by Jan Mach's avatar Jan Mach
Browse files

Improvements in event search form.

The event search form was enhanced to support new 'empty' and 'any' search options, that were introduced by previous commit:ae96bb62. This also fixes the issue #4091 with the 'no preference' option, that was broken. Additionally, the bootstrap select widgets now try to enforce the policy, that 'empty' and 'any' options are mutually exclusive with everything else. There is stil room for improvement, because 'any' option is not capable of disabling the 'empty' option. (Redmine issue: #4091)
parent ae96bb62
No related branches found
No related tags found
No related merge requests found
......@@ -120,4 +120,23 @@ $(function() {
animate: true,
container: 'body'
});
// Special handling of '__EMPTY__' and '__ANY__' options in event search form
// selects. This method stil can be improved, so that 'any' is capable of disabling
// 'empty'.
$(".esf-any-empty").on("changed.bs.select", function(e, clickedIndex, newValue, oldValue) {
var selected = $(e.currentTarget).val();
// The empty option is mutually exclusive with everything else and has
// top priority.
if (selected.indexOf('__EMPTY__') != -1) {
//console.log('Empty selected');
$(e.currentTarget).selectpicker('val', ['__EMPTY__']);
}
// The any option is mutually exclusive with everything else.
else if (selected.indexOf('__ANY__') != -1) {
//console.log('Any selected');
$(e.currentTarget).selectpicker('val', ['__ANY__']);
}
//console.log(e, this, this.value, selected, clickedIndex, newValue, oldValue);
});
});
......@@ -133,7 +133,7 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional()
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [],
filters = [lambda x: x or []]
)
target_types = wtforms.SelectMultipleField(
......@@ -141,7 +141,7 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional()
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [],
filters = [lambda x: x or []]
)
host_types = wtforms.SelectMultipleField(
......@@ -149,7 +149,7 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional()
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [],
filters = [lambda x: x or []]
)
detectors = wtforms.SelectMultipleField(
......@@ -157,7 +157,10 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional(),
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [
('__EMPTY__', lazy_gettext('<< without value >>')),
('__ANY__', lazy_gettext('<< any value >>'))
],
filters = [lambda x: x or []]
)
detector_types = wtforms.SelectMultipleField(
......@@ -165,7 +168,10 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional()
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [
('__EMPTY__', lazy_gettext('<< without value >>')),
('__ANY__', lazy_gettext('<< any value >>'))
],
filters = [lambda x: x or []]
)
categories = wtforms.SelectMultipleField(
......@@ -173,7 +179,10 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional(),
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [
('__EMPTY__', lazy_gettext('<< without value >>')),
('__ANY__', lazy_gettext('<< any value >>'))
],
filters = [lambda x: x or []]
)
severities = wtforms.SelectMultipleField(
......@@ -181,7 +190,10 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional(),
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [
('__EMPTY__', lazy_gettext('<< without value >>')),
('__ANY__', lazy_gettext('<< any value >>'))
],
filters = [lambda x: x or []]
)
classes = wtforms.SelectMultipleField(
......@@ -189,7 +201,10 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional(),
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [
('__EMPTY__', lazy_gettext('<< without value >>')),
('__ANY__', lazy_gettext('<< any value >>'))
],
filters = [lambda x: x or []]
)
description = wtforms.StringField(
......@@ -203,7 +218,10 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
validators = [
wtforms.validators.Optional(),
],
choices = [('', lazy_gettext('<< no preference >>'))],
choices = [
('__EMPTY__', lazy_gettext('<< without value >>')),
('__ANY__', lazy_gettext('<< any value >>'))
],
filters = [lambda x: x or []]
)
groups = QuerySelectMultipleField(
......@@ -253,12 +271,13 @@ class SimpleEventSearchForm(flask_wtf.FlaskForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.source_types.choices[1:] = kwargs['choices_source_types']
self.target_types.choices[1:] = kwargs['choices_target_types']
self.host_types.choices[1:] = kwargs['choices_host_types']
self.detectors.choices[1:] = kwargs['choices_detectors']
self.detector_types.choices[1:] = kwargs['choices_detector_types']
self.categories.choices[1:] = kwargs['choices_categories']
self.severities.choices[1:] = kwargs['choices_severities']
self.classes.choices[1:] = kwargs['choices_classes']
self.protocols.choices[1:] = kwargs['choices_protocols']
self.source_types.choices = kwargs['choices_source_types']
self.target_types.choices = kwargs['choices_target_types']
self.host_types.choices = kwargs['choices_host_types']
self.detectors.choices[2:] = kwargs['choices_detectors']
self.detector_types.choices[2:] = kwargs['choices_detector_types']
self.categories.choices[2:] = kwargs['choices_categories']
self.severities.choices[2:] = kwargs['choices_severities']
self.classes.choices[2:] = kwargs['choices_classes']
self.protocols.choices[2:] = kwargs['choices_protocols']
......@@ -214,21 +214,21 @@
<div class="form-group{{ frmctrlhdn }}" id="form-group-event-1">
<div class="col-sm-4">
<label>{{ search_form.categories.label }}</label>
{{ search_form.categories(class_='form-control selectpicker', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{{ search_form.categories(class_='form-control selectpicker esf-any-empty', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{%- if search_form.categories.errors %}
{{ macros_site.form_errors(search_form.categories.errors) }}
{%- endif %}
</div>
<div class="col-sm-4">
<label>{{ search_form.severities.label }}</label>
{{ search_form.severities(class_='form-control selectpicker', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{{ search_form.severities(class_='form-control selectpicker esf-any-empty', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{%- if search_form.severities.errors %}
{{ macros_site.form_errors(search_form.severities.errors) }}
{%- endif %}
</div>
<div class="col-sm-4">
<label>{{ search_form.classes.label }}</label>
{{ search_form.classes(class_='form-control selectpicker', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{{ search_form.classes(class_='form-control selectpicker esf-any-empty', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{%- if search_form.classes.errors %}
{{ macros_site.form_errors(search_form.classes.errors) }}
{%- endif %}
......@@ -244,7 +244,7 @@
</div>
<div class="col-sm-4">
<label>{{ search_form.protocols.label }}</label>
{{ search_form.protocols(class_='form-control selectpicker', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{{ search_form.protocols(class_='form-control selectpicker esf-any-empty', disabled=frmctrldsb,**{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{%- if search_form.protocols.errors %}
{{ macros_site.form_errors(search_form.protocols.errors) }}
{%- endif %}
......@@ -263,14 +263,14 @@
<div class="form-group{{ frmctrlhdn }}" id="form-group-detector">
<div class="col-sm-6">
<label>{{ search_form.detectors.label }}</label>
{{ search_form.detectors(class_='form-control selectpicker', disabled=frmctrldsb, **{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{{ search_form.detectors(class_='form-control selectpicker esf-any-empty', disabled=frmctrldsb, **{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{%- if search_form.detectors.errors %}
{{ macros_site.form_errors(search_form.detectors.errors) }}
{%- endif %}
</div>
<div class="col-sm-6">
<label>{{ search_form.detector_types.label }}</label>
{{ search_form.detector_types(class_='form-control selectpicker', disabled=frmctrldsb, **{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{{ search_form.detector_types(class_='form-control selectpicker esf-any-empty', disabled=frmctrldsb, **{'data-live-search':'true', 'data-size': '10', 'data-selected-text-format': 'count > 3'}) }}
{%- if search_form.detector_types.errors %}
{{ macros_site.form_errors(search_form.detector_types.errors) }}
{%- endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment