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) {
/* FIXME: Does not work well. */
setTimeout(function() {
$("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).removeClass("marked");
} else {
$(this).show();
}
/* Full match */
if($(this).children("span.name").text() == typed) {
$(this).addClass("marked");
var full_match = name.toLowerCase() == typed.toLowerCase();
// FIXME: needs one more char.
//var single_match = $("li.customer:visible").length == 1;
//console.log(full_match, single_match);
//if(full_match || single_match) {
if(full_match) {
$(this).addClass("marked");
} else {
$(this).removeClass("marked");
}
}
});
}, 50);
}
/* Customer search */
$('.typeahead').typeahead();
$('#id_customer_name').keydown(function(event) {
//$('.typeahead').typeahead();
$('#id_customer_typeahead').keyup(function(event) {
filter_customers(event.srcElement.value);
});
/* Customer selection */
+13 -7
View File
@@ -21,19 +21,25 @@ $(document).ready(function() {
});
}
function filter_customers(typed) {
/* FIXME: Does not work. */
console.log(typed);
setTimeout(function() {
$("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).removeClass("marked");
} else {
$(this).show();
}
/* Full match */
if($(this).children("span.name").text() == typed) {
$(this).addClass("marked");
var full_match = name.toLowerCase() == typed.toLowerCase();
// FIXME: needs one more char.
//var single_match = $("li.customer:visible").length == 1;
//console.log(full_match, single_match);
//if(full_match || single_match) {
if(full_match) {
$(this).addClass("marked");
} else {
$(this).removeClass("marked");
}
}
});
}, 50);
+1 -1
View File
@@ -52,7 +52,7 @@
</section>
{% endblock %}
{% 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>
{% endblock %}