From efe943361b7456e9179c48a3724f6248e6a1bb7e Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 12 Jan 2014 01:11:24 +0100 Subject: [PATCH] Clean code --- inc/myco.js | 11 ++------ inc/myco_objects.js | 69 +++++++++++++++++++++++++++------------------ index.html | 2 -- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/inc/myco.js b/inc/myco.js index 7ab09f4..54475c8 100644 --- a/inc/myco.js +++ b/inc/myco.js @@ -6,7 +6,6 @@ refresh_group_list=function() { if (groups.count()==0) { $(grouplist).prepend('
  • Aucune groupe
  • '); - } else { groups.each(function(idx,group) { @@ -113,7 +112,7 @@ show_contributions=function(group,contributor_name) { } total.html(sum+' €'); } - + $('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click); $('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click); } @@ -167,7 +166,6 @@ on_valid_add_contributor_modal=function() { $('#add_contributor_name')[0].value=''; $('#add_contributor_email')[0].value=''; groups.save(); - } on_close_add_contributor_modal=function () { @@ -249,7 +247,7 @@ on_valid_add_contribution_modal=function(e) { return; } cost=parseFloat(cost.replace(',','.')); - + var date=$('#add_contribution_date')[0].value; if (date!='') { if(!RegExp('^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]$').test(date)) { @@ -266,7 +264,7 @@ on_valid_add_contribution_modal=function(e) { else { date=new Date(); } - + if($('#add_contribution_modal #edit_id')[0].value=='-1') { group.addContribution(new Contribution(contributor,cost,title,date)); } @@ -305,8 +303,6 @@ on_contribution_edit_btn_click=function(e) { contribution_id=$($(e.target).parents('div')[0]).data('id'); contribution=group.contributions[contribution_id]; $('#add_contribution_modal #add_contribution_contributor_name')[0].value=contribution.contributor.name; - console.log($('#add_contribution_modal #add_contribution_contributor_name')[0]); - console.log(contribution.contributor.name); $('#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'); @@ -358,7 +354,6 @@ display_balance=function(group) { on_remove_group_btn_click=function(e) { group=groups[$('#view-group #group_name')[0].value]; myconfirm('Etes-vous sûre de vouloir supprimer le group '+group.name+' ?',on_confirm_remove_group,null,group); - } on_confirm_remove_group=function(group) { diff --git a/inc/myco_objects.js b/inc/myco_objects.js index d30542b..ef1c1d1 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -79,6 +79,9 @@ function Group(name,data) { }; } + /* + * Contributors + */ this.removeContributor=function(c) { this.contributors=this.contributors.filter(function(v){ return (v.name!=c); @@ -99,6 +102,19 @@ function Group(name,data) { return undefined; } + 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; + } + + /* + * Contributions + */ this.contributionsByContributorName=function(name) { var ret=[]; for (idx in this.contributions) { @@ -119,16 +135,9 @@ 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; - } - + /* + * Balance + */ this.balance=function() { ret={} for (idx in this.contributors) { @@ -143,27 +152,31 @@ function Group(name,data) { return ret; } + /* + * Contructor + */ if (jQuery.type(data)=='object') { try { - this.name=data.name; - if (jQuery.type(data.contributors) == 'array') { - for (idx in data.contributors) { - this.contributors.push(new Contributor( - data.contributors[idx].name, - data.contributors[idx].email, - idx - )); + this.name=data.name; + if (jQuery.type(data.contributors) == 'array') { + for (idx in data.contributors) { + this.contributors.push(new Contributor( + data.contributors[idx].name, + data.contributors[idx].email, + idx + )); + } } - } - if (jQuery.type(data.contributions) == 'array') { - for (idx in data.contributions) { - this.contributions.push(new Contribution( - this.contributorByName(data.contributions[idx].contributor), - data.contributions[idx].cost, - data.contributions[idx].title, - data.contributions[idx].date, - idx - )); + if (jQuery.type(data.contributions) == 'array') { + for (idx in data.contributions) { + this.contributions.push(new Contribution( + this.contributorByName(data.contributions[idx].contributor), + data.contributions[idx].cost, + data.contributions[idx].title, + data.contributions[idx].date, + idx + )); + } } } } diff --git a/index.html b/index.html index 138c282..20835b0 100644 --- a/index.html +++ b/index.html @@ -60,8 +60,6 @@ body{