Filtering fixes

This commit is contained in:
nikolark committed 2012-11-11 00:06:12 +01:00
1 parent 3e11ea9b75
commit 3ae6a0675a
3 files changed
+29 -16

No files matched your search

+15 -8
View File
@@ -6,25 +6,32 @@ $(document).ready(function() {
}); });
} }
function filter_customers(typed) { function filter_customers(typed) {
/* FIXME: Does not work well. */
setTimeout(function() { setTimeout(function() {
$("li.customer").each(function(i) { $("li.customer").each(function(i) {
if($(this).children("span.name").text().indexOf(typed) == -1) { var pattern = new RegExp(typed,"i");
var name = $(this).children("span.name").text();
if(!pattern.test(name)) {
$(this).hide(); $(this).hide();
$(this).removeClass("marked"); $(this).removeClass("marked");
} else { } else {
$(this).show(); $(this).show();
} var full_match = name.toLowerCase() == typed.toLowerCase();
/* Full match */ // FIXME: needs one more char.
if($(this).children("span.name").text() == typed) { //var single_match = $("li.customer:visible").length == 1;
$(this).addClass("marked"); //console.log(full_match, single_match);
//if(full_match || single_match) {
if(full_match) {
$(this).addClass("marked");
} else {
$(this).removeClass("marked");
}
} }
}); });
}, 50); }, 50);
} }
/* Customer search */ /* Customer search */
$('.typeahead').typeahead(); //$('.typeahead').typeahead();
$('#id_customer_name').keydown(function(event) { $('#id_customer_typeahead').keyup(function(event) {
filter_customers(event.srcElement.value); filter_customers(event.srcElement.value);
}); });
/* Customer selection */ /* Customer selection */
+13 -7
View File
@@ -21,19 +21,25 @@ $(document).ready(function() {
}); });
} }
function filter_customers(typed) { function filter_customers(typed) {
/* FIXME: Does not work. */
console.log(typed);
setTimeout(function() { setTimeout(function() {
$("li.customer").each(function(i) { $("li.customer").each(function(i) {
if($(this).children("span.name").text().indexOf(typed) == -1) { var pattern = new RegExp(typed,"i");
var name = $(this).children("span.name").text();
if(!pattern.test(name)) {
$(this).hide(); $(this).hide();
$(this).removeClass("marked"); $(this).removeClass("marked");
} else { } else {
$(this).show(); $(this).show();
} var full_match = name.toLowerCase() == typed.toLowerCase();
/* Full match */ // FIXME: needs one more char.
if($(this).children("span.name").text() == typed) { //var single_match = $("li.customer:visible").length == 1;
$(this).addClass("marked"); //console.log(full_match, single_match);
//if(full_match || single_match) {
if(full_match) {
$(this).addClass("marked");
} else {
$(this).removeClass("marked");
}
} }
}); });
}, 50); }, 50);
+1 -1
View File
@@ -52,7 +52,7 @@
</section> </section>
{% endblock %} {% endblock %}
{% block tailinc %} {% block tailinc %}
<script src="{{ STATIC_URL }}js/bootstrap-typeahead.js"></script> <!--<script src="{{ STATIC_URL }}js/bootstrap-typeahead.js"></script>-->
<script src="{{ STATIC_URL }}js/deposit.js"></script> <script src="{{ STATIC_URL }}js/deposit.js"></script>
{% endblock %} {% endblock %}