diff --git a/inc/myco.js b/inc/myco.js index 576ad50..7206271 100644 --- a/inc/myco.js +++ b/inc/myco.js @@ -233,6 +233,48 @@ on_confirm_contribution_restore=function(data) { view_group(data.group,data.contribution.contributor.email); } +on_trash_group_contributors_btn_click=function(e) { + group=groups[$('#view-group').data('uuid')]; + view_group_trash_contributors(group); +} + +on_go_back_group_trash_contributors_btn_click=function(e) { + group=groups[$('#view-group-trash-contributors').data('uuid')]; + view_group(group); +} + +view_group_trash_contributors=function(group) { + $('#view-group-trash-contributors').data('uuid',group.uuid); + var tbody=$('#view-group-trash-contributors #trash tbody'); + tbody.html(''); + contributors=group.getDeletedContributors(); + if (contributors.length==0) { + tbody.append('Aucun participant'); + } + else { + for (idx in contributors) { + tbody.append(''+contributors[idx].name+''); + } + } + + $('#view-group-trash-contributors .contributor_restore_btn').bind('click',on_contributor_restore_btn_click); + + view_part('#view-group-trash-contributors'); +} + +on_contributor_restore_btn_click=function(e) { + var group=groups[$('#view-group-trash-contributors').data('uuid')]; + contributor_email=$($(e.target).parents('tr')[0]).data('email'); + contributor=group.importContributor(group.deletedContributors[contributor_email]); + myconfirm('Etes-vous sûre de vouloir restaurer '+contributor.name+' ?',on_confirm_contributor_restore,null,{'group':group,'contributor_email':contributor_email, 'contributor': contributor} ); +} + +on_confirm_contributor_restore=function(data) { + data.group.restoreContributor(data.contributor_email); + groups.save(); + view_group(data.group,data.contributor_email); +} + /****************************** * Add/Edit/remove contributor ******************************/ @@ -728,6 +770,7 @@ $( document ).ready( function() { $("#add_contributor_modal form").bind('submit',on_valid_add_contributor_modal); $('#edit_contributor_btn').bind('click',on_edit_contributor_btn_click); + $('#trash_contributor_btn').bind('click',on_trash_group_contributors_btn_click); $('#del_contributor_btn').bind('click',on_click_del_contributor_btn); $('#add_contribution_btn').bind('click',on_click_add_contribution_btn); @@ -739,6 +782,7 @@ $( 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); + $("#view-group-trash-contributors #go-back-group").bind('click',on_go_back_group_trash_contributors_btn_click); $('#trash_group_btn').bind('click',on_trash_group_btn_click); $('#remove_group_btn').bind('click',on_remove_group_btn_click); diff --git a/inc/myco_objects.js b/inc/myco_objects.js index 13da5c1..159baf1 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -118,6 +118,7 @@ function Group(uuid,name,data) { this.uuid=uuid || generate_uuid(); this.name=name || false; this.contributors={}; + this.deletedContributors={}; this.contributions={}; this.deletedContributions={}; @@ -139,6 +140,7 @@ function Group(uuid,name,data) { 'uuid': this.uuid, 'name': encodeURIComponent(this.name), 'contributors': contributors, + 'deletedContributors': this.deletedContributors, 'contributions': contributions, 'deletedContributions': this.deletedContributions }; @@ -148,7 +150,37 @@ function Group(uuid,name,data) { * Contributors */ this.removeContributor=function(c) { + this.deletedContributors[c.email]=c.export(); + time=new Date().getTime(); + this.deletedContributors[c.email].deletionTime=time; + contributions=this.contributionsByContributorEmail(c.email); + for (idx in contributions) { + this.deleteContribution(contributions[idx].uuid,time); + } delete this.contributors[c.email]; + return true; + } + + this.restoreContributor=function(email) { + if (email in this.contributors) return; + if (! email in this.deletedContributors) return; + this.contributors[email]=this.importContributor(this.deletedContributors[email]); + contributions=this.deletedContributionsByContributorEmail(email); + for (idx in contributions) { + if (contributions[idx].lastChange==this.deletedContributors[email].deletionTime) { + this.restoreContribution(contributions[idx].uuid); + } + } + delete this.deletedContributors[email]; + return true; + } + + this.getDeletedContributors=function() { + var ret=[]; + for (email in this.deletedContributors) { + ret.push(this.importContributor(this.deletedContributors[email])); + } + return ret; } this.contributorByName=function(name) { @@ -235,8 +267,8 @@ function Group(uuid,name,data) { this.contributions[uuid]=c; } - this.deleteContribution=function(uuid) { - this.contributions[uuid].lastChange=new Date().getTime(); + this.deleteContribution=function(uuid,time) { + this.contributions[uuid].lastChange=time || new Date().getTime(); this.deletedContributions[uuid]=this.contributions[uuid].export(); delete this.contributions[uuid]; } @@ -247,6 +279,13 @@ function Group(uuid,name,data) { delete this.deletedContributions[uuid]; } + this.importContributor=function(data) { + return new Contributor( + decodeURIComponent(data.name), + data.email + ); + } + this.importContribution=function(data) { return new Contribution( this.contributorByEmail(data.contributor), @@ -306,10 +345,12 @@ function Group(uuid,name,data) { this.name=data.name; if (jQuery.type(data.contributors) == 'object') { for (email in data.contributors) { - this.contributors[email]=new Contributor( - decodeURIComponent(data.contributors[email].name), - data.contributors[email].email - ); + this.contributors[email]=this.importContributor(data.contributors[email]); + } + } + if (jQuery.type(data.deletedContributors) == 'object') { + for (email in data.deletedContributors) { + this.deletedContributors[email]=data.deletedContributors[email]; } } if (jQuery.type(data.contributions) == 'object') { diff --git a/index.html b/index.html index 6822103..6a63372 100644 --- a/index.html +++ b/index.html @@ -123,9 +123,15 @@ body{ - - + + @@ -196,6 +202,27 @@ body{ +
+

Corbeille

+ + + + + + + + + + + + + + +
ParticipantActions
Nom + +
+
+