bea5709efd3433b3f6ab9e3432907fc29b66864b
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 Manage contributor by their...

Benjamin Renard authored 10 years ago

175) show_contributions=function(group,contributor_email) {
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 Manage contributor by their...

Benjamin Renard authored 10 years ago

179)   contributions=group.contributionsByContributorEmail(contributor_email);
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

180)   contributions.reverse();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

189)       if (contributions[idx].category && jQuery.type(group.categories[contributions[idx].category])) {
190) 		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

191) 	  }
Benjamin Renard Upgrade to bootstrap 3

Benjamin Renard authored 10 years ago

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

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

197)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

198)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

233)             'radius': .8,
234)             'tilt': .5,
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

240)                 }
241)             }
242)         }
243)     }
244) });
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

301) /*****************************
302)  * Trash
303)  *****************************/
304) 
305) on_trash_group_btn_click=function(e) {
306)   group=groups[$('#view-group').data('uuid')];
307)   contributor_email=$('#view-group #contributor')[0].value;
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

309)   view_group_trash(group,contributor_email);
310) }
311) 
312) on_go_back_group_btn_click=function(e) {
313)   group=groups[$('#view-group-trash').data('uuid')];
314)   contributor_email=$('#view-group-trash').data('contributor-email');
315)   view_group(group,contributor_email);
316) }
317) 
318) view_group_trash=function(group,contributor_email) {
319)   $('#view-group-trash').data('uuid',group.uuid);
320)   $('#view-group-trash').data('contributor-email',contributor_email);
321)   var tbody=$('#view-group-trash #trash tbody');
322)   tbody.html('');
323)   contributions=group.deletedContributionsByContributorEmail(contributor_email);
324)   contributions.reverse();
325)   if (contributions.length==0) {
326)     tbody.append('<tr><td colspan=3>Aucune contributions</td></tr>');
327)   }
328)   else {
329)     for (idx in contributions) {
330)       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>');
331)     }
332)   }
333)   
334)   $('#view-group-trash .contribution_restore_btn').bind('click',on_contribution_restore_btn_click);
335)  
336)   view_part('#view-group-trash');
337) }
338) 
339) on_contribution_restore_btn_click=function(e) {
340)   var group=groups[$('#view-group-trash').data('uuid')];
341)   contribution_uuid=$($(e.target).parents('tr')[0]).data('uuid');
342)   contribution=group.importContribution(group.deletedContributions[contribution_uuid]);
343)   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} );
344) }
345) 
346) on_confirm_contribution_restore=function(data) {
347)   data.group.restoreContribution(data.contribution_uuid);
348)   groups.save();
349)   view_group(data.group,data.contribution.contributor.email);
350) }
351) 
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

352) on_trash_group_contributors_btn_click=function(e) {
353)   group=groups[$('#view-group').data('uuid')];
354)   view_group_trash_contributors(group);
355) }
356) 
357) on_go_back_group_trash_contributors_btn_click=function(e) {
358)   group=groups[$('#view-group-trash-contributors').data('uuid')];
359)   view_group(group);
360) }
361) 
362) view_group_trash_contributors=function(group) {
363)   $('#view-group-trash-contributors').data('uuid',group.uuid);
364)   var tbody=$('#view-group-trash-contributors #trash tbody');
365)   tbody.html('');
366)   contributors=group.getDeletedContributors();
367)   if (contributors.length==0) {
368)     tbody.append('<tr><td colspan=3>Aucun participant</td></tr>');
369)   }
370)   else {
371)     for (idx in contributors) {
372)       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>');
373)     }
374)   }
375) 
376)   $('#view-group-trash-contributors .contributor_restore_btn').bind('click',on_contributor_restore_btn_click);
377) 
378)   view_part('#view-group-trash-contributors');
379) }
380) 
381) on_contributor_restore_btn_click=function(e) {
382)   var group=groups[$('#view-group-trash-contributors').data('uuid')];
383)   contributor_email=$($(e.target).parents('tr')[0]).data('email');
384)   contributor=group.importContributor(group.deletedContributors[contributor_email]);
385)   myconfirm('Etes-vous sûre de vouloir restaurer '+contributor.name+' ?',on_confirm_contributor_restore,null,{'group':group,'contributor_email':contributor_email, 'contributor': contributor} );
386) }
387) 
388) on_confirm_contributor_restore=function(data) {
389)   data.group.restoreContributor(data.contributor_email);
390)   groups.save();
391)   view_group(data.group,data.contributor_email);
392) }
393) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

394) /******************************
395)  * Add/Edit/remove contributor
396)  ******************************/
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

403)   $('#add_contributor_modal').modal('show');
404) }
405) 
406) on_show_add_contributor_modal=function(e) {
407)   $('#add_contributor_modal #add_contributor_name').focus();
408) }
409) 
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

410) validateEmail=function(email) {
411)     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,}))$/;
412)     return re.test(email);
413) }
414) 
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

420)   if (name=='') {
421)     alert('Vous devez saisir un nom !');
422)     return;
423)   }
424)   var email=$('#add_contributor_email')[0].value;
425)   if (email=='') {
426)     alert('Vous devez saisir un email !');
427)     return;
428)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

431)     alert('Un contributor utilise déjà cet email !');
432)     return;
433)   }
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

434)   if (!validateEmail(email)) {
435)     alert('Email invalide !');
436)     return;
437)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

438)   if(edit_id=='-1') {
439)     group.addContributor(new Contributor(name,email));
440)   }
441)   else {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

443)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

444)   set_contributors(group);
445)   $('#add_contributor_modal').modal('hide');
446)   groups.save();
Benjamin Renard Display contribution of con...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

448) }
449) 
450) on_close_add_contributor_modal=function () {
451)   $('#add_contributor_name')[0].value='';
452)   $('#add_contributor_email')[0].value='';
453) }
454) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

464)   $($('#add_contributor_modal h4')[0]).html('Editer un participant');
465)   $($('#add_contributor_modal #add_contributor_submit')[0]).html('Valider');
466)   $('#add_contributor_modal').modal('show');
467) }
468) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

473)   myconfirm(question,on_confirm_del_contributor,null,contributor);
474) }
475) 
476) on_confirm_del_contributor=function(contributor) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

479)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

480)   groups.save();
481) }
482) 
483) /********************************
484)  * Add/edit/delete contribution
485)  ********************************/
486) on_show_add_contribution_modal=function(e) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

497)   $('#add_contribution_modal #add_contribution_category')[0].value=current_cat;
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

498)   $('#add_contribution_modal #add_contribution_title').typeahead({
499)     hint: true,
500)     highlight: true,
501)     minLength: 1
502)   },
503)   {
504)     name: 'titles',
505)     displayKey: 'value',
506)     source: group.findContributionByTitleMatches()
507)   });
508) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

509)   $('#add_contribution_modal #add_contribution_title').focus();
510) }
511) 
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

512) on_select_contribution_suggestion=function(event,choice,name) {
513)   if (jQuery.type(choice['category'])=='string') {
514)     $('#add_contribution_modal #add_contribution_category')[0].value=choice['category'];
515)   }
516) }
517) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

524)   $('#add_contribution_modal').modal('show');
525) }
526) 
527) on_valid_add_contribution_modal=function(e) {
528)   e.preventDefault();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

532)   if (contributor==undefined) {
533)     alert('Participant inconu !');
534)     return;
535)   }
536)   var title=$('#add_contribution_title')[0].value;
537)   if (title=='') {
538)     $('#add_contribution_title')[0].focus();
539)     alert('Vous devez saisir un titre !');
540)     return;
541)   }
542)   var cost=$('#add_contribution_cost')[0].value;
543)   if (cost=='') {
544)     $('#add_contribution_cost')[0].focus();
545)     alert('Vous devez saisir un coût !');
546)     return;
547)   }
Benjamin Renard Add support of dot and comm...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

549)     $('#add_contribution_cost')[0].focus();
550)     alert('Coût incorrect !');
551)     return;
552)   }
553)   cost=parseFloat(cost.replace(',','.'));
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

554)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

557)   if (date!='') {
558)     if(!RegExp('^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]$').test(date)) {
559)       $('#add_contribution_date')[0].focus();
560)       alert('Date incorrect !');
561)       return;
562)     }
563)     date=moment(date,'DD-MM-YYYY').toDate();
564)     if (jQuery.type(date)!='date') {
565)       alert('Date non-reconnu !');
566)       return;
567)     }
568)   }
569)   else {
570)     date=new Date();
571)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

572)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

576) 	return;
577)   }
578)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

581)   }
582)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

587)   $('#add_contribution_modal').modal('hide');
588)   $('#add_contribution_modal form')[0].reset();
589)   groups.save();
590) }
591) 
592) on_close_add_contribution_modal=function () {
593)   $('#add_contribution_modal form')[0].reset();
594) }
595) 
596) on_contribution_delete_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

601) }
602) 
603) on_confirm_contribution_delete=function(data) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

605)   groups.save();
606)   on_contributor_change();
607) }
608) 
609) on_contribution_edit_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

624)   $('#add_contribution_modal').modal('show');
625) }
626) 
627) 
628) 
629) /********************
630)  * Clear local data
631)  ********************/
632) clear_local_data=function() {
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

633)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

638)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

639)   location.reload();
640) }
641) 
642) /*********************
643)  * View balance
644)  *********************/
645) 
646) on_display_balance_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

648)   display_balance(group);
649) }
650) 
651) display_balance=function(group) {
652)   bal=group.balance();
653)   tbody=$($('#display_balance_modal tbody')[0]);
654)   tbody.html('');
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

655)   for (c in bal['balance']) {
656)     if(bal['balance'][c]['diff']<0) {
657)       diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>';
658)     }
659)     else {
660)       diff='<td><span class="glyphicon glyphicon-thumbs-up"></span></td>';
661)     }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

663)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

665)   $('#display_balance_modal').modal('show');
666) }
667) 
668) /*********************
669)  * Remove group
670)  *********************/
671) 
672) on_remove_group_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

674)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

680)     groups.save();
681)     location.reload();
682)   }
683)   else {
684)     alert('Erreur en supprimant le groupe '+group.name+' :(');
685)   }
686) }
687) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

688) /********************
689)  * Login
690)  ********************/
691) on_close_login_modal=function(e) {
692)   $('#login_modal form')[0].reset();
693) }
694) 
695) sync_server=false;
696) on_valid_login_modal=function(e) {
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

698)   email=$('#login_modal #login_email')[0].value;
699)   pass=$('#login_modal #login_pass')[0].value;
700)   server=$('#login_modal #login_server')[0].value;
701)   $('#login_modal').modal('hide');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

703)   sync_server.login(server,email,pass,
704)     function(data) {
705)       localStorage.user=JSON.stringify({
706)         'name': data.name,
707)         'email': email,
708)         'password': pass,
709)         'server': server,
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

713)       logged_menu();
714)     },
715)     function(data) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

717)       if (jQuery.type(data) != 'object' && data.loginerror) {
718)         alert(data.loginerror);
719)       }
720)       else {
721)         console.log(data);
722)         alert('Erreur durant la connexion au serveur');
723)       }
724)     }
725)   );
726) }
727) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

728) on_click_go_to_subscribe_btn=function() {
729)   $('#login_modal').modal('hide');
730)   $('#subscribe_modal').modal('show');
731) }
732) 
733) /********************
734)  * Subscribe
735)  ********************/
736) on_close_subscribe_modal=function(e) {
737)   $('#subscribe_modal form')[0].reset();
738) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

739) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

740) sync_server=false;
741) on_valid_subscribe_modal=function(e) {
742)   e.preventDefault();
743)   email=$('#subscribe_modal #subscribe_email')[0].value;
744)   name=$('#subscribe_modal #subscribe_name')[0].value;
745)   pass=$('#subscribe_modal #subscribe_pass')[0].value;
746)   server=$('#subscribe_modal #subscribe_server')[0].value;
747)   $('#subscribe_modal').modal('hide');
748)   pleaseWaitShow();
749)   sync_server.subscribe(server,email,name,pass,
750)     function(data) {
751)       localStorage.user=JSON.stringify({
752)         'name': data.name,
753)         'email': data.email,
754)         'password': data.password,
755)         'server': server,
756)       });
757)       pleaseWaitHide();
758)       logged_menu();
759)       alert('Bienvenu '+data.name+' !');
760)     },
761)     function(data) {
762)       pleaseWaitHide();
763)       if (jQuery.type(data) == 'object' && jQuery.type(data.subscribeerror)!='undefined') {
764)         alert(data.subscribeerror);
765)       }
766)       else {
767)         console.log(data);
768)         alert('Erreur durant la connexion au serveur');
769)       }
770)     }
771)   );
772) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

773) 
774) /********************
775)  * Sync
776)  ********************/
777) on_click_sync_btn=function(e) {
Benjamin Renard Hide navbar after sync btn...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

781)     onsuccess=function(data) {
782)       console.log(data);
783)       if (data.groups) {
784)         groups.import(data.groups);
785)         groups.save();
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

791)         alert('Groupes synchronisés');
792)       }
793)       else {
794)         onerror(data);
795)       }
796)     }
797)     onerror=function(data) {
798)       pleaseWaitHide();
799)       console.log(data);
800)       if (jQuery.type(data['loginerror'])!='undefined') {
801)         alert(data['loginerror']);
802)       }
803)       else if (jQuery.type(data['syncerror'])!='undefined') {
804)         alert(data['syncerror']);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

806)       else {
807)         alert('Erreur durant la synchronisation :(');
808)       }
809)     }
810)     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

811)   }
812)   else {
813)     alert("Vous devez vous connecter pour commencer");
814)     $('#login_modal').modal('show');
815)   }
816) }
817) 
818) /*
819)  * User menu
820)  */
821) user=false;
822) logged_menu=function() {
823)   user=JSON.parse(localStorage.user);
824)   $('#user-name').html(user.name);
825)   $('#user-menu li').remove();
826)   menu=$('#user-menu');
827)   menu.html("<li><a id='myaccount_btn'>Mon compte</a></li>"+
828)   "<li><a id='sync_btn'>Synchroniser</a></li>" +
829)   "<li class='divider'></li>" +
830)   "<li><a id='logoff_btn'>Déconnexion</a></li>");
831)   $('#myaccount_btn').bind('click',on_click_myaccount_btn);
832)   $('#sync_btn').bind('click',on_click_sync_btn);
833)   $('#logoff_btn').bind('click',on_click_logoff_btn);
834) }
835) 
836) logged_out_menu=function() {
Benjamin Renard Manage user global variable

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

838)   $('#user-name').html('Connexion');
839)   $('#user-menu li').remove();
840)   menu=$('#user-menu');
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

845) }
846) 
847) on_click_myaccount_btn=function() {
848)   $('#myaccount_modal #myaccount_email').html(user.email);
849)   $('#myaccount_modal #myaccount_name')[0].value=user.name;
Benjamin Renard Display server in myaccount...

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

851)   if (user.lastsync) {
852)     $('#myaccount_modal #myaccount_lastsync').html(moment(user.lastsync).format('DD/MM/YYYY HH:mm:ss'));
853)   }
854)   else {
855)     $('#myaccount_modal #myaccount_lastsync').html('Jamais synchronis&eacute;');
856)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

857)   $('#myaccount_modal').modal('show');
858) }
859) 
860) on_click_login_btn=function() {
861)   $('#login_modal').modal('show');
862) }
863) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

864) on_click_subscribe_btn=function() {
865)   $('#subscribe_modal').modal('show');
866) }
867) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

868) on_click_logoff_btn=function() {
869)   delete localStorage.user;
870)   logged_out_menu();
871) }
872) 
Benjamin Renard Add pleaseWaitDialog and fu...

Benjamin Renard authored 10 years ago

873) /*******************
874)  * pleaseWaitDialog
875)  *******************/
876) 
877) pleaseWaitShow=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

879) }
880) 
881) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

883) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

884) 
885) /*********************
886)  * Activate
887)  *********************/
888) $( document ).ready( function() {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

889)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

890)   if(typeof(Storage)!=="undefined"){
891)     groups=new GroupList();
892)     groups.loadFromLocalStorage();
893)     refresh_group_list();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

894)     if (jQuery.type(localStorage.user)!='undefined') {
895)       logged_menu();
896)     }
897)     else {
898)       logged_out_menu();
899)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

900)   }
901)   else {
902)     alert('Local storage not supported !');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

904)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

905)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

907) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

915) 
916)   $('#clear_local_data').bind('click',clear_local_data);
917) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

923)   $('#subscribe_modal').on('hidden.bs.modal',on_close_subscribe_modal);
924)   $('#subscribe_modal #subscribe_submit').bind('click',on_valid_subscribe_modal);
925)   $('#subscribe_modal form').bind('submit',on_valid_subscribe_modal);
926) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

927)   $('#view-group #contributor').bind('change',on_contributor_change);
928) 
929)   $('#add_contributor_btn').bind('click',on_click_add_contributor_btn);
930)   $('#add_contributor_submit').bind('click',on_valid_add_contributor_modal);
931)   $("#add_contributor_modal").on('shown.bs.modal',on_show_add_contributor_modal);
932)   $("#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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

935) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

938)   $('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
939) 
940)   $('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
941)   $('#add_contribution_submit').bind('click',on_valid_add_contribution_modal);
942)   $("#add_contribution_modal").on('shown.bs.modal',on_show_add_contribution_modal);
943)   $("#add_contribution_modal").on('hidden.bs.modal',on_close_add_contribution_modal);
944)   $("#add_contribution_modal form").on('submit',on_valid_add_contribution_modal);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

946) 
947)   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
948) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

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

951) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

954)   $('#remove_group_btn').bind('click',on_remove_group_btn_click);
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

955)   
956)   $('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
957)   $("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
958)   
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

960)   pleaseWaitHide();