From 903c4f071baa1f7e7e28d13bb265ba8e975062a1 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 16 Jan 2014 20:40:05 +0100 Subject: [PATCH] Sort contribution by date on display --- inc/myco.js | 11 ++++++----- inc/myco_objects.js | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/inc/myco.js b/inc/myco.js index b8eca66..c0d9c4e 100644 --- a/inc/myco.js +++ b/inc/myco.js @@ -157,18 +157,19 @@ show_contributions=function(group,contributor_name) { tbody.html(''); total=$($('#view-group #total-value')[0]); contributions=group.contributionsByContributorName(contributor_name); + contributions.reverse(); if (contributions.length==0) { tbody.append('Aucune contributions'); total.html('0,00 €'); } else { sum=0; - for (uuid in contributions) { - col_actions='
'; - tbody.append(''+contributions[uuid].getTitle()+''+contributions[uuid].cost+' €'+col_actions+''); - sum+=contributions[uuid].cost; + for (idx in contributions) { + col_actions='
'; + tbody.append(''+contributions[idx].getTitle()+''+contributions[idx].cost+' €'+col_actions+''); + sum+=contributions[idx].cost; } - total.html(sum+' €'); + total.html(sum.toFixed(2)+' €'); } $('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click); diff --git a/inc/myco_objects.js b/inc/myco_objects.js index b64ecdb..1d8cfcc 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -180,12 +180,23 @@ function Group(uuid,name,data) { * Contributions */ this.contributionsByContributorName=function(name) { - var ret={}; + var ret=[]; for (uuid in this.contributions) { if (this.contributions[uuid].contributor.name==name) { - ret[uuid]=this.contributions[uuid]; + ret.push(this.contributions[uuid]); } } + ret.sort(function(a,b) { + if (a.date==b.date) { + return 0; + } + else if(a.datesum) { min=sum;