c939ca1cb7816553c4235047dd60e57330f8ff9f
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 Clear navbar input search v...

Benjamin Renard authored 9 years ago

173) 	$('#nav-search-form input')[0].value='';
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

174) }
175) 
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

176) _current_displayed_contributions=[];
177) _current_displayed_contributions_group=null;
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

179)   var tbody=$($('#view-group #contributions tbody')[0]);
180)   tbody.html('');
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

181)   if (!contributions) {
182)     contributions=group.contributionsByContributorEmail(contributor_email);
183)   }
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

184)   _current_displayed_contributions=contributions;
185)   _current_displayed_contributions_group=group;
186) 
187)   show_more_contributions();
188) }
189) 
190) show_more_contributions=function(count) {
191)   if (!_current_displayed_contributions_group) return;
192)   var tbody=$($('#view-group #contributions tbody')[0]);
193)    if (_current_displayed_contributions.length==0) {
194)     tbody.html('');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

195)     tbody.append('<tr><td colspan=3>Aucune contributions</td></tr>');
196)   }
197)   else {
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

198)     var previous=0;
199)     if (tbody.children('tr').length>0) {
Benjamin Renard Fix duplicated contribution...

Benjamin Renard authored 9 years ago

200)       previous=tbody.children('tr').length;
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

201)     }
202)     if (!count) count=20;
203)     for (var i=0; i<count; i++) {
204)       var idx=previous+i;
205)       if (!_current_displayed_contributions[idx]) break;
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

206)       var cat='';
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

209) 	  }
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

210)       col_actions='<td><div class="btn-group" data-uuid="'+_current_displayed_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 Fix edit/del contrib btn bi...

Benjamin Renard authored 9 years ago

211)       var tr=$('<tr><td>'+_current_displayed_contributions[idx].getTitle()+cat+'</td><td>'+_current_displayed_contributions[idx].cost.toFixed(2)+' €<br/><span class="date">'+moment(_current_displayed_contributions[idx].date).format('DD/MM/YYYY')+'</span></td>'+col_actions+'</tr>');
212) 
213)       tr.find('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click);
214)       tr.find('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click);
215) 
216)       tbody.append(tr);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

217)     }
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

218)   } 
219) }
220) 
221) _view_group_scroll_lock=false;
222) on_view_group_scroll=function(event) {
223)   if (_view_group_scroll_lock) return;
224)   _view_group_scroll_lock=true;
225)   if ($('#view-group').css('display')=='block' && is_on_bottom()) {
226)     show_more_contributions(20);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

227)   }
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

228)   _view_group_scroll_lock=false;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

229) }
230) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

231) on_categories_group_btn_click=function(e) {
232)   group=groups[$('#view-group').data('uuid')];
233)   $('#view-group-categories').data('group-uuid',$('#view-group').data('uuid'));
234)   refresh_group_categories(group);
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

236)   view_part('#view-group-categories');
237) }
238) 
239) refresh_group_categories=function(group) {
240)   ul=$('#view-group-categories ul');
241)   html="";
242)   for(cid in group.getSortedCategories()) {
243)     html+="<li data-uuid='"+cid+"'><span class='cat-color' style='background-color: "+group.categories[cid]['color']+"'></span> "+group.categories[cid]['name']+"</li>";
244)   }
245)   ul.html(html);
246)   $('#view-group-categories ul li').bind('click',on_categories_group_cat_click);
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

247)   
248)   $('#cats-chart').css('width',$(window).width()*0.9+'px');
249)   
250)   $.plot($('#cats-chart'),group.getCategoriesStats(),{
251)     'grid': {
252)         'hoverable': true
253)     }, 
254)     'legend': {
Benjamin Renard Preserve categories's color...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

256)     },
257)     'series': { 
258)         'pie': {
259)             'show': true,
260)             'innerRadius': 0.5,
Benjamin Renard Improve chart

Benjamin Renard authored 10 years ago

261)             'radius': .8,
262)             'tilt': .5,
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

263)             'label': {
264)                 'show': true,
265)                 'formatter': function (label, series) {
Benjamin Renard Improve chart

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

268)                 }
269)             }
270)         }
271)     }
272) });
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

273) }
274) 
275) on_categories_group_cat_click=function(e) {
276)   li=$(e.target);
277)   if (li.prop("tagName")!='LI') {
278)     return true;
279)   }
280)   cid=li.data('uuid');
281)   group=groups[$('#view-group-categories').data('group-uuid')];
282)   cat=group.categories[cid];
283)   li.html("<span class='cat-color' style='background-color: "+cat['color']+"'></span> "+
284)   "<input type='text' value=\""+cat.name+"\"/> "+
285)   "<button class='btn btn-default btn-xs cat_edit'><span class='glyphicon glyphicon-ok'></span></button>"+
286)   "<button class='btn btn-default btn-xs cat_delete'><span class='glyphicon glyphicon-trash'></span></button>");
287)   li.children('button.cat_edit').bind('click',{'li': li,'group': group,'cid': cid},on_categories_group_cat_edit_valid_btn_click);
288)   li.children('button.cat_delete').bind('click',{'li': li,'group': group,'cid': cid},on_categories_group_cat_delete_btn_click);
289) }
290) 
291) on_categories_group_cat_edit_valid_btn_click=function(e) {
292)   name=e.data.li.children('input:first').val();
293)   cat=e.data.group.categories[e.data.cid];
294)   e.data.group.updateCategory(e.data.cid,new Category(name,cat.color));
295)   groups.save();
296)   refresh_group_categories(e.data.group);
297) }
298) 
299) on_categories_group_cat_delete_btn_click=function(e) {
300)   e.data.group.deleteCategory(e.data.cid);
301)   groups.save();
302)   refresh_group_categories(e.data.group);
303) }
304) 
305) on_categories_go_back_group_btn_click=function(e) {
306)   view_group(groups[$('#view-group-categories').data('group-uuid')]);
307) }
308) 
309) on_categories_group_add_btn_click=function(e) {
310)   name=$('#add_category input')[0].value;
311)   
312)   if (jQuery.type(name)!='string' || name=='') {
313)     return;
314)   }
315)   group_uuid=$('#view-group-categories').data('group-uuid');
316)   group=groups[group_uuid];
317)   
318)   if (group.getCategoryByName(name,true)) {
319)     alert('Cette catégorie existe déjà');
320)   }
321)   else {
322)     group.addCategory(new Category(name));
323)     $('#add_category input')[0].value='';
324)     refresh_group_categories(group);
325)   }
326) }
327) 
Benjamin Renard Add export group contributi...

Benjamin Renard authored 10 years ago

328) on_export_group_btn_click=function(e) {
329)   if (user) {
330)     group=$('#view-group').data('uuid');
331)     document.location=user.server+'/export2csv?email='+user.email+'&password='+user.password+'&group='+group;
332)   }
333)   else {
334)     alert('Vous devez être connecté à un serveur pour cela !');
335)   }
336) }
337) 
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

338) on_nav_search_form_submit=function(e) {
339)   e.preventDefault();
340) }
341) 
342) on_nav_search_form_input=function(e) {
343)   var ipt=$(e.target);
344)   var pattern=ipt.val();
345) 
346)   group=groups[$('#view-group').data('uuid')];
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

347)   contributor_email=$('#view-group #contributor')[0].value;
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

348)  
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

349)   var found=group.searchContributions(pattern,contributor_email);
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

350)   show_contributions(group,null,found);
351) }
352) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

353) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

354) /*****************************
355)  * Trash
356)  *****************************/
357) 
358) on_trash_group_btn_click=function(e) {
359)   group=groups[$('#view-group').data('uuid')];
360)   contributor_email=$('#view-group #contributor')[0].value;
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

362)   view_group_trash(group,contributor_email);
363) }
364) 
365) on_go_back_group_btn_click=function(e) {
366)   group=groups[$('#view-group-trash').data('uuid')];
367)   contributor_email=$('#view-group-trash').data('contributor-email');
368)   view_group(group,contributor_email);
369) }
370) 
371) view_group_trash=function(group,contributor_email) {
372)   $('#view-group-trash').data('uuid',group.uuid);
373)   $('#view-group-trash').data('contributor-email',contributor_email);
374)   var tbody=$('#view-group-trash #trash tbody');
375)   tbody.html('');
376)   contributions=group.deletedContributionsByContributorEmail(contributor_email);
377)   contributions.reverse();
378)   if (contributions.length==0) {
379)     tbody.append('<tr><td colspan=3>Aucune contributions</td></tr>');
380)   }
381)   else {
382)     for (idx in contributions) {
383)       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>');
384)     }
385)   }
386)   
387)   $('#view-group-trash .contribution_restore_btn').bind('click',on_contribution_restore_btn_click);
388)  
389)   view_part('#view-group-trash');
390) }
391) 
392) on_contribution_restore_btn_click=function(e) {
393)   var group=groups[$('#view-group-trash').data('uuid')];
394)   contribution_uuid=$($(e.target).parents('tr')[0]).data('uuid');
395)   contribution=group.importContribution(group.deletedContributions[contribution_uuid]);
396)   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} );
397) }
398) 
399) on_confirm_contribution_restore=function(data) {
400)   data.group.restoreContribution(data.contribution_uuid);
401)   groups.save();
402)   view_group(data.group,data.contribution.contributor.email);
403) }
404) 
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

405) on_trash_group_contributors_btn_click=function(e) {
406)   group=groups[$('#view-group').data('uuid')];
407)   view_group_trash_contributors(group);
408) }
409) 
410) on_go_back_group_trash_contributors_btn_click=function(e) {
411)   group=groups[$('#view-group-trash-contributors').data('uuid')];
412)   view_group(group);
413) }
414) 
415) view_group_trash_contributors=function(group) {
416)   $('#view-group-trash-contributors').data('uuid',group.uuid);
417)   var tbody=$('#view-group-trash-contributors #trash tbody');
418)   tbody.html('');
419)   contributors=group.getDeletedContributors();
420)   if (contributors.length==0) {
421)     tbody.append('<tr><td colspan=3>Aucun participant</td></tr>');
422)   }
423)   else {
424)     for (idx in contributors) {
425)       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>');
426)     }
427)   }
428) 
429)   $('#view-group-trash-contributors .contributor_restore_btn').bind('click',on_contributor_restore_btn_click);
430) 
431)   view_part('#view-group-trash-contributors');
432) }
433) 
434) on_contributor_restore_btn_click=function(e) {
435)   var group=groups[$('#view-group-trash-contributors').data('uuid')];
436)   contributor_email=$($(e.target).parents('tr')[0]).data('email');
437)   contributor=group.importContributor(group.deletedContributors[contributor_email]);
438)   myconfirm('Etes-vous sûre de vouloir restaurer '+contributor.name+' ?',on_confirm_contributor_restore,null,{'group':group,'contributor_email':contributor_email, 'contributor': contributor} );
439) }
440) 
441) on_confirm_contributor_restore=function(data) {
442)   data.group.restoreContributor(data.contributor_email);
443)   groups.save();
444)   view_group(data.group,data.contributor_email);
445) }
446) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

447) /******************************
448)  * Add/Edit/remove contributor
449)  ******************************/
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

456)   $('#add_contributor_modal').modal('show');
457) }
458) 
459) on_show_add_contributor_modal=function(e) {
460)   $('#add_contributor_modal #add_contributor_name').focus();
461) }
462) 
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

463) validateEmail=function(email) {
464)     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,}))$/;
465)     return re.test(email);
466) }
467) 
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

473)   if (name=='') {
474)     alert('Vous devez saisir un nom !');
475)     return;
476)   }
477)   var email=$('#add_contributor_email')[0].value;
478)   if (email=='') {
479)     alert('Vous devez saisir un email !');
480)     return;
481)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

484)     alert('Un contributor utilise déjà cet email !');
485)     return;
486)   }
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

487)   if (!validateEmail(email)) {
488)     alert('Email invalide !');
489)     return;
490)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

491)   if(edit_id=='-1') {
492)     group.addContributor(new Contributor(name,email));
493)   }
494)   else {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

496)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

497)   set_contributors(group);
498)   $('#add_contributor_modal').modal('hide');
499)   groups.save();
Benjamin Renard Display contribution of con...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

501) }
502) 
503) on_close_add_contributor_modal=function () {
504)   $('#add_contributor_name')[0].value='';
505)   $('#add_contributor_email')[0].value='';
506) }
507) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

517)   $($('#add_contributor_modal h4')[0]).html('Editer un participant');
518)   $($('#add_contributor_modal #add_contributor_submit')[0]).html('Valider');
519)   $('#add_contributor_modal').modal('show');
520) }
521) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

526)   myconfirm(question,on_confirm_del_contributor,null,contributor);
527) }
528) 
529) on_confirm_del_contributor=function(contributor) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

532)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

533)   groups.save();
534) }
535) 
536) /********************************
537)  * Add/edit/delete contribution
538)  ********************************/
539) on_show_add_contribution_modal=function(e) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

552)   $('#add_contribution_modal #add_contribution_title').typeahead({
553)     hint: true,
554)     highlight: true,
555)     minLength: 1
556)   },
557)   {
558)     name: 'titles',
559)     displayKey: 'value',
560)     source: group.findContributionByTitleMatches()
561)   });
562) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

563)   $('#add_contribution_modal #add_contribution_title').focus();
564) }
565) 
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

569)   }
570) }
571) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

578)   $('#add_contribution_modal').modal('show');
579) }
580) 
581) on_valid_add_contribution_modal=function(e) {
582)   e.preventDefault();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

586)   if (contributor==undefined) {
587)     alert('Participant inconu !');
588)     return;
589)   }
590)   var title=$('#add_contribution_title')[0].value;
591)   if (title=='') {
592)     $('#add_contribution_title')[0].focus();
593)     alert('Vous devez saisir un titre !');
594)     return;
595)   }
596)   var cost=$('#add_contribution_cost')[0].value;
597)   if (cost=='') {
598)     $('#add_contribution_cost')[0].focus();
599)     alert('Vous devez saisir un coût !');
600)     return;
601)   }
Benjamin Renard Add support of dot and comm...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

603)     $('#add_contribution_cost')[0].focus();
604)     alert('Coût incorrect !');
605)     return;
606)   }
607)   cost=parseFloat(cost.replace(',','.'));
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

608)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

611)   if (date!='') {
612)     if(!RegExp('^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]$').test(date)) {
613)       $('#add_contribution_date')[0].focus();
614)       alert('Date incorrect !');
615)       return;
616)     }
617)     date=moment(date,'DD-MM-YYYY').toDate();
618)     if (jQuery.type(date)!='date') {
619)       alert('Date non-reconnu !');
620)       return;
621)     }
622)   }
623)   else {
624)     date=new Date();
625)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

626)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

630) 	return;
631)   }
632)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

635)   }
636)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

641)   $('#add_contribution_modal').modal('hide');
642)   $('#add_contribution_modal form')[0].reset();
643)   groups.save();
644) }
645) 
646) on_close_add_contribution_modal=function () {
647)   $('#add_contribution_modal form')[0].reset();
648) }
649) 
650) on_contribution_delete_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

655) }
656) 
657) on_confirm_contribution_delete=function(data) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

659)   groups.save();
660)   on_contributor_change();
661) }
662) 
663) on_contribution_edit_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

678)   $('#add_contribution_modal').modal('show');
679) }
680) 
681) 
682) 
683) /********************
684)  * Clear local data
685)  ********************/
686) clear_local_data=function() {
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

687)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

692)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

693)   location.reload();
694) }
695) 
696) /*********************
697)  * View balance
698)  *********************/
699) 
700) on_display_balance_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

702)   display_balance(group);
703) }
704) 
705) display_balance=function(group) {
706)   bal=group.balance();
707)   tbody=$($('#display_balance_modal tbody')[0]);
708)   tbody.html('');
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

709)   for (c in bal['balance']) {
710)     if(bal['balance'][c]['diff']<0) {
711)       diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>';
712)     }
713)     else {
714)       diff='<td><span class="glyphicon glyphicon-thumbs-up"></span></td>';
715)     }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

717)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

719)   $('#display_balance_modal').modal('show');
720) }
721) 
722) /*********************
723)  * Remove group
724)  *********************/
725) 
726) on_remove_group_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

728)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

734)     groups.save();
735)     location.reload();
736)   }
737)   else {
738)     alert('Erreur en supprimant le groupe '+group.name+' :(');
739)   }
740) }
741) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

742) /********************
743)  * Login
744)  ********************/
745) on_close_login_modal=function(e) {
746)   $('#login_modal form')[0].reset();
747) }
748) 
749) sync_server=false;
750) on_valid_login_modal=function(e) {
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

752)   email=$('#login_modal #login_email')[0].value;
753)   pass=$('#login_modal #login_pass')[0].value;
754)   server=$('#login_modal #login_server')[0].value;
755)   $('#login_modal').modal('hide');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

757)   sync_server.login(server,email,pass,
758)     function(data) {
759)       localStorage.user=JSON.stringify({
760)         'name': data.name,
761)         'email': email,
762)         'password': pass,
763)         'server': server,
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

767)       logged_menu();
768)     },
769)     function(data) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

771)       if (jQuery.type(data) != 'object' && data.loginerror) {
772)         alert(data.loginerror);
773)       }
774)       else {
775)         console.log(data);
776)         alert('Erreur durant la connexion au serveur');
777)       }
778)     }
779)   );
780) }
781) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

782) on_click_go_to_subscribe_btn=function() {
783)   $('#login_modal').modal('hide');
784)   $('#subscribe_modal').modal('show');
785) }
786) 
787) /********************
788)  * Subscribe
789)  ********************/
790) on_close_subscribe_modal=function(e) {
791)   $('#subscribe_modal form')[0].reset();
792) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

793) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

794) sync_server=false;
795) on_valid_subscribe_modal=function(e) {
796)   e.preventDefault();
797)   email=$('#subscribe_modal #subscribe_email')[0].value;
798)   name=$('#subscribe_modal #subscribe_name')[0].value;
799)   pass=$('#subscribe_modal #subscribe_pass')[0].value;
800)   server=$('#subscribe_modal #subscribe_server')[0].value;
801)   $('#subscribe_modal').modal('hide');
802)   pleaseWaitShow();
803)   sync_server.subscribe(server,email,name,pass,
804)     function(data) {
805)       localStorage.user=JSON.stringify({
806)         'name': data.name,
807)         'email': data.email,
808)         'password': data.password,
809)         'server': server,
810)       });
811)       pleaseWaitHide();
812)       logged_menu();
813)       alert('Bienvenu '+data.name+' !');
814)     },
815)     function(data) {
816)       pleaseWaitHide();
817)       if (jQuery.type(data) == 'object' && jQuery.type(data.subscribeerror)!='undefined') {
818)         alert(data.subscribeerror);
819)       }
820)       else {
821)         console.log(data);
822)         alert('Erreur durant la connexion au serveur');
823)       }
824)     }
825)   );
826) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

827) 
828) /********************
829)  * Sync
830)  ********************/
831) on_click_sync_btn=function(e) {
Benjamin Renard Hide navbar after sync btn...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

835)     onsuccess=function(data) {
836)       console.log(data);
837)       if (data.groups) {
838)         groups.import(data.groups);
839)         groups.save();
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

845)         alert('Groupes synchronisés');
846)       }
847)       else {
848)         onerror(data);
849)       }
850)     }
851)     onerror=function(data) {
852)       pleaseWaitHide();
853)       console.log(data);
854)       if (jQuery.type(data['loginerror'])!='undefined') {
855)         alert(data['loginerror']);
856)       }
857)       else if (jQuery.type(data['syncerror'])!='undefined') {
858)         alert(data['syncerror']);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

860)       else {
861)         alert('Erreur durant la synchronisation :(');
862)       }
863)     }
864)     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

865)   }
866)   else {
867)     alert("Vous devez vous connecter pour commencer");
868)     $('#login_modal').modal('show');
869)   }
870) }
871) 
872) /*
873)  * User menu
874)  */
875) user=false;
876) logged_menu=function() {
877)   user=JSON.parse(localStorage.user);
878)   $('#user-name').html(user.name);
879)   $('#user-menu li').remove();
880)   menu=$('#user-menu');
881)   menu.html("<li><a id='myaccount_btn'>Mon compte</a></li>"+
882)   "<li><a id='sync_btn'>Synchroniser</a></li>" +
883)   "<li class='divider'></li>" +
884)   "<li><a id='logoff_btn'>Déconnexion</a></li>");
885)   $('#myaccount_btn').bind('click',on_click_myaccount_btn);
886)   $('#sync_btn').bind('click',on_click_sync_btn);
887)   $('#logoff_btn').bind('click',on_click_logoff_btn);
888) }
889) 
890) logged_out_menu=function() {
Benjamin Renard Manage user global variable

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

892)   $('#user-name').html('Connexion');
893)   $('#user-menu li').remove();
894)   menu=$('#user-menu');
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

899) }
900) 
901) on_click_myaccount_btn=function() {
902)   $('#myaccount_modal #myaccount_email').html(user.email);
903)   $('#myaccount_modal #myaccount_name')[0].value=user.name;
Benjamin Renard Display server in myaccount...

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

905)   if (user.lastsync) {
906)     $('#myaccount_modal #myaccount_lastsync').html(moment(user.lastsync).format('DD/MM/YYYY HH:mm:ss'));
907)   }
908)   else {
909)     $('#myaccount_modal #myaccount_lastsync').html('Jamais synchronis&eacute;');
910)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

911)   $('#myaccount_modal').modal('show');
912) }
913) 
914) on_click_login_btn=function() {
915)   $('#login_modal').modal('show');
916) }
917) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

918) on_click_subscribe_btn=function() {
919)   $('#subscribe_modal').modal('show');
920) }
921) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

922) on_click_logoff_btn=function() {
923)   delete localStorage.user;
924)   logged_out_menu();
925) }
926) 
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

927) is_on_bottom=function(){
928)   var totalHeight, currentScroll, visibleHeight;
929)   
930)   if (document.documentElement.scrollTop) {
931)     currentScroll = document.documentElement.scrollTop;
932)   }
933)   else {
934)     currentScroll = document.body.scrollTop;
935)   }
936)   
937)   totalHeight = document.body.offsetHeight;
938)   visibleHeight = document.documentElement.clientHeight;
939)   
940)   return (totalHeight <= currentScroll + visibleHeight );
941) }
942)   
943) 
Benjamin Renard Add pleaseWaitDialog and fu...

Benjamin Renard authored 10 years ago

944) /*******************
945)  * pleaseWaitDialog
946)  *******************/
947) 
948) pleaseWaitShow=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

950) }
951) 
952) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

954) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

955) 
Benjamin Renard Add method to manage cache

Benjamin Renard authored 10 years ago

956) /**************************
957)  * Cache / Update
958)  *************************/
959) 
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 10 years ago

960) _checkForUpgrade=false;
Benjamin Renard Add method to manage cache

Benjamin Renard authored 10 years ago

961) onUpdateReady=function() {
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 10 years ago

962)   if (_checkForUpgrade) {
963)     pleaseWaitHide();
964)   }
Benjamin Renard Add method to manage cache

Benjamin Renard authored 10 years ago

965)   myconfirm(
966)     "Une nouvelle version de l'application est disponible. Voulez-vous lancer la mise à jour ?",
967)     onConfirmUpdate,null,{} 
968)   );
969) }
970) 
971) onConfirmUpdate=function() {
972)   window.applicationCache.swapCache();
973)   location.reload();  
974) }
975) 
976) updateApp = function() {
Benjamin Renard hide navbar after update bt...

Benjamin Renard authored 10 years ago

977)   navbar_collapse_hide();
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 10 years ago

978)   pleaseWaitShow();
Benjamin Renard Add method to manage cache

Benjamin Renard authored 10 years ago

979)   _checkForUpgrade=true;
980)   window.applicationCache.update();
981) }
982) 
983) onNoUpdate = function() {
984)   if (_checkForUpgrade) {
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 10 years ago

985)     pleaseWaitHide();
Benjamin Renard Add method to manage cache

Benjamin Renard authored 10 years ago

986)     _checkForUpgrade=false;
987)     alert('Aucune mise à jour disponible');
988)   }
989) }
990) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

991) /*********************
992)  * Activate
993)  *********************/
994) $( document ).ready( function() {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

995)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

996)   if(typeof(Storage)!=="undefined"){
997)     groups=new GroupList();
998)     groups.loadFromLocalStorage();
999)     refresh_group_list();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

1000)     if (jQuery.type(localStorage.user)!='undefined') {
1001)       logged_menu();
1002)     }
1003)     else {
1004)       logged_out_menu();
1005)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1006)   }
1007)   else {
1008)     alert('Local storage not supported !');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1010)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1011)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1013) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

1021) 
1022)   $('#clear_local_data').bind('click',clear_local_data);
1023) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

1029)   $('#subscribe_modal').on('hidden.bs.modal',on_close_subscribe_modal);
1030)   $('#subscribe_modal #subscribe_submit').bind('click',on_valid_subscribe_modal);
1031)   $('#subscribe_modal form').bind('submit',on_valid_subscribe_modal);
1032) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1033)   $('#view-group #contributor').bind('change',on_contributor_change);
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 10 years ago

1034)   $(window).bind('scroll',on_view_group_scroll);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1035) 
1036)   $('#add_contributor_btn').bind('click',on_click_add_contributor_btn);
1037)   $('#add_contributor_submit').bind('click',on_valid_add_contributor_modal);
1038)   $("#add_contributor_modal").on('shown.bs.modal',on_show_add_contributor_modal);
1039)   $("#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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

1042) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1045)   $('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
1046) 
1047)   $('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
1048)   $('#add_contribution_submit').bind('click',on_valid_add_contribution_modal);
1049)   $("#add_contribution_modal").on('shown.bs.modal',on_show_add_contribution_modal);
1050)   $("#add_contribution_modal").on('hidden.bs.modal',on_close_add_contribution_modal);
1051)   $("#add_contribution_modal form").on('submit',on_valid_add_contribution_modal);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1053) 
1054)   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
1055) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

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

1058) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1065)   
1066)   $('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
1067)   $("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
1068)   
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1070)   pleaseWaitHide();
Benjamin Renard Add method to manage cache

Benjamin Renard authored 10 years ago

1071) 
1072)   $('#update_app').bind('click',updateApp);
1073)   window.applicationCache.addEventListener('updateready', onUpdateReady);
1074)   window.applicationCache.addEventListener('noupdate', onNoUpdate);
1075)   if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
1076)     onUpdateReady();
1077)   }