diff --git a/kfet/autocomplete.py b/kfet/autocomplete.py
index 1ebbbc75..1c2b1a75 100644
--- a/kfet/autocomplete.py
+++ b/kfet/autocomplete.py
@@ -77,3 +77,29 @@ def account_create(request):
data['options'] = options
return render(request, "kfet/account_create_autocomplete.html", data)
+
+
+def account_search(request):
+ if "q" not in request.GET:
+ raise Http404
+ q = request.GET.get("q")
+ words = q.split()
+
+ data = {'q': q}
+
+ for word in words:
+ query = Account.objects.filter(
+ Q(cofprofile__user__username__icontains=word) |
+ Q(cofprofile__user__first_name__icontains=word) |
+ Q(cofprofile__user__last_name__icontains=word)
+ ).distinct()
+
+ query = [(account.trigramme, account.cofprofile.user.get_full_name())
+ for account in query]
+
+ data['accounts'] = query
+ options = len(query)
+
+ data['options'] = options
+
+ return render(request, 'kfet/account_search_autocomplete.html', data)
diff --git a/kfet/templates/kfet/account_search_autocomplete.html b/kfet/templates/kfet/account_search_autocomplete.html
new file mode 100644
index 00000000..22e2cca3
--- /dev/null
+++ b/kfet/templates/kfet/account_search_autocomplete.html
@@ -0,0 +1,14 @@
+{% load kfet_tags %}
+
+
+ {% if accounts %}
+ {% for trigramme, user in accounts %}
+ - {{ user|highlight_text:q }} ({{ trigramme }})
+ {% endfor %}
+ {% elif not q %}
+ - Pas de recherche, pas de résultats !
+ {% else %}
+ - Aucune correspondance trouvée :-(
+ {% endif %}
+
+
diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html
index 26c98e55..6178f039 100644
--- a/kfet/templates/kfet/kpsul.html
+++ b/kfet/templates/kfet/kpsul.html
@@ -4,6 +4,7 @@
{% block extra_head %}
+
@@ -256,12 +257,48 @@ $(document).ready(function() {
buttons += '';
} else {
var url_base = '{% url 'kfet.account' %}'
- buttons += '';
+ buttons += '';
}
}
account_container.find('.buttons').html(buttons);
}
+ // Search for an account
+ function searchAccount() {
+ var content = '' ;
+ $.dialog({
+ title: 'Recherche de compte',
+ content: content,
+ backgroundDismiss: true,
+ animation: 'top',
+ closeAnimation: 'bottom',
+ keyboardEnabled: true,
+ onOpen: function() {
+ var that=this ;
+ $('input#search_autocomplete').yourlabsAutocomplete({
+ url: '{% url 'kfet.account.search.autocomplete' %}',
+ minimumCharacters: 2,
+ id: 'search_autocomplete',
+ choiceSelector: '.choice',
+ placeholder: "Chercher un utilisateur K-Fêt",
+ box: $(".yourlabs-autocomplete"),
+ });
+ $('input#search_autocomplete').bind(
+ 'selectChoice',
+ function(e, choice, autocomplete) {
+ autocomplete.hide() ;
+ triInput.val(choice.find('.trigramme').text()) ;
+ triInput.trigger('input') ;
+ that.close() ;
+ });
+ }
+ });
+ }
+
+ account_container.on('click', '.search', function () {
+ searchAccount() ;
+ }) ;
+
// Clear data
function resetAccountData() {
account_data = account_data_default;