diff --git a/inc/myco.js b/inc/myco.js
index 60f1f3a..43ddd1b 100644
--- a/inc/myco.js
+++ b/inc/myco.js
@@ -9,7 +9,7 @@ refresh_group_list=function() {
}
else {
groups.each(function(idx,group) {
- $(grouplist).prepend('
'+group.name+'');
+ $(grouplist).prepend(''+group.name+'');
});
$('a.group-choice').each(function(idx,a) {
@@ -43,11 +43,11 @@ on_valid_add_group_modal=function (e) {
alert('Ce groupe exite déjà !');
return;
}
- groups[name]=new Group(name);
+ var uuid=groups.newGroup(name);
refresh_group_list();
$('#add_group_modal').modal('hide');
groups.save();
- view_group(groups[name]);
+ view_group(groups[uuid]);
}
on_close_add_group_modal=function () {
@@ -58,7 +58,7 @@ on_close_add_group_modal=function () {
* Nav bars
****************/
on_group_choice_click=function(e) {
- view_group(groups[$(e.target).html()]);
+ view_group(groups[$(e.target).data('uuid')]);
navbar_collapse_hide();
}
@@ -102,7 +102,7 @@ view_home=function() {
sum+=value;
diff='+'+value.toFixed(2)+' € | ';
}
- tbody.html(tbody.html()+''+g+' | '+diff+'
');
+ tbody.html(tbody.html()+''+balances[g].name+' | '+diff+'
');
}
}
$('#view-home #mybalances a.group-link').bind('click',function(e) {
@@ -129,8 +129,8 @@ view_home=function() {
* View group
****************/
view_group=function(group) {
+ $('#view-group').data('uuid',group.uuid);
$('#view-group h1 span:first').html(group.name);
- $('#view-group #group_name')[0].value=group.name;
set_contributors(group);
on_contributor_change();
view_part('#view-group');
@@ -149,7 +149,7 @@ set_contributors=function(group) {
}
on_contributor_change=function(e) {
- show_contributions(groups[$('#view-group #group_name')[0].value],$('#view-group #contributor')[0].value);
+ show_contributions(groups[$('#view-group').data('uuid')],$('#view-group #contributor')[0].value);
}
show_contributions=function(group,contributor_name) {
@@ -179,7 +179,7 @@ show_contributions=function(group,contributor_name) {
* 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').data('group-uuid',('#view-group').data('uuid'))
$($('#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';
@@ -192,7 +192,7 @@ on_show_add_contributor_modal=function(e) {
on_valid_add_contributor_modal=function(e) {
e.preventDefault();
- var group=groups[$('#add_contributor_modal #group_name')[0].value];
+ var group=groups[$('#add_contributor_modal').data('group-uuid')];
var name=$('#add_contributor_name')[0].value;
edit_id=$('#view-group #edit_id')[0].value;
if (name=='') {
@@ -233,8 +233,8 @@ on_close_add_contributor_modal=function () {
}
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;
+ var group=groups[$('#view-group').data('uuid')];
+ $('#add_contributor_modal').data('group-uuid',group.uuid);
contributor_name=$('#view-group #contributor')[0].value;
contributor=group.contributorByName(contributor_name);
$('#view-group #edit_id')[0].value=contributor.id;
@@ -252,7 +252,7 @@ on_click_del_contributor_btn=function() {
}
on_confirm_del_contributor=function(contributor) {
- var group=groups[$('#view-group #group_name')[0].value];
+ var group=groups[$('#view-group').data('uuid')];
group.removeContributor(contributor);
set_contributors(group);
groups.save();
@@ -272,7 +272,7 @@ on_show_add_contribution_modal=function(e) {
}
on_click_add_contribution_btn=function() {
- $('#add_contribution_modal #group_name')[0].value=$('#view-group #group_name')[0].value;
+ $('#add_contribution_modal').data('group-uuid',$('#view-group').data('uuid'));
$('#add_contribution_modal #edit_uuid')[0].value='-1';
$($('#add_contribution_modal h4')[0]).html('Ajouter une contribution');
$($('#add_contribution_modal #add_contribution_submit')[0]).html('Ajouter');
@@ -281,7 +281,7 @@ on_click_add_contribution_btn=function() {
on_valid_add_contribution_modal=function(e) {
e.preventDefault();
- var group=groups[$('#add_contribution_modal #group_name')[0].value];
+ var group=groups[$('#add_contribution_modal').data('group-uuid')];
var contributor_name=$('#add_contribution_contributor_name')[0].value;
var contributor=group.contributorByName(contributor_name);
if (contributor==undefined) {
@@ -342,7 +342,7 @@ on_close_add_contribution_modal=function () {
}
on_contribution_delete_btn_click=function(e) {
- var group=groups[$('#view-group #group_name')[0].value];
+ var group=groups[$('#view-group').data('uuid')];
contribution_uuid=$($(e.target).parents('div')[0]).data('uuid');
contribution=group.contributions[contribution_uuid];
myconfirm('Etes-vous sûre de vouloir supprimer la participation '+contribution.getTitle()+' de '+contribution.contributor.name+' ?',on_confirm_contribution_delete,null,{'group':group,'contribution_uuid':contribution_uuid, 'contribution': contribution} );
@@ -355,8 +355,8 @@ on_confirm_contribution_delete=function(data) {
}
on_contribution_edit_btn_click=function(e) {
- var group=groups[$('#view-group #group_name')[0].value];
- $('#add_contribution_modal #group_name')[0].value=$('#view-group #group_name')[0].value;
+ var group=groups[$('#view-group').data('uuid')];
+ $('#add_contribution_modal').data('group-uuid',$('#view-group').data('uuid'));
$($('#add_contribution_modal h4')[0]).html('Editer une contribution');
$($('#add_contribution_modal #add_contribution_submit')[0]).html('Valider');
contribution_uuid=$($(e.target).parents('div')[0]).data('uuid');
@@ -389,7 +389,7 @@ on_confirm_clear_local_data=function(data) {
*********************/
on_display_balance_btn_click=function(e) {
- group=groups[$('#view-group #group_name')[0].value];
+ group=groups[$('#view-group').data('uuid')];
display_balance(group);
}
@@ -415,12 +415,12 @@ display_balance=function(group) {
*********************/
on_remove_group_btn_click=function(e) {
- group=groups[$('#view-group #group_name')[0].value];
+ group=groups[$('#view-group').data('uuid')];
myconfirm('Etes-vous sûre de vouloir supprimer le group '+group.name+' ?',on_confirm_remove_group,null,group);
}
on_confirm_remove_group=function(group) {
- if(groups.removeGroup(group.name)) {
+ if(groups.removeGroup(group.uuid)) {
groups.save();
location.reload();
}
diff --git a/inc/myco_objects.js b/inc/myco_objects.js
index e74f839..b64ecdb 100644
--- a/inc/myco_objects.js
+++ b/inc/myco_objects.js
@@ -8,7 +8,7 @@ function GroupList() {
var data=JSON.parse(localStorage.groups);
this.lastChange=data.lastChange;
for (el in data.groups) {
- this[el]=new Group(el,data.groups[el]);
+ this[el]=new Group(el,false,data.groups[el]);
}
}
catch(e) {
@@ -41,7 +41,7 @@ function GroupList() {
}
}
for (el in groups) {
- this[el]=new Group(el,groups[el]);
+ this[el]=new Group(el,false,groups[el]);
}
return true;
}
@@ -77,9 +77,21 @@ function GroupList() {
return (jQuery.type(el)=='object' && jQuery.type(el.isGroup)=='function' && el.isGroup());
}
- this.removeGroup=function(name) {
- if (this.isGroup(this[name])) {
- delete this[name];
+ this.byName=function(name) {
+ for (el in this) {
+ if(this.isGroup(this[el])) {
+ if (this[el].name==name) {
+ return this[el];
+ }
+ }
+ }
+ return false;
+ }
+
+
+ this.removeGroup=function(uuid) {
+ if (this.isGroup(this[uuid])) {
+ delete this[uuid];
return true;
}
return false;
@@ -87,14 +99,23 @@ function GroupList() {
this.balances=function(fct) {
return this.each(function(idx,group) {
- return group.balance();
+ bal=group.balance();
+ bal.name=group.name;
+ return bal;
});
}
+ this.newGroup=function(name,uuid) {
+ var uuid=uuid||generate_uuid();
+ this[uuid]=new Group(uuid,name);
+ return uuid;
+ }
+
}
-function Group(name,data) {
- this.name=name;
+function Group(uuid,name,data) {
+ this.uuid=uuid || generate_uuid();
+ this.name=name || false;
this.contributors=[];
this.contributions={};
this.deletedContributions={};
@@ -114,6 +135,7 @@ function Group(name,data) {
contributions[uuid]=this.contributions[uuid].export();
}
return {
+ 'uuid': this.uuid,
'name': encodeURIComponent(this.name),
'contributors': contributors,
'contributions': contributions,
@@ -227,6 +249,7 @@ function Group(name,data) {
*/
if (jQuery.type(data)=='object') {
try {
+ this.uuid=data.uuid;
this.name=data.name;
if (jQuery.type(data.contributors) == 'array') {
for (idx in data.contributors) {
diff --git a/index.html b/index.html
index 2b9e1d2..3cc5e1c 100644
--- a/index.html
+++ b/index.html
@@ -110,7 +110,6 @@ body{