2272ff551bf4e65a2e3436be802033f3b6f51da7
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1) refresh_group_list=function() {
2)   grouplist=$('#group-choice')[0];
3)   $('a.group-choice').each(function(idx,a) {
4)     $(a).parent().remove();
5)   });
6) 
7)   if (groups.count()==0) {
8)     $(grouplist).prepend('<li><a class="group-choice">Aucune groupe</a></li>');
9)   }
10)   else { 
11)     groups.each(function(idx,group) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

12)       $(grouplist).prepend('<li><a class="group-choice" data-uuid="'+group.uuid+'">'+group.name+'</a></li>');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

13)     });
14) 
15)     $('a.group-choice').each(function(idx,a) {
16)       $(a).bind('click',on_group_choice_click);
17)     });
18)   }
19) }
20) 
21) 
22) /****************
23)  * Add group
24)  ****************/
Benjamin Renard Hide navbar-groupe-collapse...

Benjamin Renard authored 10 years ago

25) 
26) on_click_add_group_btn=function(e) {
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

27)   navbar_collapse_hide();
Benjamin Renard Hide navbar-groupe-collapse...

Benjamin Renard authored 10 years ago

28)   $('#add_group_modal').modal('show');
29) }
30) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

31) on_show_add_group_modal=function(e) {
32)   $('#add_group_modal #add_group_name').focus();
33) }
34) 
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

35) on_valid_add_group_modal=function (e) {
36)   e.preventDefault();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

37)   var name=$('#add_group_name')[0].value;
38)   if (name=='') {
39)     alert('Vous devez saisir un nom !');
40)     return;
41)   }
42)   if (groups[name]!==undefined) {
43)     alert('Ce groupe exite déjà !');
44)     return;
45)   }
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

46)   var uuid=groups.newGroup(name);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

47)   refresh_group_list();
48)   $('#add_group_modal').modal('hide');
49)   groups.save();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

50)   view_group(groups[uuid]);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

51) }
52) 
53) on_close_add_group_modal=function () {
Benjamin Renard Fix error on add_group_moda...

Benjamin Renard authored 10 years ago

54)   $('#add_group_modal form')[0].reset();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

55) }
56) 
57) /****************
58)  * Nav bars
59)  ****************/
60) on_group_choice_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

61)   view_group(groups[$(e.target).data('uuid')]);
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

62)   navbar_collapse_hide();
63) }
64) 
65) navbar_collapse_hide=function() {
66)   if ($('#navbar-groupe-collapse').hasClass('in')) {
67)     $('#navbar-groupe-collapse').collapse('hide');
68)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

69) }
70) 
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

71) bottom_navbar_collapse_hide=function() {
72)   if ($('#bottom-navbar-collapse-1').hasClass('in')) {
73)     $('#bottom-navbar-collapse-1').collapse('hide');
74)   }
75) }
76) 
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

77) /****************
78)  * Parts
79)  ****************/
80) 
81) view_part=function(part) {
82)   $('.part').each(function(idx,div) {
83)     $(div).css('display','none');
84)   });
85)   $(part).css('display','block');
86) }
87) 
88) view_home=function() {
Benjamin Renard Hide navbar on view_home

Benjamin Renard authored 10 years ago

89)   navbar_collapse_hide();
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

90)   if (user) {
91)     $('#view-home #title').html('Bonjour '+user.name);
92)   }
93)   else {
94)     $('#view-home #title').html('Bonjour');
95)   }
96)   if (groups.count()>0) {
97)     tbody=$('#view-home #mybalances tbody');
98)     tbody.html('');
99)     balances=groups.balances();
100)     var sum=0;
101)     for (g in balances) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

102)       if (jQuery.type(balances[g]['balance'][user.email])!='undefined') {
103)         if (balances[g]['balance'][user.email]['diff']<0) {
104)           sum+=balances[g]['balance'][user.email]['diff'];
105)           diff='<td class="negative">'+balances[g]['balance'][user.email]['diff'].toFixed(2)+'</td>';
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

106)         }
107)         else {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

108)           value=balances[g]['balance'][user.email]['total']-balances[g]['min'];
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

109)           sum+=value;
110)           diff='<td class="positive">+'+value.toFixed(2)+' €</td>';
111)         }
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

112)         tbody.html(tbody.html()+'<tr><td><a class="group-link" data-uuid="'+g+'">'+balances[g].name+'</a></td>'+diff+'</tr>');
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

113)       }
114)     }
Benjamin Renard Make group name as link in...

Benjamin Renard authored 10 years ago

115)     $('#view-home #mybalances a.group-link').bind('click',function(e) {
Benjamin Renard Fixed link to group in Home...

Benjamin Renard authored 10 years ago

116)       g=$(e.target).data('uuid');
Benjamin Renard Make group name as link in...

Benjamin Renard authored 10 years ago

117)       if (jQuery.type(groups[g])!='undefined') {
118)         view_group(groups[g]);
119)       }
120)     });
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

121)     $('a.home_grp_cat_btn').each(function(idx,a) {
122)       $(a).bind('click',on_home_grp_cat_btn_click);
123)     });
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

124)     if (sum<0) {
125)       $('#view-home #mybalances #total-value').html('<span class="negative">'+sum.toFixed(2)+' €</span>');
126)     }
127)     else {
128)       $('#view-home #mybalances #total-value').html('<span class="positive">'+(sum==0?'':'+')+sum.toFixed(2)+' €</span>');
129)     }
Benjamin Renard Fixed table display on home...

Benjamin Renard authored 10 years ago

130)     $('#view-home #mybalances').css('display','table');
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

131)   }
132)   else {
133)     $('#view-home #mybalances').css('display','none');
134)   }
135)   view_part('#view-home');
136) }
137) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

138) /****************
139)  * View group
140)  ****************/
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

141) view_group=function(group,contributor_email) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

142)   $('#view-group').data('uuid',group.uuid);
Benjamin Renard Upgrade to bootstrap 3

Benjamin Renard authored 10 years ago

143)   $('#view-group .group-title:first').html(group.name);
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

144)   set_contributors(group,contributor_email);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

145)   on_contributor_change();
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

146)   view_part('#view-group');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

147) }
148) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

149) set_contributors=function(group,contributor_email) {
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

150)   $('#view-group #contributor option').remove();
151)   if(group.contributors.length==0) {
152)     $('#view-group #contributor').append('<option>Aucun participant</option>');
153)   }
154)   else {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

155)     for (email in group.contributors) {
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

156)       if (email == contributor_email) {
157)         sel=' selected';
158)       }
159)       else {
160)         sel='';
161)       }
162)       $('#view-group #contributor').append('<option value="'+email+'"'+sel+'>'+group.contributors[email].name+'</option>');
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

163)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

164)   }
165) }
166) 
167) on_contributor_change=function(e) {
Benjamin Renard Upgrade to bootstrap 3

Benjamin Renard authored 10 years ago

168) 	if ($('#group-navbar-collapse-1').hasClass('in')) {
169) 		$('#group-navbar-collapse-1').collapse('hide');
170) 	}
171) 	$('#view-group #group-username').html($('#view-group #contributor option:selected').text());
172) 	show_contributions(groups[$('#view-group').data('uuid')],$('#view-group #contributor')[0].value);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

173) }
174) 
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

175) show_contributions=function(group,contributor_email,contributions) {
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

176)   var tbody=$($('#view-group #contributions tbody')[0]);
177)   tbody.html('');
178)   total=$($('#view-group #total-value')[0]);
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

179)   if (!contributions) {
180)     contributions=group.contributionsByContributorEmail(contributor_email);
181)     contributions.reverse();
182)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

183)   if (contributions.length==0) {
184)     tbody.append('<tr><td colspan=3>Aucune contributions</td></tr>');
185)     total.html('0,00 €');
186)   }
187)   else {
188)     sum=0;
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

189)     for (idx in contributions) {
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

190)       var cat='';
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

191)       if (contributions[idx].category && jQuery.type(group.categories[contributions[idx].category])) {
192) 		cat='<br/><span class="category"><span class="cat-color" style="background-color: '+group.categories[contributions[idx].category]['color']+'"></span> '+group.categories[contributions[idx].category]['name']+"</span>";
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

193) 	  }
Benjamin Renard Upgrade to bootstrap 3

Benjamin Renard authored 10 years ago

194)       col_actions='<td><div class="btn-group" data-uuid="'+contributions[idx].uuid+'"><button type="button" class="btn btn-default btn-sm contribution_edit_btn"><span class="glyphicon glyphicon-edit"></span></button><button type="button" class="btn btn-default btn-sm contribution_delete_btn"><span class="glyphicon glyphicon-trash"></span></button></div></td>';
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

195)       tbody.append('<tr><td>'+contributions[idx].getTitle()+cat+'</td><td>'+contributions[idx].cost.toFixed(2)+' €<br/><span class="date">'+moment(contributions[idx].date).format('DD/MM/YYYY')+'</span></td>'+col_actions+'</tr>');
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

196)       sum+=contributions[idx].cost;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

197)     }
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

198)     total.html(sum.toFixed(2)+' €');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

199)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

200)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

201)   $('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click);
202)   $('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click);
203) }
204) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

205) on_categories_group_btn_click=function(e) {
206)   group=groups[$('#view-group').data('uuid')];
207)   $('#view-group-categories').data('group-uuid',$('#view-group').data('uuid'));
208)   refresh_group_categories(group);
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

209)   bottom_navbar_collapse_hide();
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

210)   view_part('#view-group-categories');
211) }
212) 
213) refresh_group_categories=function(group) {
214)   ul=$('#view-group-categories ul');
215)   html="";
216)   for(cid in group.getSortedCategories()) {
217)     html+="<li data-uuid='"+cid+"'><span class='cat-color' style='background-color: "+group.categories[cid]['color']+"'></span> "+group.categories[cid]['name']+"</li>";
218)   }
219)   ul.html(html);
220)   $('#view-group-categories ul li').bind('click',on_categories_group_cat_click);
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

221)   
222)   $('#cats-chart').css('width',$(window).width()*0.9+'px');
223)   
224)   $.plot($('#cats-chart'),group.getCategoriesStats(),{
225)     'grid': {
226)         'hoverable': true
227)     }, 
228)     'legend': {
Benjamin Renard Preserve categories's color...

Benjamin Renard authored 10 years ago

229)         'show': false,
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

230)     },
231)     'series': { 
232)         'pie': {
233)             'show': true,
234)             'innerRadius': 0.5,
Benjamin Renard Improve chart

Benjamin Renard authored 10 years ago

235)             'radius': .8,
236)             'tilt': .5,
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

237)             'label': {
238)                 'show': true,
239)                 'formatter': function (label, series) {
Benjamin Renard Improve chart

Benjamin Renard authored 10 years ago

240) return '<div class="cats-chart-label">' + label + '<br/><span>' +   
241)                             Math.round(series.percent) + '% - '+series.data[0][1].toFixed(2)+'€</span></div>';
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

242)                 }
243)             }
244)         }
245)     }
246) });
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

247) }
248) 
249) on_categories_group_cat_click=function(e) {
250)   li=$(e.target);
251)   if (li.prop("tagName")!='LI') {
252)     return true;
253)   }
254)   cid=li.data('uuid');
255)   group=groups[$('#view-group-categories').data('group-uuid')];
256)   cat=group.categories[cid];
257)   li.html("<span class='cat-color' style='background-color: "+cat['color']+"'></span> "+
258)   "<input type='text' value=\""+cat.name+"\"/> "+
259)   "<button class='btn btn-default btn-xs cat_edit'><span class='glyphicon glyphicon-ok'></span></button>"+
260)   "<button class='btn btn-default btn-xs cat_delete'><span class='glyphicon glyphicon-trash'></span></button>");
261)   li.children('button.cat_edit').bind('click',{'li': li,'group': group,'cid': cid},on_categories_group_cat_edit_valid_btn_click);
262)   li.children('button.cat_delete').bind('click',{'li': li,'group': group,'cid': cid},on_categories_group_cat_delete_btn_click);
263) }
264) 
265) on_categories_group_cat_edit_valid_btn_click=function(e) {
266)   name=e.data.li.children('input:first').val();
267)   cat=e.data.group.categories[e.data.cid];
268)   e.data.group.updateCategory(e.data.cid,new Category(name,cat.color));
269)   groups.save();
270)   refresh_group_categories(e.data.group);
271) }
272) 
273) on_categories_group_cat_delete_btn_click=function(e) {
274)   e.data.group.deleteCategory(e.data.cid);
275)   groups.save();
276)   refresh_group_categories(e.data.group);
277) }
278) 
279) on_categories_go_back_group_btn_click=function(e) {
280)   view_group(groups[$('#view-group-categories').data('group-uuid')]);
281) }
282) 
283) on_categories_group_add_btn_click=function(e) {
284)   name=$('#add_category input')[0].value;
285)   
286)   if (jQuery.type(name)!='string' || name=='') {
287)     return;
288)   }
289)   group_uuid=$('#view-group-categories').data('group-uuid');
290)   group=groups[group_uuid];
291)   
292)   if (group.getCategoryByName(name,true)) {
293)     alert('Cette catégorie existe déjà');
294)   }
295)   else {
296)     group.addCategory(new Category(name));
297)     $('#add_category input')[0].value='';
298)     refresh_group_categories(group);
299)   }
300) }
301) 
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

302) on_nav_search_form_submit=function(e) {
303)   e.preventDefault();
304) }
305) 
306) on_nav_search_form_input=function(e) {
307)   var ipt=$(e.target);
308)   var pattern=ipt.val();
309) 
310)   group=groups[$('#view-group').data('uuid')];
311)  
312)   var found=group.searchContributions(pattern);
313)   show_contributions(group,null,found);
314) }
315) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

316) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

317) /*****************************
318)  * Trash
319)  *****************************/
320) 
321) on_trash_group_btn_click=function(e) {
322)   group=groups[$('#view-group').data('uuid')];
323)   contributor_email=$('#view-group #contributor')[0].value;
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

324)   bottom_navbar_collapse_hide();
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

325)   view_group_trash(group,contributor_email);
326) }
327) 
328) on_go_back_group_btn_click=function(e) {
329)   group=groups[$('#view-group-trash').data('uuid')];
330)   contributor_email=$('#view-group-trash').data('contributor-email');
331)   view_group(group,contributor_email);
332) }
333) 
334) view_group_trash=function(group,contributor_email) {
335)   $('#view-group-trash').data('uuid',group.uuid);
336)   $('#view-group-trash').data('contributor-email',contributor_email);
337)   var tbody=$('#view-group-trash #trash tbody');
338)   tbody.html('');
339)   contributions=group.deletedContributionsByContributorEmail(contributor_email);
340)   contributions.reverse();
341)   if (contributions.length==0) {
342)     tbody.append('<tr><td colspan=3>Aucune contributions</td></tr>');
343)   }
344)   else {
345)     for (idx in contributions) {
346)       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>');
347)     }
348)   }
349)   
350)   $('#view-group-trash .contribution_restore_btn').bind('click',on_contribution_restore_btn_click);
351)  
352)   view_part('#view-group-trash');
353) }
354) 
355) on_contribution_restore_btn_click=function(e) {
356)   var group=groups[$('#view-group-trash').data('uuid')];
357)   contribution_uuid=$($(e.target).parents('tr')[0]).data('uuid');
358)   contribution=group.importContribution(group.deletedContributions[contribution_uuid]);
359)   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} );
360) }
361) 
362) on_confirm_contribution_restore=function(data) {
363)   data.group.restoreContribution(data.contribution_uuid);
364)   groups.save();
365)   view_group(data.group,data.contribution.contributor.email);
366) }
367) 
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

368) on_trash_group_contributors_btn_click=function(e) {
369)   group=groups[$('#view-group').data('uuid')];
370)   view_group_trash_contributors(group);
371) }
372) 
373) on_go_back_group_trash_contributors_btn_click=function(e) {
374)   group=groups[$('#view-group-trash-contributors').data('uuid')];
375)   view_group(group);
376) }
377) 
378) view_group_trash_contributors=function(group) {
379)   $('#view-group-trash-contributors').data('uuid',group.uuid);
380)   var tbody=$('#view-group-trash-contributors #trash tbody');
381)   tbody.html('');
382)   contributors=group.getDeletedContributors();
383)   if (contributors.length==0) {
384)     tbody.append('<tr><td colspan=3>Aucun participant</td></tr>');
385)   }
386)   else {
387)     for (idx in contributors) {
388)       tbody.append('<tr data-email="'+contributors[idx].email+'"><td>'+contributors[idx].name+'</td><td><button type="button" class="btn btn-default contributor_restore_btn"><span class="glyphicon glyphicon-share"></span></button></td></tr>');
389)     }
390)   }
391) 
392)   $('#view-group-trash-contributors .contributor_restore_btn').bind('click',on_contributor_restore_btn_click);
393) 
394)   view_part('#view-group-trash-contributors');
395) }
396) 
397) on_contributor_restore_btn_click=function(e) {
398)   var group=groups[$('#view-group-trash-contributors').data('uuid')];
399)   contributor_email=$($(e.target).parents('tr')[0]).data('email');
400)   contributor=group.importContributor(group.deletedContributors[contributor_email]);
401)   myconfirm('Etes-vous sûre de vouloir restaurer '+contributor.name+' ?',on_confirm_contributor_restore,null,{'group':group,'contributor_email':contributor_email, 'contributor': contributor} );
402) }
403) 
404) on_confirm_contributor_restore=function(data) {
405)   data.group.restoreContributor(data.contributor_email);
406)   groups.save();
407)   view_group(data.group,data.contributor_email);
408) }
409) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

410) /******************************
411)  * Add/Edit/remove contributor
412)  ******************************/
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

413) on_click_add_contributor_btn=function() {
Benjamin Renard Fixed add contributor

Benjamin Renard authored 10 years ago

414)   $('#add_contributor_modal').data('group-uuid',$('#view-group').data('uuid'))
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

415)   $($('#add_contributor_modal h4')[0]).html('Ajouter un participant');
416)   $($('#add_contributor_modal #add_contributor_submit')[0]).html('Ajouter');
417)   $('#view-group #edit_id')[0].value='-1';
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

418)   $('#add_contributor_modal #add_contributor_email').attr('disabled',false);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

419)   $('#add_contributor_modal').modal('show');
420) }
421) 
422) on_show_add_contributor_modal=function(e) {
423)   $('#add_contributor_modal #add_contributor_name').focus();
424) }
425) 
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

426) validateEmail=function(email) {
427)     var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
428)     return re.test(email);
429) }
430) 
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

431) on_valid_add_contributor_modal=function(e) {
432)   e.preventDefault();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

433)   var group=groups[$('#add_contributor_modal').data('group-uuid')];
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

434)   var name=$('#add_contributor_name')[0].value;
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

435)   edit_id=$('#view-group #edit_id')[0].value;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

436)   if (name=='') {
437)     alert('Vous devez saisir un nom !');
438)     return;
439)   }
440)   var email=$('#add_contributor_email')[0].value;
441)   if (email=='') {
442)     alert('Vous devez saisir un email !');
443)     return;
444)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

445)   duplicate=group.contributorByEmail(email)
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

446)   if (duplicate!=undefined && edit=='-1') {
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

447)     alert('Un contributor utilise déjà cet email !');
448)     return;
449)   }
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

450)   if (!validateEmail(email)) {
451)     alert('Email invalide !');
452)     return;
453)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

454)   if(edit_id=='-1') {
455)     group.addContributor(new Contributor(name,email));
456)   }
457)   else {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

458)     group.replaceContributor(email,new Contributor(name,email));
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

459)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

460)   set_contributors(group);
461)   $('#add_contributor_modal').modal('hide');
462)   groups.save();
Benjamin Renard Display contribution of con...

Benjamin Renard authored 10 years ago

463)   view_group(group,email);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

464) }
465) 
466) on_close_add_contributor_modal=function () {
467)   $('#add_contributor_name')[0].value='';
468)   $('#add_contributor_email')[0].value='';
469) }
470) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

471) on_edit_contributor_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

472)   var group=groups[$('#view-group').data('uuid')];
473)   $('#add_contributor_modal').data('group-uuid',group.uuid);
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

474)   contributor_email=$('#view-group #contributor')[0].value;
475)   contributor=group.contributorByEmail(contributor_email);
476)   $('#view-group #edit_id')[0].value=contributor_email;
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

477)   $('#add_contributor_modal #add_contributor_name')[0].value=contributor.name;
478)   $('#add_contributor_modal #add_contributor_email')[0].value=contributor.email;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

479)   $('#add_contributor_modal #add_contributor_email').attr('disabled',true);
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

480)   $($('#add_contributor_modal h4')[0]).html('Editer un participant');
481)   $($('#add_contributor_modal #add_contributor_submit')[0]).html('Valider');
482)   $('#add_contributor_modal').modal('show');
483) }
484) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

485) on_click_del_contributor_btn=function() {
Benjamin Renard Fix contributor deletion

Benjamin Renard authored 10 years ago

486)   var group=groups[$('#view-group').data('uuid')];
487)   contributor=group.contributorByEmail($('#view-group #contributor')[0].value);
488)   question='Voulez-vous vraiment supprimer '+contributor.name+' ?';
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

489)   myconfirm(question,on_confirm_del_contributor,null,contributor);
490) }
491) 
492) on_confirm_del_contributor=function(contributor) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

493)   var group=groups[$('#view-group').data('uuid')];
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

494)   group.removeContributor(contributor);
Benjamin Renard Display group home after de...

Benjamin Renard authored 10 years ago

495)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

496)   groups.save();
497) }
498) 
499) /********************************
500)  * Add/edit/delete contribution
501)  ********************************/
502) on_show_add_contribution_modal=function(e) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

503)   $('#add_contribution_modal #add_contribution_contributor_email').html($('#view-group #contributor').html());
504)   $('#add_contribution_modal #add_contribution_contributor_email')[0].value=$('#view-group #contributor')[0].value;
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

505)   gid=$('#add_contribution_modal').data('group-uuid');
506)   group=groups[gid];
Benjamin Renard Improve category selection

Benjamin Renard authored 10 years ago

507)   current_cat=$('#add_contribution_modal #add_contribution_category')[0].value;
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

508)   cats="<option value=''>Non définie</option>";
Benjamin Renard Improve category selection

Benjamin Renard authored 10 years ago

509)   for (u in group.getSortedCategories()) {
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

510) 	cats+="<option value='"+u+"'>"+group.categories[u]['name']+"</option>";
511)   }
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

512)   $('#add_contribution_modal #add_contribution_category').html(cats);
Benjamin Renard Improve category selection

Benjamin Renard authored 10 years ago

513)   $('#add_contribution_modal #add_contribution_category')[0].value=current_cat;
Benjamin Renard Fixed autocomplete

Benjamin Renard authored 10 years ago

514)   $('#add_contribution_modal #add_contribution_title').typeahead('destroy');
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

515)   $('#add_contribution_modal #add_contribution_title').typeahead({
516)     hint: true,
517)     highlight: true,
518)     minLength: 1
519)   },
520)   {
521)     name: 'titles',
522)     displayKey: 'value',
523)     source: group.findContributionByTitleMatches()
524)   });
525) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

526)   $('#add_contribution_modal #add_contribution_title').focus();
527) }
528) 
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

529) on_select_contribution_suggestion=function(event,choice,name) {
530)   if (jQuery.type(choice['category'])=='string') {
Benjamin Renard Fixed autocomplete

Benjamin Renard authored 10 years ago

531)     $('#add_contribution_modal #add_contribution_category').val(choice['category']);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

532)   }
533) }
534) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

535) on_click_add_contribution_btn=function() {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

536)   $('#add_contribution_modal').data('group-uuid',$('#view-group').data('uuid'));
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

537)   $('#add_contribution_modal #edit_uuid')[0].value='-1';
bn8 Add pickadate date picker

bn8 authored 10 years ago

538)   $('#add_contribution_date')[0].value=moment().format('DD/MM/YYYY');
Benjamin Renard Customize add_contribution_...

Benjamin Renard authored 10 years ago

539)   $($('#add_contribution_modal h4')[0]).html('Ajouter une contribution');
540)   $($('#add_contribution_modal #add_contribution_submit')[0]).html('Ajouter');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

541)   $('#add_contribution_modal').modal('show');
542) }
543) 
544) on_valid_add_contribution_modal=function(e) {
545)   e.preventDefault();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

546)   var group=groups[$('#add_contribution_modal').data('group-uuid')];
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

547)   var contributor_email=$('#add_contribution_contributor_email')[0].value;
548)   var contributor=group.contributorByEmail(contributor_email);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

549)   if (contributor==undefined) {
550)     alert('Participant inconu !');
551)     return;
552)   }
553)   var title=$('#add_contribution_title')[0].value;
554)   if (title=='') {
555)     $('#add_contribution_title')[0].focus();
556)     alert('Vous devez saisir un titre !');
557)     return;
558)   }
559)   var cost=$('#add_contribution_cost')[0].value;
560)   if (cost=='') {
561)     $('#add_contribution_cost')[0].focus();
562)     alert('Vous devez saisir un coût !');
563)     return;
564)   }
Benjamin Renard Add support of dot and comm...

Benjamin Renard authored 10 years ago

565)   else if(!RegExp('^[0-9]*((,|\.)[0-9]{1,2})*$').test(cost)) {
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

566)     $('#add_contribution_cost')[0].focus();
567)     alert('Coût incorrect !');
568)     return;
569)   }
570)   cost=parseFloat(cost.replace(',','.'));
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

571)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

572)   var date=$('#add_contribution_date')[0].value;
bn8 Add pickadate date picker

bn8 authored 10 years ago

573)   date.replace(/ /g,'');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

574)   if (date!='') {
575)     if(!RegExp('^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]$').test(date)) {
576)       $('#add_contribution_date')[0].focus();
577)       alert('Date incorrect !');
578)       return;
579)     }
580)     date=moment(date,'DD-MM-YYYY').toDate();
581)     if (jQuery.type(date)!='date') {
582)       alert('Date non-reconnu !');
583)       return;
584)     }
585)   }
586)   else {
587)     date=new Date();
588)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

589)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

590)   var cat=$('#add_contribution_category')[0].value;
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

591)   if (cat != '' && !jQuery.type(group.categories[cat])) {
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

592) 	alert('Category incorrect');
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

593) 	return;
594)   }
595)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

596)   if($('#add_contribution_modal #edit_uuid')[0].value=='-1') {
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

597)     group.addContribution(new Contribution(contributor,cost,title,date,cat));
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

598)   }
599)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

600)     contribution_uuid=$('#add_contribution_modal #edit_uuid')[0].value;
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

601)     group.updateContribution(contribution_uuid,new Contribution(contributor,cost,title,date,cat));
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

602)   }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

603)   show_contributions(group,contributor_email);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

604)   $('#add_contribution_modal').modal('hide');
605)   $('#add_contribution_modal form')[0].reset();
606)   groups.save();
607) }
608) 
609) on_close_add_contribution_modal=function () {
610)   $('#add_contribution_modal form')[0].reset();
611) }
612) 
613) on_contribution_delete_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

614)   var group=groups[$('#view-group').data('uuid')];
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

615)   contribution_uuid=$($(e.target).parents('div')[0]).data('uuid');
616)   contribution=group.contributions[contribution_uuid];
617)   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} );
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

618) }
619) 
620) on_confirm_contribution_delete=function(data) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

621)   data.group.deleteContribution(data.contribution_uuid);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

622)   groups.save();
623)   on_contributor_change();
624) }
625) 
626) on_contribution_edit_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

627)   var group=groups[$('#view-group').data('uuid')];
628)   $('#add_contribution_modal').data('group-uuid',$('#view-group').data('uuid'));
Benjamin Renard Customize add_contribution_...

Benjamin Renard authored 10 years ago

629)   $($('#add_contribution_modal h4')[0]).html('Editer une contribution');
630)   $($('#add_contribution_modal #add_contribution_submit')[0]).html('Valider');
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

631)   contribution_uuid=$($(e.target).parents('div')[0]).data('uuid');
632)   contribution=group.contributions[contribution_uuid];
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

633)   $('#add_contribution_modal #add_contribution_contributor_email')[0].value=contribution.contributor.email;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

634)   $('#add_contribution_modal #add_contribution_title')[0].value=contribution.getTitle();
635)   $('#add_contribution_modal #add_contribution_cost')[0].value=contribution.cost;
636)   $('#add_contribution_modal #add_contribution_date')[0].value=moment(contribution.date).format('DD/MM/YYYY');
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

637)   if (contribution.category) {
638) 	$('#add_contribution_modal #add_contribution_category')[0].value=contribution.category;
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

639)   }
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

640)   $('#add_contribution_modal #edit_uuid')[0].value=contribution_uuid;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

641)   $('#add_contribution_modal').modal('show');
642) }
643) 
644) 
645) 
646) /********************
647)  * Clear local data
648)  ********************/
649) clear_local_data=function() {
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

650)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

651)   myconfirm('Etes-vous sûre de vouloir supprimer les données locales ?',on_confirm_clear_local_data);
652) }
653) 
654) on_confirm_clear_local_data=function(data) {
Benjamin Renard Just remove groups from loc...

Benjamin Renard authored 10 years ago

655)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

656)   location.reload();
657) }
658) 
659) /*********************
660)  * View balance
661)  *********************/
662) 
663) on_display_balance_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

664)   group=groups[$('#view-group').data('uuid')];
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

665)   display_balance(group);
666) }
667) 
668) display_balance=function(group) {
669)   bal=group.balance();
670)   tbody=$($('#display_balance_modal tbody')[0]);
671)   tbody.html('');
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

672)   for (c in bal['balance']) {
673)     if(bal['balance'][c]['diff']<0) {
674)       diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>';
675)     }
676)     else {
677)       diff='<td><span class="glyphicon glyphicon-thumbs-up"></span></td>';
678)     }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

679)     tbody.append('<tr><td>'+bal['balance'][c]['name']+'</td><td>'+bal['balance'][c]['total'].toFixed(2)+' €</td>'+diff+'</tr>');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

680)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

681)   $('#display_balance_modal #total-value').html(bal.sum.toFixed(2)+' €');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

682)   $('#display_balance_modal').modal('show');
683) }
684) 
685) /*********************
686)  * Remove group
687)  *********************/
688) 
689) on_remove_group_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

690)   group=groups[$('#view-group').data('uuid')];
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

691)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

692)   myconfirm('Etes-vous sûre de vouloir supprimer le group '+group.name+' ?',on_confirm_remove_group,null,group);
693) }
694) 
695) on_confirm_remove_group=function(group) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

696)   if(groups.removeGroup(group.uuid)) {
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

697)     groups.save();
698)     location.reload();
699)   }
700)   else {
701)     alert('Erreur en supprimant le groupe '+group.name+' :(');
702)   }
703) }
704) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

705) /********************
706)  * Login
707)  ********************/
708) on_close_login_modal=function(e) {
709)   $('#login_modal form')[0].reset();
710) }
711) 
712) sync_server=false;
713) on_valid_login_modal=function(e) {
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

714)   e.preventDefault();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

715)   email=$('#login_modal #login_email')[0].value;
716)   pass=$('#login_modal #login_pass')[0].value;
717)   server=$('#login_modal #login_server')[0].value;
718)   $('#login_modal').modal('hide');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

719)   pleaseWaitShow();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

720)   sync_server.login(server,email,pass,
721)     function(data) {
722)       localStorage.user=JSON.stringify({
723)         'name': data.name,
724)         'email': email,
725)         'password': pass,
726)         'server': server,
bn8 Add lastsync information to...

bn8 authored 10 years ago

727)         'lastsync': null
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

728)       });
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

729)       pleaseWaitHide();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

730)       logged_menu();
731)     },
732)     function(data) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

733)       pleaseWaitHide();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

734)       if (jQuery.type(data) != 'object' && data.loginerror) {
735)         alert(data.loginerror);
736)       }
737)       else {
738)         console.log(data);
739)         alert('Erreur durant la connexion au serveur');
740)       }
741)     }
742)   );
743) }
744) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

745) on_click_go_to_subscribe_btn=function() {
746)   $('#login_modal').modal('hide');
747)   $('#subscribe_modal').modal('show');
748) }
749) 
750) /********************
751)  * Subscribe
752)  ********************/
753) on_close_subscribe_modal=function(e) {
754)   $('#subscribe_modal form')[0].reset();
755) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

756) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

757) sync_server=false;
758) on_valid_subscribe_modal=function(e) {
759)   e.preventDefault();
760)   email=$('#subscribe_modal #subscribe_email')[0].value;
761)   name=$('#subscribe_modal #subscribe_name')[0].value;
762)   pass=$('#subscribe_modal #subscribe_pass')[0].value;
763)   server=$('#subscribe_modal #subscribe_server')[0].value;
764)   $('#subscribe_modal').modal('hide');
765)   pleaseWaitShow();
766)   sync_server.subscribe(server,email,name,pass,
767)     function(data) {
768)       localStorage.user=JSON.stringify({
769)         'name': data.name,
770)         'email': data.email,
771)         'password': data.password,
772)         'server': server,
773)       });
774)       pleaseWaitHide();
775)       logged_menu();
776)       alert('Bienvenu '+data.name+' !');
777)     },
778)     function(data) {
779)       pleaseWaitHide();
780)       if (jQuery.type(data) == 'object' && jQuery.type(data.subscribeerror)!='undefined') {
781)         alert(data.subscribeerror);
782)       }
783)       else {
784)         console.log(data);
785)         alert('Erreur durant la connexion au serveur');
786)       }
787)     }
788)   );
789) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

790) 
791) /********************
792)  * Sync
793)  ********************/
794) on_click_sync_btn=function(e) {
Benjamin Renard Hide navbar after sync btn...

Benjamin Renard authored 10 years ago

795)   navbar_collapse_hide();
Benjamin Renard Manage user global variable

Benjamin Renard authored 10 years ago

796)   if (user) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

797)     pleaseWaitShow();
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

798)     onsuccess=function(data) {
799)       console.log(data);
800)       if (data.groups) {
801)         groups.import(data.groups);
802)         groups.save();
bn8 Add lastsync information to...

bn8 authored 10 years ago

803)         user.lastsync=new Date().getTime();
804)         localStorage.user=JSON.stringify(user);
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

805)         refresh_group_list();
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

806)         pleaseWaitHide();
Benjamin Renard Display home after successf...

Benjamin Renard authored 10 years ago

807)         view_home();
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

808)         alert('Groupes synchronisés');
809)       }
810)       else {
811)         onerror(data);
812)       }
813)     }
814)     onerror=function(data) {
815)       pleaseWaitHide();
816)       console.log(data);
817)       if (jQuery.type(data['loginerror'])!='undefined') {
818)         alert(data['loginerror']);
819)       }
820)       else if (jQuery.type(data['syncerror'])!='undefined') {
821)         alert(data['syncerror']);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

822)       }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

823)       else {
824)         alert('Erreur durant la synchronisation :(');
825)       }
826)     }
827)     sync_server.sync(user.server, user.email, user.password, groups.export(),onsuccess,onerror);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

828)   }
829)   else {
830)     alert("Vous devez vous connecter pour commencer");
831)     $('#login_modal').modal('show');
832)   }
833) }
834) 
835) /*
836)  * User menu
837)  */
838) user=false;
839) logged_menu=function() {
840)   user=JSON.parse(localStorage.user);
841)   $('#user-name').html(user.name);
842)   $('#user-menu li').remove();
843)   menu=$('#user-menu');
844)   menu.html("<li><a id='myaccount_btn'>Mon compte</a></li>"+
845)   "<li><a id='sync_btn'>Synchroniser</a></li>" +
846)   "<li class='divider'></li>" +
847)   "<li><a id='logoff_btn'>Déconnexion</a></li>");
848)   $('#myaccount_btn').bind('click',on_click_myaccount_btn);
849)   $('#sync_btn').bind('click',on_click_sync_btn);
850)   $('#logoff_btn').bind('click',on_click_logoff_btn);
851) }
852) 
853) logged_out_menu=function() {
Benjamin Renard Manage user global variable

Benjamin Renard authored 10 years ago

854)   user=false;
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

855)   $('#user-name').html('Connexion');
856)   $('#user-menu li').remove();
857)   menu=$('#user-menu');
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

858)   menu.html("<li><a id='login_btn'>Connexion</a></li>"+
859) 	"<li><a id='subscribe_btn'>Inscription</a></li>");
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

860)   $('#login_btn').bind('click',on_click_login_btn);
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

861)   $('#subscribe_btn').bind('click',on_click_subscribe_btn);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

862) }
863) 
864) on_click_myaccount_btn=function() {
865)   $('#myaccount_modal #myaccount_email').html(user.email);
866)   $('#myaccount_modal #myaccount_name')[0].value=user.name;
Benjamin Renard Display server in myaccount...

Benjamin Renard authored 10 years ago

867)   $('#myaccount_modal #myaccount_server').html(user.server);
bn8 Add lastsync information to...

bn8 authored 10 years ago

868)   if (user.lastsync) {
869)     $('#myaccount_modal #myaccount_lastsync').html(moment(user.lastsync).format('DD/MM/YYYY HH:mm:ss'));
870)   }
871)   else {
872)     $('#myaccount_modal #myaccount_lastsync').html('Jamais synchronis&eacute;');
873)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

874)   $('#myaccount_modal').modal('show');
875) }
876) 
877) on_click_login_btn=function() {
878)   $('#login_modal').modal('show');
879) }
880) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

881) on_click_subscribe_btn=function() {
882)   $('#subscribe_modal').modal('show');
883) }
884) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

885) on_click_logoff_btn=function() {
886)   delete localStorage.user;
887)   logged_out_menu();
888) }
889) 
Benjamin Renard Add pleaseWaitDialog and fu...

Benjamin Renard authored 10 years ago

890) /*******************
891)  * pleaseWaitDialog
892)  *******************/
893) 
894) pleaseWaitShow=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

895)   $('#please_wait_modal').modal('show');
Benjamin Renard Add pleaseWaitDialog and fu...

Benjamin Renard authored 10 years ago

896) }
897) 
898) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

899)   $('#please_wait_modal').modal('hide');
Benjamin Renard Add pleaseWaitDialog and fu...

Benjamin Renard authored 10 years ago

900) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

901) 
902) /*********************
903)  * Activate
904)  *********************/
905) $( document ).ready( function() {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

906)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

907)   if(typeof(Storage)!=="undefined"){
908)     groups=new GroupList();
909)     groups.loadFromLocalStorage();
910)     refresh_group_list();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

911)     if (jQuery.type(localStorage.user)!='undefined') {
912)       logged_menu();
913)     }
914)     else {
915)       logged_out_menu();
916)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

917)   }
918)   else {
919)     alert('Local storage not supported !');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

920)     pleaseWaitHide();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

921)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

922)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

923)   sync_server=new SyncServer();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

924) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

925)   $('#app-name').bind('click',view_home);
926) 
Benjamin Renard Hide navbar-groupe-collapse...

Benjamin Renard authored 10 years ago

927)   $('#add_group_btn').bind('click',on_click_add_group_btn);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

928)   $('#add_group_submit').bind('click',on_valid_add_group_modal);
929)   $("#add_group_modal").on('shown.bs.modal',on_show_add_group_modal);
930)   $("#add_group_modal").on('hidden.bs.modal',on_close_add_group_modal);
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

931)   $("#add_group_modal form").bind('submit',on_valid_add_group_modal);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

932) 
933)   $('#clear_local_data').bind('click',clear_local_data);
934) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

935)   $('#login_modal').on('hidden.bs.modal',on_close_login_modal);
936)   $('#login_modal #login_submit').bind('click',on_valid_login_modal);
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

937)   $('#login_modal #go_to_subscribe_btn').bind('click',on_click_go_to_subscribe_btn);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

938)   $('#login_modal form').bind('submit',on_valid_login_modal);
939) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

940)   $('#subscribe_modal').on('hidden.bs.modal',on_close_subscribe_modal);
941)   $('#subscribe_modal #subscribe_submit').bind('click',on_valid_subscribe_modal);
942)   $('#subscribe_modal form').bind('submit',on_valid_subscribe_modal);
943) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

944)   $('#view-group #contributor').bind('change',on_contributor_change);
945) 
946)   $('#add_contributor_btn').bind('click',on_click_add_contributor_btn);
947)   $('#add_contributor_submit').bind('click',on_valid_add_contributor_modal);
948)   $("#add_contributor_modal").on('shown.bs.modal',on_show_add_contributor_modal);
949)   $("#add_contributor_modal").on('hidden.bs.modal',on_close_add_contributor_modal);
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

950)   $("#add_contributor_modal form").bind('submit',on_valid_add_contributor_modal);
bn8 Add pickadate date picker

bn8 authored 10 years ago

951)   $("#add_contribution_date").pickadate({'format': 'dd/mm/yyyy','firstDay': 1});
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

952) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

953)   $('#edit_contributor_btn').bind('click',on_edit_contributor_btn_click);
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

954)   $('#trash_contributor_btn').bind('click',on_trash_group_contributors_btn_click);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

955)   $('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
956) 
957)   $('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
958)   $('#add_contribution_submit').bind('click',on_valid_add_contribution_modal);
959)   $("#add_contribution_modal").on('shown.bs.modal',on_show_add_contribution_modal);
960)   $("#add_contribution_modal").on('hidden.bs.modal',on_close_add_contribution_modal);
961)   $("#add_contribution_modal form").on('submit',on_valid_add_contribution_modal);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

962)   $('#add_contribution_modal #add_contribution_title').on('typeahead:selected', on_select_contribution_suggestion);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

963) 
964)   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
965) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

966)   $("#view-group-trash #go-back-group").bind('click',on_go_back_group_btn_click);
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

967)   $("#view-group-trash-contributors #go-back-group").bind('click',on_go_back_group_trash_contributors_btn_click);
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

968) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

969)   $('#categories_group_btn').bind('click',on_categories_group_btn_click);
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

970)   $('#trash_group_btn').bind('click',on_trash_group_btn_click);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

971)   $('#remove_group_btn').bind('click',on_remove_group_btn_click);
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

972)   $('#nav-search-form').bind('submit',on_nav_search_form_submit);
973)   $('#nav-search-form input').bind('input',on_nav_search_form_input);
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

974)   
975)   $('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
976)   $("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
977)   
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

978)   view_home();
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

979)   pleaseWaitHide();