Typeahead on the main navbar search (for devices only)
This commit is contained in:
1
Changes
1
Changes
@@ -3,6 +3,7 @@
|
|||||||
[NEW FEATURES]
|
[NEW FEATURES]
|
||||||
|
|
||||||
* Icon to copy Navbar search text to Device Search Options field (closes #11)
|
* Icon to copy Navbar search text to Device Search Options field (closes #11)
|
||||||
|
* Typeahead on the main navbar search (for devices only)
|
||||||
|
|
||||||
[ENHANCEMENTS]
|
[ENHANCEMENTS]
|
||||||
|
|
||||||
|
|||||||
@@ -171,6 +171,15 @@ ajax '/ajax/content/device/details' => sub {
|
|||||||
}, { layout => undef };
|
}, { 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 {
|
get '/device' => sub {
|
||||||
my $ip = NetAddr::IP::Lite->new(param('q'));
|
my $ip = NetAddr::IP::Lite->new(param('q'));
|
||||||
if (! $ip) {
|
if (! $ip) {
|
||||||
|
|||||||
@@ -8,4 +8,13 @@
|
|||||||
[% IF params.tab %]
|
[% IF params.tab %]
|
||||||
$('#[% params.tab %]_form').trigger("submit");
|
$('#[% params.tab %]_form').trigger("submit");
|
||||||
[% END %]
|
[% 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user