js/events: improve search field change detection

This used to be nasty since "search" is the field with the initial
focus. Right now we detect "real" changes, this might be implemented
in a more generic way for all autocompleting fields later on.
This commit is contained in:
Thomas Gelf 2014-05-20 14:07:19 +00:00
parent 67144407e6
commit de0b97b4ca
1 changed files with 17 additions and 1 deletions

View File

@ -9,6 +9,8 @@
Icinga.Events = function (icinga) {
this.icinga = icinga;
this.searchValue = '';
};
Icinga.Events.prototype = {
@ -27,6 +29,11 @@
this.applyHandlers($('#layout'));
this.icinga.ui.prepareContainers();
this.icinga.ui.prepareMultiselectTables($(document));
// Remember initial search field value if any
if ($('#menu input.search').val().length) {
this.searchValue = $('#menu input.search').val();
}
},
// TODO: What's this?
@ -108,7 +115,7 @@
// We support an 'autosubmit' class on dropdown form elements
$(document).on('change', 'form select.autosubmit', { self: this }, this.autoSubmitForm);
$(document).on('keyup', '#menu input.search', {self: this}, this.autoSubmitForm);
$(document).on('keyup', '#menu input.search', {self: this}, this.autoSubmitSearch);
$(document).on('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
$(document).on('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
@ -233,6 +240,15 @@
$(this).removeClass('hover');
},
autoSubmitSearch: function(event) {
var self = event.data.self;
if ($('#menu input.search').val() === self.searchValue) {
return;
}
self.searchValue = $('#menu input.search').val();
return self.autoSubmitForm(event);
},
autoSubmitForm: function (event) {
return event.data.self.submitForm(event, true);
},