Add possibility to view trash
This commit is contained in:
parent
fe92325853
commit
bb84db00c0
3 changed files with 134 additions and 13 deletions
67
inc/myco.js
67
inc/myco.js
|
@ -129,22 +129,28 @@ view_home=function() {
|
||||||
/****************
|
/****************
|
||||||
* View group
|
* View group
|
||||||
****************/
|
****************/
|
||||||
view_group=function(group) {
|
view_group=function(group,contributor_email) {
|
||||||
$('#view-group').data('uuid',group.uuid);
|
$('#view-group').data('uuid',group.uuid);
|
||||||
$('#view-group h1 span:first').html(group.name);
|
$('#view-group h1 span:first').html(group.name);
|
||||||
set_contributors(group);
|
set_contributors(group,contributor_email);
|
||||||
on_contributor_change();
|
on_contributor_change();
|
||||||
view_part('#view-group');
|
view_part('#view-group');
|
||||||
}
|
}
|
||||||
|
|
||||||
set_contributors=function(group) {
|
set_contributors=function(group,contributor_email) {
|
||||||
$('#view-group #contributor option').remove();
|
$('#view-group #contributor option').remove();
|
||||||
if(group.contributors.length==0) {
|
if(group.contributors.length==0) {
|
||||||
$('#view-group #contributor').append('<option>Aucun participant</option>');
|
$('#view-group #contributor').append('<option>Aucun participant</option>');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (email in group.contributors) {
|
for (email in group.contributors) {
|
||||||
$('#view-group #contributor').append('<option value="'+email+'">'+group.contributors[email].name+'</option>');
|
if (email == contributor_email) {
|
||||||
|
sel=' selected';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sel='';
|
||||||
|
}
|
||||||
|
$('#view-group #contributor').append('<option value="'+email+'"'+sel+'>'+group.contributors[email].name+'</option>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +183,56 @@ show_contributions=function(group,contributor_email) {
|
||||||
$('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click);
|
$('.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('<tr><td colspan=3>Aucune contributions</td></tr>');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (idx in contributions) {
|
||||||
|
tbody.append('<tr data-uuid="'+contributions[idx].uuid+'"><td>'+contributions[idx].getTitle()+'</td><td>'+contributions[idx].cost.toFixed(2)+' €<br/><span class="date">'+moment(contributions[idx].date).format('DD/MM/YYYY')+'</span></td><td><button type="button" class="btn btn-default contribution_restore_btn"><span class="glyphicon glyphicon-share"></span></button></td></tr>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#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
|
* Add/Edit/remove contributor
|
||||||
******************************/
|
******************************/
|
||||||
|
@ -671,6 +727,9 @@ $( 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);
|
||||||
|
|
||||||
|
$('#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);
|
||||||
view_home();
|
view_home();
|
||||||
pleaseWaitHide();
|
pleaseWaitHide();
|
||||||
|
|
|
@ -198,6 +198,34 @@ function Group(uuid,name,data) {
|
||||||
return ret;
|
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<b.lastChange) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
this.addContribution=function(c) {
|
this.addContribution=function(c) {
|
||||||
this.contributions[c.uuid]=c;
|
this.contributions[c.uuid]=c;
|
||||||
}
|
}
|
||||||
|
@ -213,6 +241,22 @@ function Group(uuid,name,data) {
|
||||||
delete this.contributions[uuid];
|
delete this.contributions[uuid];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.restoreContribution=function(uuid) {
|
||||||
|
this.deletedContributions[uuid].lastChange=new Date().getTime();
|
||||||
|
this.contributions[uuid]=this.importContribution(this.deletedContributions[uuid]);
|
||||||
|
delete this.deletedContributions[uuid];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.importContribution=function(data) {
|
||||||
|
return new Contribution(
|
||||||
|
this.contributorByEmail(data.contributor),
|
||||||
|
data.cost,
|
||||||
|
decodeURIComponent(data.title),
|
||||||
|
data.date,
|
||||||
|
data.uuid,
|
||||||
|
data.lastChange
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Balance
|
* Balance
|
||||||
|
@ -270,14 +314,7 @@ function Group(uuid,name,data) {
|
||||||
}
|
}
|
||||||
if (jQuery.type(data.contributions) == 'object') {
|
if (jQuery.type(data.contributions) == 'object') {
|
||||||
for (uuid in data.contributions) {
|
for (uuid in data.contributions) {
|
||||||
this.contributions[uuid]=new Contribution(
|
this.contributions[uuid]=this.importContribution(data.contributions[uuid]);
|
||||||
this.contributorByEmail(data.contributions[uuid].contributor),
|
|
||||||
data.contributions[uuid].cost,
|
|
||||||
decodeURIComponent(data.contributions[uuid].title),
|
|
||||||
data.contributions[uuid].date,
|
|
||||||
uuid,
|
|
||||||
data.contributions[uuid].lastChange
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jQuery.type(data.deletedContributions) == 'object') {
|
if (jQuery.type(data.deletedContributions) == 'object') {
|
||||||
|
|
27
index.html
27
index.html
|
@ -138,7 +138,8 @@ body{
|
||||||
<span class="glyphicon glyphicon-cog"></span>
|
<span class="glyphicon glyphicon-cog"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a id='remove_group_btn'><span class='glyphicon glyphicon-trash'></span> Supprimer le groupe</span></a></li>
|
<li><a id='trash_group_btn'><span class='glyphicon glyphicon-trash'></span> Corbeille</span></a></li>
|
||||||
|
<li><a id='remove_group_btn'><span class='glyphicon glyphicon-floppy-remove'></span> Supprimer le groupe</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -171,6 +172,30 @@ body{
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id='view-group-trash' 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>Dépence</th>
|
||||||
|
<th>Coût</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Label</td>
|
||||||
|
<td>XXX,XX€</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