Typeahead on the main navbar search (for devices only)

This commit is contained in:
Oliver Gorwits
2012-08-27 19:54:31 +01:00
parent 4cd0c06567
commit 8ae1bb1d6d
3 changed files with 19 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
[NEW FEATURES]
* Icon to copy Navbar search text to Device Search Options field (closes #11)
* Typeahead on the main navbar search (for devices only)
[ENHANCEMENTS]

View File

@@ -171,6 +171,15 @@ ajax '/ajax/content/device/details' => sub {
}, { layout => undef };
};
# support typeahead with simple AJAX query for device names
ajax '/ajax/data/device/typeahead' => sub {
my $q = param('query');
my $set = schema('netdisco')->resultset('Device')->search_fuzzy($q);
content_type 'application/json';
return to_json [map {$_->dns || $_->name || $_->ip} $set->all];
};
get '/device' => sub {
my $ip = NetAddr::IP::Lite->new(param('q'));
if (! $ip) {

View File

@@ -8,4 +8,13 @@
[% IF params.tab %]
$('#[% params.tab %]_form').trigger("submit");
[% END %]
// enable typeahead on the main search box, for device names only
$('#nq').typeahead({
source: function (query, process) {
return $.get('/ajax/data/device/typeahead', { query: query }, function (data) {
return process(data);
});
}
});
});