Sort contribution by date on display
This commit is contained in:
parent
1380086723
commit
903c4f071b
2 changed files with 21 additions and 9 deletions
11
inc/myco.js
11
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('<tr><td colspan=3>Aucune contributions</td></tr>');
|
||||
total.html('0,00 €');
|
||||
}
|
||||
else {
|
||||
sum=0;
|
||||
for (uuid in contributions) {
|
||||
col_actions='<td><div class="btn-group" data-uuid="'+contributions[uuid].uuid+'"><button type="button" class="btn btn-default contribution_edit_btn"><span class="glyphicon glyphicon-edit"></span></button><button type="button" class="btn btn-default contribution_delete_btn"><span class="glyphicon glyphicon-trash"></span></button></div></td>';
|
||||
tbody.append('<tr><td>'+contributions[uuid].getTitle()+'</td><td>'+contributions[uuid].cost+' €</td>'+col_actions+'</tr>');
|
||||
sum+=contributions[uuid].cost;
|
||||
for (idx in contributions) {
|
||||
col_actions='<td><div class="btn-group" data-uuid="'+contributions[idx].uuid+'"><button type="button" class="btn btn-default contribution_edit_btn"><span class="glyphicon glyphicon-edit"></span></button><button type="button" class="btn btn-default contribution_delete_btn"><span class="glyphicon glyphicon-trash"></span></button></div></td>';
|
||||
tbody.append('<tr><td>'+contributions[idx].getTitle()+'</td><td>'+contributions[idx].cost+' €</td>'+col_actions+'</tr>');
|
||||
sum+=contributions[idx].cost;
|
||||
}
|
||||
total.html(sum+' €');
|
||||
total.html(sum.toFixed(2)+' €');
|
||||
}
|
||||
|
||||
$('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click);
|
||||
|
|
|
@ -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.date<b.date) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -216,8 +227,8 @@ function Group(uuid,name,data) {
|
|||
var sum=0;
|
||||
c=this.contributors[idx].name;
|
||||
cl=this.contributionsByContributorName(c);
|
||||
for (uuid in cl) {
|
||||
sum+=cl[uuid].cost;
|
||||
for (idx in cl) {
|
||||
sum+=cl[idx].cost;
|
||||
}
|
||||
if (min==-1 || min>sum) {
|
||||
min=sum;
|
||||
|
|
Loading…
Reference in a new issue