diff --git a/inc/myco.js b/inc/myco.js
index 8316516..4682315 100644
--- a/inc/myco.js
+++ b/inc/myco.js
@@ -103,7 +103,8 @@ view_home=function() {
sum+=value;
diff='
+'+value.toFixed(2)+' € | ';
}
- tbody.html(tbody.html()+''+balances[g].name+' | '+diff+'
');
+ menu='';
+ tbody.html(tbody.html()+''+balances[g].name+' | '+diff+''+menu+' |
');
}
}
$('#view-home #mybalances a.group-link').bind('click',function(e) {
@@ -112,6 +113,9 @@ view_home=function() {
view_group(groups[g]);
}
});
+ $('a.home_grp_cat_btn').each(function(idx,a) {
+ $(a).bind('click',on_home_grp_cat_btn_click);
+ });
if (sum<0) {
$('#view-home #mybalances #total-value').html(''+sum.toFixed(2)+' €');
}
@@ -126,6 +130,20 @@ view_home=function() {
view_part('#view-home');
}
+on_home_grp_cat_btn_click=function(e) {
+ grp_id=$(e.target).parents('div.btn-group').data('grp');
+ grp=groups[grp_id];
+ console.log(grp.getCategories());
+ ul=$('#grp_cat_modal ul');
+ html="";
+ cats=grp.getCategories();
+ for(cid in cats) {
+ html+=" "+cats[cid]['name']+"";
+ }
+ ul.html(html);
+ $('#grp_cat_modal').modal('show');
+}
+
/****************
* View group
****************/
@@ -172,8 +190,13 @@ show_contributions=function(group,contributor_email) {
else {
sum=0;
for (idx in contributions) {
+ var cat='';
+ console.log(contributions[idx].categorie);
+ if (contributions[idx].categorie && jQuery.type(group.categories[contributions[idx].categorie])) {
+ cat='
'+group.categories[contributions[idx].categorie]['name']+"";
+ }
col_actions=' | ';
- tbody.append(''+contributions[idx].getTitle()+' | '+contributions[idx].cost.toFixed(2)+' € '+moment(contributions[idx].date).format('DD/MM/YYYY')+' | '+col_actions+'
');
+ tbody.append(''+contributions[idx].getTitle()+cat+' | '+contributions[idx].cost.toFixed(2)+' € '+moment(contributions[idx].date).format('DD/MM/YYYY')+' | '+col_actions+'
');
sum+=contributions[idx].cost;
}
total.html(sum.toFixed(2)+' €');
@@ -370,6 +393,13 @@ on_confirm_del_contributor=function(contributor) {
on_show_add_contribution_modal=function(e) {
$('#add_contribution_modal #add_contribution_contributor_email').html($('#view-group #contributor').html());
$('#add_contribution_modal #add_contribution_contributor_email')[0].value=$('#view-group #contributor')[0].value;
+ gid=$('#add_contribution_modal').data('group-uuid');
+ group=groups[gid];
+ cats="";
+ for (u in group.categories) {
+ cats+="";
+ }
+ $('#add_contribution_modal #add_contribution_categorie').html(cats);
$('#add_contribution_modal #add_contribution_title').focus();
}
@@ -428,12 +458,18 @@ on_valid_add_contribution_modal=function(e) {
date=new Date();
}
+ var cat=$('#add_contribution_categorie')[0].value;
+ if (cat != '' && !jQuery.type(group.categories[cat])) {
+ alert('Categorie incorrect');
+ return;
+ }
+
if($('#add_contribution_modal #edit_uuid')[0].value=='-1') {
- group.addContribution(new Contribution(contributor,cost,title,date));
+ group.addContribution(new Contribution(contributor,cost,title,date,cat));
}
else {
contribution_uuid=$('#add_contribution_modal #edit_uuid')[0].value;
- group.updateContribution(contribution_uuid,new Contribution(contributor,cost,title,date));
+ group.updateContribution(contribution_uuid,new Contribution(contributor,cost,title,date,cat));
}
show_contributions(group,contributor_email);
$('#add_contribution_modal').modal('hide');
@@ -469,6 +505,9 @@ on_contribution_edit_btn_click=function(e) {
$('#add_contribution_modal #add_contribution_title')[0].value=contribution.getTitle();
$('#add_contribution_modal #add_contribution_cost')[0].value=contribution.cost;
$('#add_contribution_modal #add_contribution_date')[0].value=moment(contribution.date).format('DD/MM/YYYY');
+ if (contribution.categorie) {
+ $('#add_contribution_modal #add_contribution_categorie')[0].value=contribution.categorie;
+ }
$('#add_contribution_modal #edit_uuid')[0].value=contribution_uuid;
$('#add_contribution_modal').modal('show');
}
diff --git a/inc/myco_objects.js b/inc/myco_objects.js
index 91265a5..159e6cb 100644
--- a/inc/myco_objects.js
+++ b/inc/myco_objects.js
@@ -121,7 +121,7 @@ function Group(uuid,name,data) {
this.deletedContributors={};
this.contributions={};
this.deletedContributions={};
-
+ this.categories={};
this.isGroup=function() {
return true;
@@ -142,7 +142,8 @@ function Group(uuid,name,data) {
'contributors': contributors,
'deletedContributors': this.deletedContributors,
'contributions': contributions,
- 'deletedContributions': this.deletedContributions
+ 'deletedContributions': this.deletedContributions,
+ 'categories': this.categories
};
}
@@ -239,6 +240,7 @@ function Group(uuid,name,data) {
this.deletedContributions[uuid].cost,
decodeURIComponent(this.deletedContributions[uuid].title),
this.deletedContributions[uuid].date,
+ this.deletedContributions[uuid].categorie,
uuid,
this.deletedContributions[uuid].lastChange
));
@@ -292,6 +294,7 @@ function Group(uuid,name,data) {
data.cost,
decodeURIComponent(data.title),
data.date,
+ data.categorie,
data.uuid,
data.lastChange
);
@@ -336,6 +339,13 @@ function Group(uuid,name,data) {
};
}
+ /*
+ * Categories
+ */
+ this.getCategories=function() {
+ return this.categories;
+ }
+
/*
* Contructor
*/
@@ -363,6 +373,32 @@ function Group(uuid,name,data) {
this.deletedContributions[uuid]=data.deletedContributions[uuid];
}
}
+ if (jQuery.type(data.categories) == 'object') {
+ for (cid in data.categories) {
+ if (jQuery.type(data.categories[cid]['color'])!='string') {
+ data.categories[cid]['color']='#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
+ }
+ this.categories[cid]=data.categories[cid];
+ }
+ }
+ else {
+ categories= {
+ 'Alimentation': '#1f83db',
+ 'Restaurant': '#f07305',
+ 'Loisir': '#d413ce',
+ 'Transport': '#13d413',
+ 'Vacances': '#e9fa00',
+ 'Maison': '#e9fa00',
+ 'Rembourssement': '#8a8b8c',
+ 'Cadeau': '#a700fa'
+ };
+ for (c in categories) {
+ this.categories[generate_uuid()]={
+ 'name': c,
+ 'color': categories[c]
+ };
+ }
+ }
}
catch (e) {
alert('Une erreur est survenue en chargeant le groupe '+this.name+' depuis le cache');
@@ -381,7 +417,7 @@ function Contributor(name,email) {
}
}
-function Contribution(contributor,cost,title,date,uuid,lastChange) {
+function Contribution(contributor,cost,title,date,cat,uuid,lastChange) {
this.contributor=contributor;
this.cost=cost;
this.title=title;
@@ -390,6 +426,7 @@ function Contribution(contributor,cost,title,date,uuid,lastChange) {
}
this.date=date;
this.uuid=uuid || generate_uuid();
+ this.categorie=cat;
this.lastChange=lastChange || new Date().getTime();
this.export=function() {
return {
@@ -398,6 +435,7 @@ function Contribution(contributor,cost,title,date,uuid,lastChange) {
'cost': this.cost,
'title': encodeURIComponent(this.title),
'date': this.date.getTime(),
+ 'categorie': this.categorie,
'lastChange': this.lastChange,
};
}
diff --git a/index.html b/index.html
index bc255c0..3defa93 100644
--- a/index.html
+++ b/index.html
@@ -55,11 +55,22 @@ body{
text-transform: capitalize;
}
-#view-group span.date {
+#view-group span.date, #view-group span.categorie {
color: #999;
font-size: 0.8em;
font-style: italic;
}
+
+span.cat-color {
+ width: 0.8em;
+ height: 0.8em;
+ display: inline-block;
+}
+
+#grp_cat_modal ul {
+ list-style-type: none;
+ padding: 0;
+}
@@ -103,6 +114,7 @@ body{
Groupe |
Balance |
+ |
@@ -110,6 +122,7 @@ body{
Total : |
|
+ |
@@ -392,6 +405,12 @@ body{
€
+
+
@@ -522,6 +542,24 @@ body{
+
+
+