Add edit contributor feature
This commit is contained in:
parent
0da244586b
commit
936a009ced
3 changed files with 45 additions and 8 deletions
37
inc/myco.js
37
inc/myco.js
|
@ -105,11 +105,14 @@ show_contributions=function(group,contributor_name) {
|
|||
$('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click);
|
||||
}
|
||||
|
||||
/*********************
|
||||
* Add contributor
|
||||
*********************/
|
||||
/******************************
|
||||
* Add/Edit/remove contributor
|
||||
******************************/
|
||||
on_click_add_contributor_btn=function() {
|
||||
$('#add_contributor_modal #group_name')[0].value=$('#view-group #group_name')[0].value;
|
||||
$($('#add_contributor_modal h4')[0]).html('Ajouter un participant');
|
||||
$($('#add_contributor_modal #add_contributor_submit')[0]).html('Ajouter');
|
||||
$('#view-group #edit_id')[0].value='-1';
|
||||
$('#add_contributor_modal').modal('show');
|
||||
}
|
||||
|
||||
|
@ -120,11 +123,13 @@ on_show_add_contributor_modal=function(e) {
|
|||
on_valid_add_contributor_modal=function() {
|
||||
var group=groups[$('#add_contributor_modal #group_name')[0].value];
|
||||
var name=$('#add_contributor_name')[0].value;
|
||||
edit_id=$('#view-group #edit_id')[0].value;
|
||||
if (name=='') {
|
||||
alert('Vous devez saisir un nom !');
|
||||
return;
|
||||
}
|
||||
if (group.contributorByName(name)!=undefined) {
|
||||
duplicate=group.contributorByName(name);
|
||||
if (duplicate!=undefined && duplicate.id!=edit_id) {
|
||||
alert('Un contributor porte déjà ce nom !');
|
||||
return;
|
||||
}
|
||||
|
@ -133,11 +138,17 @@ on_valid_add_contributor_modal=function() {
|
|||
alert('Vous devez saisir un email !');
|
||||
return;
|
||||
}
|
||||
if (group.contributorByEmail(email)!=undefined) {
|
||||
duplicate=group.contributorByEmail(email)
|
||||
if (duplicate!=undefined && duplicate.id!=edit_id) {
|
||||
alert('Un contributor utilise déjà cet email !');
|
||||
return;
|
||||
}
|
||||
group.contributors.push(new Contributor(name,email));
|
||||
if(edit_id=='-1') {
|
||||
group.addContributor(new Contributor(name,email));
|
||||
}
|
||||
else {
|
||||
group.replaceContributor(edit_id,new Contributor(name,email));
|
||||
}
|
||||
set_contributors(group);
|
||||
$('#add_contributor_modal').modal('hide');
|
||||
$('#add_contributor_name')[0].value='';
|
||||
|
@ -151,6 +162,19 @@ on_close_add_contributor_modal=function () {
|
|||
$('#add_contributor_email')[0].value='';
|
||||
}
|
||||
|
||||
on_edit_contributor_btn_click=function(e) {
|
||||
var group=groups[$('#view-group #group_name')[0].value];
|
||||
$('#add_contributor_modal #group_name')[0].value=group.name;
|
||||
contributor_name=$('#view-group #contributor')[0].value;
|
||||
contributor=group.contributorByName(contributor_name);
|
||||
$('#view-group #edit_id')[0].value=contributor.id;
|
||||
$('#add_contributor_modal #add_contributor_name')[0].value=contributor.name;
|
||||
$('#add_contributor_modal #add_contributor_email')[0].value=contributor.email;
|
||||
$($('#add_contributor_modal h4')[0]).html('Editer un participant');
|
||||
$($('#add_contributor_modal #add_contributor_submit')[0]).html('Valider');
|
||||
$('#add_contributor_modal').modal('show');
|
||||
}
|
||||
|
||||
on_click_del_contributor_btn=function() {
|
||||
contributor=$('#view-group #contributor')[0].value;
|
||||
question='Voulez-vous vraiment supprimer '+contributor+' ?';
|
||||
|
@ -358,6 +382,7 @@ $( document ).ready( function() {
|
|||
$("#add_contributor_modal").on('hidden.bs.modal',on_close_add_contributor_modal);
|
||||
$("#add_contributor_modal form").on('submit',on_valid_add_contributor_modal);
|
||||
|
||||
$('#edit_contributor_btn').bind('click',on_edit_contributor_btn_click);
|
||||
$('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
|
||||
|
||||
$('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
|
||||
|
|
|
@ -119,6 +119,15 @@ function Group(name,data) {
|
|||
this.contributions[idx]=c;
|
||||
}
|
||||
|
||||
this.addContributor=function(c) {
|
||||
c.id=this.contributors.length;
|
||||
this.contributors.push(c);
|
||||
}
|
||||
|
||||
this.replaceContributor=function(idx,c) {
|
||||
c.id=idx;
|
||||
this.contributors[idx]=c;
|
||||
}
|
||||
|
||||
this.balance=function() {
|
||||
ret={}
|
||||
|
@ -141,7 +150,8 @@ function Group(name,data) {
|
|||
for (idx in data.contributors) {
|
||||
this.contributors.push(new Contributor(
|
||||
data.contributors[idx].name,
|
||||
data.contributors[idx].email
|
||||
data.contributors[idx].email,
|
||||
idx
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -163,9 +173,10 @@ function Group(name,data) {
|
|||
}
|
||||
}
|
||||
|
||||
function Contributor(name,email) {
|
||||
function Contributor(name,email,id) {
|
||||
this.name=name;
|
||||
this.email=email;
|
||||
this.id=id;
|
||||
this.export=function() {
|
||||
return {
|
||||
'name': this.name,
|
||||
|
|
|
@ -77,6 +77,7 @@ body{
|
|||
<h1><span>Noël</span><small><span id='edit_group_btn' class='glyphicon glyphicon-edit btn btn-sm'></span></small></h1>
|
||||
<form class="form-horizontal" role="form">
|
||||
<input type='hidden' id='group_name' value='Noël'/>
|
||||
<input type='hidden' id='edit_id' value='-1' />
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">Participant</span>
|
||||
|
|
Loading…
Reference in a new issue