From 2272ff551bf4e65a2e3436be802033f3b6f51da7 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 13 Oct 2014 00:20:28 +0200 Subject: [PATCH] Add search contributions feature --- inc/myco.js | 24 +++++++++++++++++++++--- inc/myco_objects.js | 11 +++++++++++ index.html | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/inc/myco.js b/inc/myco.js index 2bc3371..da00268 100644 --- a/inc/myco.js +++ b/inc/myco.js @@ -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('Aucune contributions'); 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); diff --git a/inc/myco_objects.js b/inc/myco_objects.js index f23d72b..5bac102 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -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={}; diff --git a/index.html b/index.html index 139ec09..7c5ad9a 100644 --- a/index.html +++ b/index.html @@ -277,6 +277,11 @@ span.cat-color {