diff --git a/inc/myco.js b/inc/myco.js index 092a873..2e030af 100644 --- a/inc/myco.js +++ b/inc/myco.js @@ -129,22 +129,28 @@ view_home=function() { /**************** * View group ****************/ -view_group=function(group) { +view_group=function(group,contributor_email) { $('#view-group').data('uuid',group.uuid); $('#view-group h1 span:first').html(group.name); - set_contributors(group); + set_contributors(group,contributor_email); on_contributor_change(); view_part('#view-group'); } -set_contributors=function(group) { +set_contributors=function(group,contributor_email) { $('#view-group #contributor option').remove(); if(group.contributors.length==0) { $('#view-group #contributor').append(''); } else { for (email in group.contributors) { - $('#view-group #contributor').append(''); + if (email == contributor_email) { + sel=' selected'; + } + else { + sel=''; + } + $('#view-group #contributor').append(''); } } } @@ -177,6 +183,56 @@ show_contributions=function(group,contributor_email) { $('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click); } +/***************************** + * Trash + *****************************/ + +on_trash_group_btn_click=function(e) { + group=groups[$('#view-group').data('uuid')]; + contributor_email=$('#view-group #contributor')[0].value; + view_group_trash(group,contributor_email); +} + +on_go_back_group_btn_click=function(e) { + group=groups[$('#view-group-trash').data('uuid')]; + contributor_email=$('#view-group-trash').data('contributor-email'); + view_group(group,contributor_email); +} + +view_group_trash=function(group,contributor_email) { + $('#view-group-trash').data('uuid',group.uuid); + $('#view-group-trash').data('contributor-email',contributor_email); + var tbody=$('#view-group-trash #trash tbody'); + tbody.html(''); + contributions=group.deletedContributionsByContributorEmail(contributor_email); + contributions.reverse(); + if (contributions.length==0) { + tbody.append('Aucune contributions'); + } + else { + for (idx in contributions) { + tbody.append(''+contributions[idx].getTitle()+''+contributions[idx].cost.toFixed(2)+' €
'+moment(contributions[idx].date).format('DD/MM/YYYY')+''); + } + } + + $('#view-group-trash .contribution_restore_btn').bind('click',on_contribution_restore_btn_click); + + view_part('#view-group-trash'); +} + +on_contribution_restore_btn_click=function(e) { + var group=groups[$('#view-group-trash').data('uuid')]; + contribution_uuid=$($(e.target).parents('tr')[0]).data('uuid'); + contribution=group.importContribution(group.deletedContributions[contribution_uuid]); + myconfirm('Etes-vous sûre de vouloir restaurer la participation '+contribution.getTitle()+' de '+contribution.contributor.name+' ?',on_confirm_contribution_restore,null,{'group':group,'contribution_uuid':contribution_uuid, 'contribution': contribution} ); +} + +on_confirm_contribution_restore=function(data) { + data.group.restoreContribution(data.contribution_uuid); + groups.save(); + view_group(data.group,data.contribution.contributor.email); +} + /****************************** * Add/Edit/remove contributor ******************************/ @@ -671,6 +727,9 @@ $( document ).ready( function() { $("#display_balance_btn").bind('click',on_display_balance_btn_click); + $("#view-group-trash #go-back-group").bind('click',on_go_back_group_btn_click); + + $('#trash_group_btn').bind('click',on_trash_group_btn_click); $('#remove_group_btn').bind('click',on_remove_group_btn_click); view_home(); pleaseWaitHide(); diff --git a/inc/myco_objects.js b/inc/myco_objects.js index 8fa9609..13da5c1 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -198,6 +198,34 @@ function Group(uuid,name,data) { return ret; } + this.deletedContributionsByContributorEmail=function(email) { + var ret=[]; + for (uuid in this.deletedContributions) { + if (this.deletedContributions[uuid].contributor==email) { + ret.push(new Contribution( + this.contributorByEmail(email), + this.deletedContributions[uuid].cost, + decodeURIComponent(this.deletedContributions[uuid].title), + this.deletedContributions[uuid].date, + uuid, + this.deletedContributions[uuid].lastChange + )); + } + } + ret.sort(function(a,b) { + if (a.lastChange==b.lastChange) { + return 0; + } + else if(a.lastChange @@ -171,6 +172,30 @@ body{ +
+

Corbeille

+ + + + + + + + + + + + + + + + +
DépenceCoûtActions
LabelXXX,XX€ + +
+ +
+