Manage group contributors trash
This commit is contained in:
parent
7641bfd1ef
commit
66b82a89ed
3 changed files with 120 additions and 8 deletions
44
inc/myco.js
44
inc/myco.js
|
@ -233,6 +233,48 @@ on_confirm_contribution_restore=function(data) {
|
||||||
view_group(data.group,data.contribution.contributor.email);
|
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('<tr><td colspan=3>Aucun participant</td></tr>');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (idx in contributors) {
|
||||||
|
tbody.append('<tr data-email="'+contributors[idx].email+'"><td>'+contributors[idx].name+'</td><td><button type="button" class="btn btn-default contributor_restore_btn"><span class="glyphicon glyphicon-share"></span></button></td></tr>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#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
|
* Add/Edit/remove contributor
|
||||||
******************************/
|
******************************/
|
||||||
|
@ -728,6 +770,7 @@ $( document ).ready( function() {
|
||||||
$("#add_contributor_modal form").bind('submit',on_valid_add_contributor_modal);
|
$("#add_contributor_modal form").bind('submit',on_valid_add_contributor_modal);
|
||||||
|
|
||||||
$('#edit_contributor_btn').bind('click',on_edit_contributor_btn_click);
|
$('#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);
|
$('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
|
||||||
|
|
||||||
$('#add_contribution_btn').bind('click',on_click_add_contribution_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);
|
$("#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 #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);
|
$('#trash_group_btn').bind('click',on_trash_group_btn_click);
|
||||||
$('#remove_group_btn').bind('click',on_remove_group_btn_click);
|
$('#remove_group_btn').bind('click',on_remove_group_btn_click);
|
||||||
|
|
|
@ -118,6 +118,7 @@ function Group(uuid,name,data) {
|
||||||
this.uuid=uuid || generate_uuid();
|
this.uuid=uuid || generate_uuid();
|
||||||
this.name=name || false;
|
this.name=name || false;
|
||||||
this.contributors={};
|
this.contributors={};
|
||||||
|
this.deletedContributors={};
|
||||||
this.contributions={};
|
this.contributions={};
|
||||||
this.deletedContributions={};
|
this.deletedContributions={};
|
||||||
|
|
||||||
|
@ -139,6 +140,7 @@ function Group(uuid,name,data) {
|
||||||
'uuid': this.uuid,
|
'uuid': this.uuid,
|
||||||
'name': encodeURIComponent(this.name),
|
'name': encodeURIComponent(this.name),
|
||||||
'contributors': contributors,
|
'contributors': contributors,
|
||||||
|
'deletedContributors': this.deletedContributors,
|
||||||
'contributions': contributions,
|
'contributions': contributions,
|
||||||
'deletedContributions': this.deletedContributions
|
'deletedContributions': this.deletedContributions
|
||||||
};
|
};
|
||||||
|
@ -148,7 +150,37 @@ function Group(uuid,name,data) {
|
||||||
* Contributors
|
* Contributors
|
||||||
*/
|
*/
|
||||||
this.removeContributor=function(c) {
|
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];
|
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) {
|
this.contributorByName=function(name) {
|
||||||
|
@ -235,8 +267,8 @@ function Group(uuid,name,data) {
|
||||||
this.contributions[uuid]=c;
|
this.contributions[uuid]=c;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.deleteContribution=function(uuid) {
|
this.deleteContribution=function(uuid,time) {
|
||||||
this.contributions[uuid].lastChange=new Date().getTime();
|
this.contributions[uuid].lastChange=time || new Date().getTime();
|
||||||
this.deletedContributions[uuid]=this.contributions[uuid].export();
|
this.deletedContributions[uuid]=this.contributions[uuid].export();
|
||||||
delete this.contributions[uuid];
|
delete this.contributions[uuid];
|
||||||
}
|
}
|
||||||
|
@ -247,6 +279,13 @@ function Group(uuid,name,data) {
|
||||||
delete this.deletedContributions[uuid];
|
delete this.deletedContributions[uuid];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.importContributor=function(data) {
|
||||||
|
return new Contributor(
|
||||||
|
decodeURIComponent(data.name),
|
||||||
|
data.email
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.importContribution=function(data) {
|
this.importContribution=function(data) {
|
||||||
return new Contribution(
|
return new Contribution(
|
||||||
this.contributorByEmail(data.contributor),
|
this.contributorByEmail(data.contributor),
|
||||||
|
@ -306,10 +345,12 @@ function Group(uuid,name,data) {
|
||||||
this.name=data.name;
|
this.name=data.name;
|
||||||
if (jQuery.type(data.contributors) == 'object') {
|
if (jQuery.type(data.contributors) == 'object') {
|
||||||
for (email in data.contributors) {
|
for (email in data.contributors) {
|
||||||
this.contributors[email]=new Contributor(
|
this.contributors[email]=this.importContributor(data.contributors[email]);
|
||||||
decodeURIComponent(data.contributors[email].name),
|
}
|
||||||
data.contributors[email].email
|
}
|
||||||
);
|
if (jQuery.type(data.deletedContributors) == 'object') {
|
||||||
|
for (email in data.deletedContributors) {
|
||||||
|
this.deletedContributors[email]=data.deletedContributors[email];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jQuery.type(data.contributions) == 'object') {
|
if (jQuery.type(data.contributions) == 'object') {
|
||||||
|
|
31
index.html
31
index.html
|
@ -123,9 +123,15 @@ body{
|
||||||
<select id='contributor' class="form-control">
|
<select id='contributor' class="form-control">
|
||||||
</select>
|
</select>
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button type="button" class="btn btn-primary" id='edit_contributor_btn'><span class='glyphicon glyphicon-edit'></span></button>
|
|
||||||
<button type="button" class="btn btn-primary" id='del_contributor_btn'><span class='glyphicon glyphicon-trash'></span></button>
|
|
||||||
<button type="button" class="btn btn-primary" id='add_contributor_btn'><span class='glyphicon glyphicon-plus'></span></button>
|
<button type="button" class="btn btn-primary" id='add_contributor_btn'><span class='glyphicon glyphicon-plus'></span></button>
|
||||||
|
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
|
||||||
|
<span class="glyphicon glyphicon-cog"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li><a id='edit_contributor_btn'><span class='glyphicon glyphicon-edit'></span> Modifier</span></a></li>
|
||||||
|
<li><a id='trash_contributor_btn'><span class='glyphicon glyphicon-trash'></span> Corbeille</span></a></li>
|
||||||
|
<li><a id='del_contributor_btn'><span class='glyphicon glyphicon-floppy-remove'></span> Supprimer le participant</span></a></li>
|
||||||
|
</ul>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -196,6 +202,27 @@ body{
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id='view-group-trash-contributors' class='part'>
|
||||||
|
<h1>Corbeille</h1>
|
||||||
|
<button type="button" class="btn btn-default" id="go-back-group"><span class="glyphicon glyphicon-arrow-left"> Retour</span></button>
|
||||||
|
<table id='trash' class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Participant</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Nom</td>
|
||||||
|
<td>
|
||||||
|
<button type="button" class="btn btn-default contribution_restore_btn"><span class='glyphicon glyphicon-share'></span></button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" id="add_group_modal" tabindex="-1" role="dialog" aria-labelledby="addGroupModal" aria-hidden="true">
|
<div class="modal fade" id="add_group_modal" tabindex="-1" role="dialog" aria-labelledby="addGroupModal" aria-hidden="true">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
|
|
Loading…
Reference in a new issue