Updated all typeahead code to use new library

This commit is contained in:
laf
2015-04-29 17:48:57 +01:00
parent bcb39db66a
commit 02967b095b
6 changed files with 286 additions and 79 deletions

View File

@@ -1635,3 +1635,7 @@ tr.search:nth-child(odd) {
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2); -moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
box-shadow: 0 5px 10px rgba(0,0,0,.2); box-shadow: 0 5px 10px rgba(0,0,0,.2);
} }
.typeahead-left {
left: 0px !important;
}

View File

@@ -147,24 +147,64 @@ $('#add-map').click('',function (event) {
$('#map-stub').val(''); $('#map-stub').val('');
}); });
$('#map-stub').typeahead([ var map_devices = new Bloodhound({
{ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
name: 'map_devices', queryTokenizer: Bloodhound.tokenizers.whitespace,
remote : '/ajax_search.php?search=%QUERY&type=device&map=1', remote: {
header : '<h5><strong>&nbsp;Devices</strong></h5>', url: "ajax_search.php?search=%QUERY&type=device&map=1",
template: '{{name}}', filter: function (output) {
valueKey:"name", return $.map(output, function (item) {
engine: Hogan return {
}, name: item.name,
{ };
name: 'map_groups', });
remote : '/ajax_search.php?search=%QUERY&type=group&map=1', },
header : '<h5><strong>&nbsp;Groups</strong></h5>', wildcard: "%QUERY"
template: '{{name}}', }
valueKey:"name", });
engine: Hogan var map_groups = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "ajax_search.php?search=%QUERY&type=group&map=1",
filter: function (output) {
return $.map(output, function (item) {
return {
name: item.name,
};
});
},
wildcard: "%QUERY"
}
});
map_devices.initialize();
map_groups.initialize();
$('#map-stub').typeahead({
hint: true,
highlight: true,
minLength: 1,
classNames: {
menu: 'typeahead-left'
} }
]); },
{
source: map_devices.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
},
{
source: map_groups.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
});
$(function () { $(function () {
$("#start").datetimepicker({ $("#start").datetimepicker({

View File

@@ -67,34 +67,98 @@ $('#create-map').on('show.bs.modal', function (event) {
}); });
}); });
var cache = {}; var cache = {};
$('#rule').typeahead([ var alert_rules = new Bloodhound({
{ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
name: 'map_rules', queryTokenizer: Bloodhound.tokenizers.whitespace,
remote : '/ajax_search.php?search=%QUERY&type=alert-rules', remote: {
template: '{{name}}', url: "ajax_search.php?search=%QUERY&type=alert-rules",
valueKey:"name", filter: function (output) {
engine: Hogan return $.map(output, function (item) {
return {
name: item.name,
};
});
},
wildcard: "%QUERY"
}
});
alert_rules.initialize();
$('#rule').typeahead({
hint: true,
highlight: true,
minLength: 1,
classNames: {
menu: 'typeahead-left'
} }
]); },
{
source: alert_rules.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
alert_rules: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
});
$('#target').typeahead([ var map_devices = new Bloodhound({
{ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
name: 'map_devices', queryTokenizer: Bloodhound.tokenizers.whitespace,
remote : '/ajax_search.php?search=%QUERY&type=device&map=1', remote: {
header : '<h5><strong>&nbsp;Devices</strong></h5>', url: "ajax_search.php?search=%QUERY&type=device&map=1",
template: '{{name}}', filter: function (output) {
valueKey:"name", return $.map(output, function (item) {
engine: Hogan return {
}, name: item.name,
{ };
name: 'map_groups', });
remote : '/ajax_search.php?search=%QUERY&type=group&map=1', },
header : '<h5><strong>&nbsp;Groups</strong></h5>', wildcard: "%QUERY"
template: '{{name}}', }
valueKey:"name", });
engine: Hogan var map_groups = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "ajax_search.php?search=%QUERY&type=group&map=1",
filter: function (output) {
return $.map(output, function (item) {
return {
name: item.name,
};
});
},
wildcard: "%QUERY"
}
});
map_devices.initialize();
map_groups.initialize();
$('#target').typeahead({
hint: true,
highlight: true,
minLength: 1,
classNames: {
menu: 'typeahead-left'
} }
]); },
{
source: map_devices.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
},
{
source: map_groups.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
});
$('#map-submit').click('', function(e) { $('#map-submit').click('', function(e) {
e.preventDefault(); e.preventDefault();

View File

@@ -206,33 +206,98 @@ $('#create-alert').on('show.bs.modal', function (event) {
<script> <script>
var cache = {}; var cache = {};
$('#suggest').typeahead([ var suggestions = new Bloodhound({
{ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
name: 'suggestion', queryTokenizer: Bloodhound.tokenizers.whitespace,
remote : '/ajax_rulesuggest.php?device_id=<?php echo $device['device_id'];?>&term=%QUERY', remote: {
template: '{{name}}', url: "ajax_rulesuggest.php?device_id=<?php echo $device['device_id'];?>&term=%QUERY",
valueKey:"name", filter: function (output) {
engine: Hogan return $.map(output, function (item) {
return {
name: item.name,
};
});
},
wildcard: "%QUERY"
}
});
suggestions.initialize();
$('#suggest').typeahead({
hint: true,
highlight: true,
minLength: 1,
classNames: {
menu: 'typeahead-left'
} }
]); },
$('#map-stub').typeahead([ {
{ source: suggestions.ttAdapter(),
name: 'map_devices', async: true,
remote : '/ajax_search.php?search=%QUERY&type=device&map=1', displayKey: 'name',
header : '<h5><strong>&nbsp;Devices</strong></h5>', valueKey: name,
template: '{{name}}', templates: {
valueKey:"name", suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
engine: Hogan
},
{
name: 'map_groups',
remote : '/ajax_search.php?search=%QUERY&type=group&map=1',
header : '<h5><strong>&nbsp;Groups</strong></h5>',
template: '{{name}}',
valueKey:"name",
engine: Hogan
} }
]); });
var map_devices = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "ajax_search.php?search=%QUERY&type=device&map=1",
filter: function (output) {
return $.map(output, function (item) {
return {
name: item.name,
};
});
},
wildcard: "%QUERY"
}
});
var map_groups = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "ajax_search.php?search=%QUERY&type=group&map=1",
filter: function (output) {
return $.map(output, function (item) {
return {
name: item.name,
};
});
},
wildcard: "%QUERY"
}
});
map_devices.initialize();
map_groups.initialize();
$('#map-stub').typeahead({
hint: true,
highlight: true,
minLength: 1,
classNames: {
menu: 'typeahead-left'
}
},
{
source: map_devices.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
},
{
source: map_groups.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
});
$('#and, #or').click('', function(e) { $('#and, #or').click('', function(e) {
e.preventDefault(); e.preventDefault();

View File

@@ -128,15 +128,39 @@ $('#create-group').on('show.bs.modal', function (event) {
}); });
}); });
var cache = {}; var cache = {};
$('#suggest').typeahead([ var suggestions = new Bloodhound({
{ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
name: 'suggestion', queryTokenizer: Bloodhound.tokenizers.whitespace,
remote : '/ajax_rulesuggest.php?device_id=-1&term=%QUERY', remote: {
template: '{{name}}', url: "ajax_rulesuggest.php?device_id=-1&term=%QUERY",
valueKey:"name", filter: function (output) {
engine: Hogan return $.map(output, function (item) {
return {
name: item.name,
};
});
},
wildcard: "%QUERY"
}
});
suggestions.initialize();
$('#suggest').typeahead({
hint: true,
highlight: true,
minLength: 1,
classNames: {
menu: 'typeahead-left'
} }
]); },
{
source: suggestions.ttAdapter(),
async: true,
displayKey: 'name',
valueKey: name,
templates: {
suggestion: Handlebars.compile('<p>&nbsp;{{name}}</p>')
}
});
$('#and, #or').click('', function(e) { $('#and, #or').click('', function(e) {
e.preventDefault(); e.preventDefault();

View File

@@ -619,17 +619,27 @@ var bgp = new Bloodhound({
} }
}); });
if ($(window).width() < 768) {
var cssMenu = 'typeahead-left';
} else {
var cssMenu = '';
}
devices.initialize(); devices.initialize();
ports.initialize(); ports.initialize();
bgp.initialize();
$('#gsearch').typeahead({ $('#gsearch').typeahead({
hint: true, hint: true,
highlight: true, highlight: true,
minLength: 1 minLength: 1,
classNames: {
menu: cssMenu
}
}, },
{ {
source: devices.ttAdapter(), source: devices.ttAdapter(),
async: true, async: true,
disaply: name, display: name,
limit: 8, limit: 8,
templates: { templates: {
header: '<h5><strong>&nbsp;Devices</strong></h5>', header: '<h5><strong>&nbsp;Devices</strong></h5>',
@@ -639,7 +649,7 @@ $('#gsearch').typeahead({
{ {
source: ports.ttAdapter(), source: ports.ttAdapter(),
async: true, async: true,
disaply: name, display: name,
limit: 8, limit: 8,
templates: { templates: {
header: '<h5><strong>&nbsp;Ports</strong></h5>', header: '<h5><strong>&nbsp;Ports</strong></h5>',
@@ -649,7 +659,7 @@ $('#gsearch').typeahead({
{ {
source: bgp.ttAdapter(), source: bgp.ttAdapter(),
async: true, async: true,
disaply: name, display: name,
limit: 8, limit: 8,
templates: { templates: {
header: '<h5><strong>&nbsp;BGP Sessions</strong></h5>', header: '<h5><strong>&nbsp;BGP Sessions</strong></h5>',