Add search contributions feature

This commit is contained in:
Benjamin Renard 2014-10-13 00:20:28 +02:00
parent 384ead0025
commit 2272ff551b
3 changed files with 37 additions and 3 deletions

View file

@ -172,12 +172,14 @@ on_contributor_change=function(e) {
show_contributions(groups[$('#view-group').data('uuid')],$('#view-group #contributor')[0].value);
}
show_contributions=function(group,contributor_email) {
show_contributions=function(group,contributor_email,contributions) {
var tbody=$($('#view-group #contributions tbody')[0]);
tbody.html('');
total=$($('#view-group #total-value')[0]);
contributions=group.contributionsByContributorEmail(contributor_email);
contributions.reverse();
if (!contributions) {
contributions=group.contributionsByContributorEmail(contributor_email);
contributions.reverse();
}
if (contributions.length==0) {
tbody.append('<tr><td colspan=3>Aucune contributions</td></tr>');
total.html('0,00 €');
@ -297,6 +299,20 @@ on_categories_group_add_btn_click=function(e) {
}
}
on_nav_search_form_submit=function(e) {
e.preventDefault();
}
on_nav_search_form_input=function(e) {
var ipt=$(e.target);
var pattern=ipt.val();
group=groups[$('#view-group').data('uuid')];
var found=group.searchContributions(pattern);
show_contributions(group,null,found);
}
/*****************************
* Trash
@ -953,6 +969,8 @@ $( document ).ready( function() {
$('#categories_group_btn').bind('click',on_categories_group_btn_click);
$('#trash_group_btn').bind('click',on_trash_group_btn_click);
$('#remove_group_btn').bind('click',on_remove_group_btn_click);
$('#nav-search-form').bind('submit',on_nav_search_form_submit);
$('#nav-search-form input').bind('input',on_nav_search_form_input);
$('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
$("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);

View file

@ -336,6 +336,17 @@ function Group(uuid,name,data) {
cb(matches);
};
}
this.searchContributions=function(pattern) {
var ret=[];
substrRegex = new RegExp(pattern, 'i');
for (uuid in this.contributions) {
if (substrRegex.test(this.contributions[uuid].title) || substrRegex.test(this.contributions[uuid].cost)) {
ret.push(this.contributions[uuid]);
}
}
return ret;
}
this.getContributionsByCategory=function (category) {
var ret={};

View file

@ -277,6 +277,11 @@ span.cat-color {
<button class="btn btn-default" id='display_balance_btn'><span class='glyphicon glyphicon-euro'></span> Balance</span></button>
</div>
<div class="collapse navbar-collapse" id="bottom-navbar-collapse-1">
<form class="navbar-form navbar-right" role="search" id='nav-search-form'>
<div class="form-group">
<input type="text" class="form-control" placeholder="Rechercher">
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a id='categories_group_btn'><span class='glyphicon glyphicon-th-list'></span> Catégories</span></a></li>
<li><a id='trash_group_btn'><span class='glyphicon glyphicon-trash'></span> Corbeille</span></a></li>