Skip to content
Snippets Groups Projects
Commit 3437a613 authored by ale's avatar ale
Browse files

move autocompletion into the backend module

parent 635bc218
Branches
No related tags found
No related merge requests found
...@@ -78,6 +78,27 @@ djr.Backend.prototype.moreLikeThese = function(n, uuids, callback, ctx) { ...@@ -78,6 +78,27 @@ djr.Backend.prototype.moreLikeThese = function(n, uuids, callback, ctx) {
}); });
}; };
/**
* Autocomplete.
*
* Autocompletion callback suitable for use with the jQuery UI
* autocomplete plugin.
*
* @param {Object} request request object (contains term).
* @param {function} callback Callback function.
*/
djr.Backend.prototype.autocomplete = function(request, callback) {
$.ajax({url: '/autocomplete',
data: {'term': request.term},
dataType: 'json',
success: function(data) {
callback(data.results);
},
error: function(xhr, status, errorThrown) {
callback();
}});
};
/** /**
* Get the playlist list for a specified user. * Get the playlist list for a specified user.
* *
...@@ -99,7 +120,6 @@ djr.Backend.prototype.getPlList = function(uid, callback, ctx) { ...@@ -99,7 +120,6 @@ djr.Backend.prototype.getPlList = function(uid, callback, ctx) {
}); });
}; };
/** /**
* Get the songs in a playlist. * Get the songs in a playlist.
* *
......
...@@ -364,6 +364,20 @@ djr.init = function () { ...@@ -364,6 +364,20 @@ djr.init = function () {
djr.state.backend = new djr.Backend(); djr.state.backend = new djr.Backend();
djr.state.player = new djr.Player(djr.state.backend, '#djr_player'); djr.state.player = new djr.Player(djr.state.backend, '#djr_player');
// Set autocompletion and search handlers.
$('#queryField').autocomplete({
source: djr.state.backend.autocomplete,
autoFocus: true,
delay: 200,
minLength: 1
});
$('#queryField').focus();
$('#searchForm').submit(function() {
var query_string = $('#queryField').val();
djr.state.player.search(query_string);
return false;
});
// Add onclick hooks to the playlist controls. // Add onclick hooks to the playlist controls.
$('#playlistClearBtn').click(function() { $('#playlistClearBtn').click(function() {
djr.state.player.clearPlaylist(); djr.state.player.clearPlaylist();
......
...@@ -2,36 +2,8 @@ ...@@ -2,36 +2,8 @@
{% block head %} {% block head %}
<script type="text/javascript"> <script type="text/javascript">
do_autocomplete = function(request, response) {
$.ajax({url: '/autocomplete',
data: {'term': request.term},
dataType: 'json',
success: function(data) {
var items = data.results;
response(data.results);
},
error: function(xhr, status, errorThrown) {
response();
}});
};
do_search = function() {
var player = djr.player();
player.search($('#queryField').val());
return false;
};
$(document).ready(function() { $(document).ready(function() {
$('#queryField').autocomplete({ // Initialize DJR.
source: do_autocomplete,
autoFocus: true,
delay: 200,
minLength: 1,
});
$('#queryField').focus();
$('#searchForm').submit(do_search);
// Initialize DJRd.
djr.init(); djr.init();
}); });
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment