f04e6fd46691b358548d6b05ef08a1416b7d3367
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 export group contributi...

Benjamin Renard authored 10 years ago

302) on_export_group_btn_click=function(e) {
303)   if (user) {
304)     group=$('#view-group').data('uuid');
305)     document.location=user.server+'/export2csv?email='+user.email+'&password='+user.password+'&group='+group;
306)   }
307)   else {
308)     alert('Vous devez être connecté à un serveur pour cela !');
309)   }
310) }
311) 
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

312) on_nav_search_form_submit=function(e) {
313)   e.preventDefault();
314) }
315) 
316) on_nav_search_form_input=function(e) {
317)   var ipt=$(e.target);
318)   var pattern=ipt.val();
319) 
320)   group=groups[$('#view-group').data('uuid')];
321)  
322)   var found=group.searchContributions(pattern);
323)   show_contributions(group,null,found);
324) }
325) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

326) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

327) /*****************************
328)  * Trash
329)  *****************************/
330) 
331) on_trash_group_btn_click=function(e) {
332)   group=groups[$('#view-group').data('uuid')];
333)   contributor_email=$('#view-group #contributor')[0].value;
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

378) on_trash_group_contributors_btn_click=function(e) {
379)   group=groups[$('#view-group').data('uuid')];
380)   view_group_trash_contributors(group);
381) }
382) 
383) on_go_back_group_trash_contributors_btn_click=function(e) {
384)   group=groups[$('#view-group-trash-contributors').data('uuid')];
385)   view_group(group);
386) }
387) 
388) view_group_trash_contributors=function(group) {
389)   $('#view-group-trash-contributors').data('uuid',group.uuid);
390)   var tbody=$('#view-group-trash-contributors #trash tbody');
391)   tbody.html('');
392)   contributors=group.getDeletedContributors();
393)   if (contributors.length==0) {
394)     tbody.append('<tr><td colspan=3>Aucun participant</td></tr>');
395)   }
396)   else {
397)     for (idx in contributors) {
398)       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>');
399)     }
400)   }
401) 
402)   $('#view-group-trash-contributors .contributor_restore_btn').bind('click',on_contributor_restore_btn_click);
403) 
404)   view_part('#view-group-trash-contributors');
405) }
406) 
407) on_contributor_restore_btn_click=function(e) {
408)   var group=groups[$('#view-group-trash-contributors').data('uuid')];
409)   contributor_email=$($(e.target).parents('tr')[0]).data('email');
410)   contributor=group.importContributor(group.deletedContributors[contributor_email]);
411)   myconfirm('Etes-vous sûre de vouloir restaurer '+contributor.name+' ?',on_confirm_contributor_restore,null,{'group':group,'contributor_email':contributor_email, 'contributor': contributor} );
412) }
413) 
414) on_confirm_contributor_restore=function(data) {
415)   data.group.restoreContributor(data.contributor_email);
416)   groups.save();
417)   view_group(data.group,data.contributor_email);
418) }
419) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

420) /******************************
421)  * Add/Edit/remove contributor
422)  ******************************/
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

429)   $('#add_contributor_modal').modal('show');
430) }
431) 
432) on_show_add_contributor_modal=function(e) {
433)   $('#add_contributor_modal #add_contributor_name').focus();
434) }
435) 
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

436) validateEmail=function(email) {
437)     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,}))$/;
438)     return re.test(email);
439) }
440) 
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

446)   if (name=='') {
447)     alert('Vous devez saisir un nom !');
448)     return;
449)   }
450)   var email=$('#add_contributor_email')[0].value;
451)   if (email=='') {
452)     alert('Vous devez saisir un email !');
453)     return;
454)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

457)     alert('Un contributor utilise déjà cet email !');
458)     return;
459)   }
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

460)   if (!validateEmail(email)) {
461)     alert('Email invalide !');
462)     return;
463)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

464)   if(edit_id=='-1') {
465)     group.addContributor(new Contributor(name,email));
466)   }
467)   else {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

469)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

470)   set_contributors(group);
471)   $('#add_contributor_modal').modal('hide');
472)   groups.save();
Benjamin Renard Display contribution of con...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

474) }
475) 
476) on_close_add_contributor_modal=function () {
477)   $('#add_contributor_name')[0].value='';
478)   $('#add_contributor_email')[0].value='';
479) }
480) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

490)   $($('#add_contributor_modal h4')[0]).html('Editer un participant');
491)   $($('#add_contributor_modal #add_contributor_submit')[0]).html('Valider');
492)   $('#add_contributor_modal').modal('show');
493) }
494) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

499)   myconfirm(question,on_confirm_del_contributor,null,contributor);
500) }
501) 
502) on_confirm_del_contributor=function(contributor) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

505)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

506)   groups.save();
507) }
508) 
509) /********************************
510)  * Add/edit/delete contribution
511)  ********************************/
512) on_show_add_contribution_modal=function(e) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

513)   $('#add_contribution_modal #add_contribution_contributor_email').html($('#view-group #contributor').html());
514)   $('#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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

525)   $('#add_contribution_modal #add_contribution_title').typeahead({
526)     hint: true,
527)     highlight: true,
528)     minLength: 1
529)   },
530)   {
531)     name: 'titles',
532)     displayKey: 'value',
533)     source: group.findContributionByTitleMatches()
534)   });
535) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

536)   $('#add_contribution_modal #add_contribution_title').focus();
537) }
538) 
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

542)   }
543) }
544) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

551)   $('#add_contribution_modal').modal('show');
552) }
553) 
554) on_valid_add_contribution_modal=function(e) {
555)   e.preventDefault();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

559)   if (contributor==undefined) {
560)     alert('Participant inconu !');
561)     return;
562)   }
563)   var title=$('#add_contribution_title')[0].value;
564)   if (title=='') {
565)     $('#add_contribution_title')[0].focus();
566)     alert('Vous devez saisir un titre !');
567)     return;
568)   }
569)   var cost=$('#add_contribution_cost')[0].value;
570)   if (cost=='') {
571)     $('#add_contribution_cost')[0].focus();
572)     alert('Vous devez saisir un coût !');
573)     return;
574)   }
Benjamin Renard Add support of dot and comm...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

576)     $('#add_contribution_cost')[0].focus();
577)     alert('Coût incorrect !');
578)     return;
579)   }
580)   cost=parseFloat(cost.replace(',','.'));
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

581)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

584)   if (date!='') {
585)     if(!RegExp('^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]$').test(date)) {
586)       $('#add_contribution_date')[0].focus();
587)       alert('Date incorrect !');
588)       return;
589)     }
590)     date=moment(date,'DD-MM-YYYY').toDate();
591)     if (jQuery.type(date)!='date') {
592)       alert('Date non-reconnu !');
593)       return;
594)     }
595)   }
596)   else {
597)     date=new Date();
598)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

599)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

603) 	return;
604)   }
605)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

608)   }
609)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

612)   }
Benjamin Renard Fix show contributions afte...

Benjamin Renard authored 10 years ago

613)   show_contributions(group,$('#view-group #contributor')[0].value);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

614)   $('#add_contribution_modal').modal('hide');
615)   $('#add_contribution_modal form')[0].reset();
616)   groups.save();
617) }
618) 
619) on_close_add_contribution_modal=function () {
620)   $('#add_contribution_modal form')[0].reset();
621) }
622) 
623) on_contribution_delete_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

625)   contribution_uuid=$($(e.target).parents('div')[0]).data('uuid');
626)   contribution=group.contributions[contribution_uuid];
627)   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

628) }
629) 
630) on_confirm_contribution_delete=function(data) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

632)   groups.save();
633)   on_contributor_change();
634) }
635) 
636) on_contribution_edit_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

644)   $('#add_contribution_modal #add_contribution_title')[0].value=contribution.getTitle();
645)   $('#add_contribution_modal #add_contribution_cost')[0].value=contribution.cost;
646)   $('#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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

651)   $('#add_contribution_modal').modal('show');
652) }
653) 
654) 
655) 
656) /********************
657)  * Clear local data
658)  ********************/
659) clear_local_data=function() {
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

660)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

665)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

666)   location.reload();
667) }
668) 
669) /*********************
670)  * View balance
671)  *********************/
672) 
673) on_display_balance_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

675)   display_balance(group);
676) }
677) 
678) display_balance=function(group) {
679)   bal=group.balance();
680)   tbody=$($('#display_balance_modal tbody')[0]);
681)   tbody.html('');
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

682)   for (c in bal['balance']) {
683)     if(bal['balance'][c]['diff']<0) {
684)       diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>';
685)     }
686)     else {
687)       diff='<td><span class="glyphicon glyphicon-thumbs-up"></span></td>';
688)     }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

689)     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

690)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

692)   $('#display_balance_modal').modal('show');
693) }
694) 
695) /*********************
696)  * Remove group
697)  *********************/
698) 
699) on_remove_group_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

701)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

707)     groups.save();
708)     location.reload();
709)   }
710)   else {
711)     alert('Erreur en supprimant le groupe '+group.name+' :(');
712)   }
713) }
714) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

715) /********************
716)  * Login
717)  ********************/
718) on_close_login_modal=function(e) {
719)   $('#login_modal form')[0].reset();
720) }
721) 
722) sync_server=false;
723) on_valid_login_modal=function(e) {
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

725)   email=$('#login_modal #login_email')[0].value;
726)   pass=$('#login_modal #login_pass')[0].value;
727)   server=$('#login_modal #login_server')[0].value;
728)   $('#login_modal').modal('hide');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

730)   sync_server.login(server,email,pass,
731)     function(data) {
732)       localStorage.user=JSON.stringify({
733)         'name': data.name,
734)         'email': email,
735)         'password': pass,
736)         'server': server,
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

740)       logged_menu();
741)     },
742)     function(data) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

744)       if (jQuery.type(data) != 'object' && data.loginerror) {
745)         alert(data.loginerror);
746)       }
747)       else {
748)         console.log(data);
749)         alert('Erreur durant la connexion au serveur');
750)       }
751)     }
752)   );
753) }
754) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

755) on_click_go_to_subscribe_btn=function() {
756)   $('#login_modal').modal('hide');
757)   $('#subscribe_modal').modal('show');
758) }
759) 
760) /********************
761)  * Subscribe
762)  ********************/
763) on_close_subscribe_modal=function(e) {
764)   $('#subscribe_modal form')[0].reset();
765) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

766) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

800) 
801) /********************
802)  * Sync
803)  ********************/
804) on_click_sync_btn=function(e) {
Benjamin Renard Hide navbar after sync btn...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

808)     onsuccess=function(data) {
809)       console.log(data);
810)       if (data.groups) {
811)         groups.import(data.groups);
812)         groups.save();
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

818)         alert('Groupes synchronisés');
819)       }
820)       else {
821)         onerror(data);
822)       }
823)     }
824)     onerror=function(data) {
825)       pleaseWaitHide();
826)       console.log(data);
827)       if (jQuery.type(data['loginerror'])!='undefined') {
828)         alert(data['loginerror']);
829)       }
830)       else if (jQuery.type(data['syncerror'])!='undefined') {
831)         alert(data['syncerror']);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

833)       else {
834)         alert('Erreur durant la synchronisation :(');
835)       }
836)     }
837)     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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

865)   $('#user-name').html('Connexion');
866)   $('#user-menu li').remove();
867)   menu=$('#user-menu');
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

872) }
873) 
874) on_click_myaccount_btn=function() {
875)   $('#myaccount_modal #myaccount_email').html(user.email);
876)   $('#myaccount_modal #myaccount_name')[0].value=user.name;
Benjamin Renard Display server in myaccount...

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

878)   if (user.lastsync) {
879)     $('#myaccount_modal #myaccount_lastsync').html(moment(user.lastsync).format('DD/MM/YYYY HH:mm:ss'));
880)   }
881)   else {
882)     $('#myaccount_modal #myaccount_lastsync').html('Jamais synchronis&eacute;');
883)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

884)   $('#myaccount_modal').modal('show');
885) }
886) 
887) on_click_login_btn=function() {
888)   $('#login_modal').modal('show');
889) }
890) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

891) on_click_subscribe_btn=function() {
892)   $('#subscribe_modal').modal('show');
893) }
894) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

895) on_click_logoff_btn=function() {
896)   delete localStorage.user;
897)   logged_out_menu();
898) }
899) 
Benjamin Renard Add pleaseWaitDialog and fu...

Benjamin Renard authored 10 years ago

900) /*******************
901)  * pleaseWaitDialog
902)  *******************/
903) 
904) pleaseWaitShow=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

906) }
907) 
908) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

910) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

911) 
912) /*********************
913)  * Activate
914)  *********************/
915) $( document ).ready( function() {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

916)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

917)   if(typeof(Storage)!=="undefined"){
918)     groups=new GroupList();
919)     groups.loadFromLocalStorage();
920)     refresh_group_list();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

921)     if (jQuery.type(localStorage.user)!='undefined') {
922)       logged_menu();
923)     }
924)     else {
925)       logged_out_menu();
926)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

927)   }
928)   else {
929)     alert('Local storage not supported !');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

931)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

932)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

934) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

938)   $('#add_group_submit').bind('click',on_valid_add_group_modal);
939)   $("#add_group_modal").on('shown.bs.modal',on_show_add_group_modal);
940)   $("#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

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

Benjamin Renard authored 10 years ago

942) 
943)   $('#clear_local_data').bind('click',clear_local_data);
944) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

947)   $('#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

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

Benjamin Renard authored 10 years ago

950)   $('#subscribe_modal').on('hidden.bs.modal',on_close_subscribe_modal);
951)   $('#subscribe_modal #subscribe_submit').bind('click',on_valid_subscribe_modal);
952)   $('#subscribe_modal form').bind('submit',on_valid_subscribe_modal);
953) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

954)   $('#view-group #contributor').bind('change',on_contributor_change);
955) 
956)   $('#add_contributor_btn').bind('click',on_click_add_contributor_btn);
957)   $('#add_contributor_submit').bind('click',on_valid_add_contributor_modal);
958)   $("#add_contributor_modal").on('shown.bs.modal',on_show_add_contributor_modal);
959)   $("#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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

962) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

965)   $('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
966) 
967)   $('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
968)   $('#add_contribution_submit').bind('click',on_valid_add_contribution_modal);
969)   $("#add_contribution_modal").on('shown.bs.modal',on_show_add_contribution_modal);
970)   $("#add_contribution_modal").on('hidden.bs.modal',on_close_add_contribution_modal);
971)   $("#add_contribution_modal form").on('submit',on_valid_add_contribution_modal);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

973) 
974)   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
975) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

976)   $("#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

977)   $("#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

978) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

979)   $('#categories_group_btn').bind('click',on_categories_group_btn_click);
Benjamin Renard Add export group contributi...

Benjamin Renard authored 10 years ago

980)   $('#export_group_btn').bind('click',on_export_group_btn_click);
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

985)   
986)   $('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
987)   $("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
988)   
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

990)   pleaseWaitHide();