86e98ca0a30006ad4a81591bcb162fdf3747b631
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)         }
112)       }
Benjamin Renard Fix home view when user not...

Benjamin Renard authored 8 years ago

113)       else {
114)         diff=$('<td>&nbsp;</td>');
115)       }
116)       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

117)     }
Benjamin Renard Make group name as link in...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

124)     $('a.home_grp_cat_btn').each(function(idx,a) {
125)       $(a).bind('click',on_home_grp_cat_btn_click);
126)     });
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

141) /****************
142)  * View group
143)  ****************/
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

150) }
151) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

159)       if (email == contributor_email) {
160)         sel=' selected';
161)       }
162)       else {
163)         sel='';
164)       }
165)       $('#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

166)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

167)   }
168) }
169) 
170) on_contributor_change=function(e) {
Benjamin Renard Upgrade to bootstrap 3

Benjamin Renard authored 10 years ago

171) 	if ($('#group-navbar-collapse-1').hasClass('in')) {
172) 		$('#group-navbar-collapse-1').collapse('hide');
173) 	}
174) 	$('#view-group #group-username').html($('#view-group #contributor option:selected').text());
175) 	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

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

Benjamin Renard authored 10 years ago

177) }
178) 
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 9 years ago

179) _current_displayed_contributions=[];
180) _current_displayed_contributions_group=null;
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

184)   if (!contributions) {
185)     contributions=group.contributionsByContributorEmail(contributor_email);
186)   }
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

210)       if (_current_displayed_contributions[idx].category && jQuery.type(_current_displayed_contributions_group.categories[_current_displayed_contributions[idx].category])) {
211) 		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

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

Benjamin Renard authored 9 years ago

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

214)       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>');
215) 
216)       tr.find('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click);
217)       tr.find('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click);
218) 
219)       tbody.append(tr);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

231)   _view_group_scroll_lock=false;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

232) }
233) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

259)     },
260)     'series': { 
261)         'pie': {
262)             'show': true,
263)             'innerRadius': 0.5,
Benjamin Renard Improve chart

Benjamin Renard authored 10 years ago

264)             'radius': .8,
265)             'tilt': .5,
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

266)             'label': {
267)                 'show': true,
268)                 'formatter': function (label, series) {
Benjamin Renard Improve chart

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

271)                 }
272)             }
273)         }
274)     }
275) });
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

276) }
277) 
278) on_categories_group_cat_click=function(e) {
279)   li=$(e.target);
280)   if (li.prop("tagName")!='LI') {
281)     return true;
282)   }
283)   cid=li.data('uuid');
284)   group=groups[$('#view-group-categories').data('group-uuid')];
285)   cat=group.categories[cid];
286)   li.html("<span class='cat-color' style='background-color: "+cat['color']+"'></span> "+
287)   "<input type='text' value=\""+cat.name+"\"/> "+
288)   "<button class='btn btn-default btn-xs cat_edit'><span class='glyphicon glyphicon-ok'></span></button>"+
289)   "<button class='btn btn-default btn-xs cat_delete'><span class='glyphicon glyphicon-trash'></span></button>");
290)   li.children('button.cat_edit').bind('click',{'li': li,'group': group,'cid': cid},on_categories_group_cat_edit_valid_btn_click);
291)   li.children('button.cat_delete').bind('click',{'li': li,'group': group,'cid': cid},on_categories_group_cat_delete_btn_click);
292) }
293) 
294) on_categories_group_cat_edit_valid_btn_click=function(e) {
295)   name=e.data.li.children('input:first').val();
296)   cat=e.data.group.categories[e.data.cid];
297)   e.data.group.updateCategory(e.data.cid,new Category(name,cat.color));
298)   groups.save();
299)   refresh_group_categories(e.data.group);
300) }
301) 
302) on_categories_group_cat_delete_btn_click=function(e) {
303)   e.data.group.deleteCategory(e.data.cid);
304)   groups.save();
305)   refresh_group_categories(e.data.group);
306) }
307) 
308) on_categories_go_back_group_btn_click=function(e) {
309)   view_group(groups[$('#view-group-categories').data('group-uuid')]);
310) }
311) 
312) on_categories_group_add_btn_click=function(e) {
Benjamin Renard Improve add group's categor...

Benjamin Renard authored 8 years ago

313)   e.preventDefault();
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

314)   name=$('#add_category input')[0].value;
315)   
316)   if (jQuery.type(name)!='string' || name=='') {
317)     return;
318)   }
319)   group_uuid=$('#view-group-categories').data('group-uuid');
320)   group=groups[group_uuid];
321)   
322)   if (group.getCategoryByName(name,true)) {
323)     alert('Cette catégorie existe déjà');
324)   }
325)   else {
326)     group.addCategory(new Category(name));
327)     $('#add_category input')[0].value='';
328)     refresh_group_categories(group);
Benjamin Renard Improve add group's categor...

Benjamin Renard authored 8 years ago

329)     $('#add_category input').focus();
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

330)   }
331) }
332) 
Benjamin Renard Add export group contributi...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

343) on_nav_search_form_submit=function(e) {
344)   e.preventDefault();
345) }
346) 
347) on_nav_search_form_input=function(e) {
348)   var ipt=$(e.target);
349)   var pattern=ipt.val();
350) 
351)   group=groups[$('#view-group').data('uuid')];
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

353)  
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

355)   show_contributions(group,null,found);
356) }
357) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

358) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

359) /*****************************
360)  * Trash
361)  *****************************/
362) 
363) on_trash_group_btn_click=function(e) {
364)   group=groups[$('#view-group').data('uuid')];
365)   contributor_email=$('#view-group #contributor')[0].value;
Benjamin Renard Auto collaspse bottom nav bar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

452) /******************************
453)  * Add/Edit/remove contributor
454)  ******************************/
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

457)   $($('#add_contributor_modal h4')[0]).html('Ajouter un participant');
458)   $($('#add_contributor_modal #add_contributor_submit')[0]).html('Ajouter');
Benjamin Renard Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

459)   $('#add_contributor_modal').data('edit-id','-1');
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

461)   $('#add_contributor_modal').modal('show');
462) }
463) 
464) on_show_add_contributor_modal=function(e) {
465)   $('#add_contributor_modal #add_contributor_name').focus();
466) }
467) 
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

468) validateEmail=function(email) {
469)     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,}))$/;
470)     return re.test(email);
471) }
472) 
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

476)   var name=$('#add_contributor_name')[0].value;
Benjamin Renard Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

477)   var edit_id=$('#add_contributor_modal').data('edit-id');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

478)   if (name=='') {
479)     alert('Vous devez saisir un nom !');
480)     return;
481)   }
482)   var email=$('#add_contributor_email')[0].value;
483)   if (email=='') {
484)     alert('Vous devez saisir un email !');
485)     return;
486)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

487)   duplicate=group.contributorByEmail(email)
Benjamin Renard Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

489)     alert('Un contributor utilise déjà cet email !');
490)     return;
491)   }
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

492)   if (!validateEmail(email)) {
493)     alert('Email invalide !');
494)     return;
495)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

496)   if(edit_id=='-1') {
497)     group.addContributor(new Contributor(name,email));
498)   }
499)   else {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

501)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

502)   set_contributors(group);
503)   $('#add_contributor_modal').modal('hide');
504)   groups.save();
Benjamin Renard Display contribution of con...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

506) }
507) 
508) on_close_add_contributor_modal=function () {
509)   $('#add_contributor_name')[0].value='';
510)   $('#add_contributor_email')[0].value='';
511) }
512) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

516)   contributor_email=$('#view-group #contributor')[0].value;
517)   contributor=group.contributorByEmail(contributor_email);
Benjamin Renard Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

518)   $('#add_contributor_modal').data('edit-id',contributor_email);
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

522)   $($('#add_contributor_modal h4')[0]).html('Editer un participant');
523)   $($('#add_contributor_modal #add_contributor_submit')[0]).html('Valider');
524)   $('#add_contributor_modal').modal('show');
525) }
526) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

531)   myconfirm(question,on_confirm_del_contributor,null,contributor);
532) }
533) 
534) on_confirm_del_contributor=function(contributor) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

537)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

538)   groups.save();
539) }
540) 
541) /********************************
542)  * Add/edit/delete contribution
543)  ********************************/
544) on_show_add_contribution_modal=function(e) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

547)   gid=$('#add_contribution_modal').data('group-uuid');
548)   group=groups[gid];
Benjamin Renard Fix add contribution modal...

Benjamin Renard authored 9 years ago

549)   populate_add_contribution_categories(group);
Benjamin Renard Fixed autocomplete

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

562)   $('#add_contribution_modal #add_contribution_title').focus();
563) }
564) 
Benjamin Renard Fix add contribution modal...

Benjamin Renard authored 9 years ago

565) populate_add_contribution_categories=function(group,select) {
566)   if (!group) {
567)     gid=$('#add_contribution_modal').data('group-uuid');
568)     group=groups[gid];
569)   }
570)   current_cat=$('#add_contribution_modal #add_contribution_category')[0].value;
571)   cats="<option value=''>Non définie</option>";
572)   for (u in group.getSortedCategories()) {
573) 	cats+="<option value='"+u+"'>"+group.categories[u]['name']+"</option>";
574)   }
575)   $('#add_contribution_modal #add_contribution_category').html(cats);
576)   if (select) {
577)     $('#add_contribution_modal #add_contribution_category').val(select);
578)   }
579)   else {
580)     $('#add_contribution_modal #add_contribution_category').val(current_cat);
581)   }
582) }
583) 
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

584) on_select_contribution_suggestion=function(event,choice,name) {
585)   if (jQuery.type(choice['category'])=='string') {
Benjamin Renard Fix add contribution modal...

Benjamin Renard authored 9 years ago

586)     populate_add_contribution_categories(null,choice['category']);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

587)   }
588) }
589) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

596)   $('#add_contribution_modal').modal('show');
597) }
598) 
599) on_valid_add_contribution_modal=function(e) {
600)   e.preventDefault();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

604)   if (contributor==undefined) {
605)     alert('Participant inconu !');
606)     return;
607)   }
608)   var title=$('#add_contribution_title')[0].value;
609)   if (title=='') {
610)     $('#add_contribution_title')[0].focus();
611)     alert('Vous devez saisir un titre !');
612)     return;
613)   }
614)   var cost=$('#add_contribution_cost')[0].value;
615)   if (cost=='') {
616)     $('#add_contribution_cost')[0].focus();
617)     alert('Vous devez saisir un coût !');
618)     return;
619)   }
Benjamin Renard Add support of dot and comm...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

621)     $('#add_contribution_cost')[0].focus();
622)     alert('Coût incorrect !');
623)     return;
624)   }
625)   cost=parseFloat(cost.replace(',','.'));
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

626)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

629)   if (date!='') {
630)     if(!RegExp('^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]$').test(date)) {
631)       $('#add_contribution_date')[0].focus();
632)       alert('Date incorrect !');
633)       return;
634)     }
635)     date=moment(date,'DD-MM-YYYY').toDate();
636)     if (jQuery.type(date)!='date') {
637)       alert('Date non-reconnu !');
638)       return;
639)     }
640)   }
641)   else {
642)     date=new Date();
643)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

644)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

648) 	return;
649)   }
650)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

653)   }
654)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

659)   $('#add_contribution_modal').modal('hide');
660)   $('#add_contribution_modal form')[0].reset();
661)   groups.save();
662) }
663) 
664) on_close_add_contribution_modal=function () {
665)   $('#add_contribution_modal form')[0].reset();
666) }
667) 
668) on_contribution_delete_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

673) }
674) 
675) on_confirm_contribution_delete=function(data) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

677)   groups.save();
678)   on_contributor_change();
679) }
680) 
681) on_contribution_edit_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

692)   if (contribution.category) {
Benjamin Renard Fix add contribution modal...

Benjamin Renard authored 9 years ago

693)     populate_add_contribution_categories(group,contribution.category);
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

696)   $('#add_contribution_modal').modal('show');
697) }
698) 
699) 
700) 
701) /********************
702)  * Clear local data
703)  ********************/
704) clear_local_data=function() {
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

705)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

710)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

711)   location.reload();
712) }
713) 
714) /*********************
715)  * View balance
716)  *********************/
717) 
718) on_display_balance_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

720)   display_balance(group);
721) }
722) 
723) display_balance=function(group) {
724)   bal=group.balance();
725)   tbody=$($('#display_balance_modal tbody')[0]);
726)   tbody.html('');
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

727)   for (c in bal['balance']) {
728)     if(bal['balance'][c]['diff']<0) {
729)       diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>';
730)     }
731)     else {
732)       diff='<td><span class="glyphicon glyphicon-thumbs-up"></span></td>';
733)     }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

735)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

737)   $('#display_balance_modal').modal('show');
738) }
739) 
740) /*********************
741)  * Remove group
742)  *********************/
743) 
744) on_remove_group_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

746)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

752)     groups.save();
753)     location.reload();
754)   }
755)   else {
756)     alert('Erreur en supprimant le groupe '+group.name+' :(');
757)   }
758) }
759) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

760) /********************
761)  * Login
762)  ********************/
763) on_close_login_modal=function(e) {
764)   $('#login_modal form')[0].reset();
765) }
766) 
767) sync_server=false;
768) on_valid_login_modal=function(e) {
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

770)   email=$('#login_modal #login_email')[0].value;
771)   pass=$('#login_modal #login_pass')[0].value;
772)   server=$('#login_modal #login_server')[0].value;
773)   $('#login_modal').modal('hide');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

775)   sync_server.login(server,email,pass,
776)     function(data) {
777)       localStorage.user=JSON.stringify({
778)         'name': data.name,
779)         'email': email,
780)         'password': pass,
781)         'server': server,
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

785)       logged_menu();
786)     },
787)     function(data) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

789)       if (jQuery.type(data) != 'object' && data.loginerror) {
790)         alert(data.loginerror);
791)       }
792)       else {
793)         console.log(data);
794)         alert('Erreur durant la connexion au serveur');
795)       }
796)     }
797)   );
798) }
799) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

800) on_click_go_to_subscribe_btn=function() {
801)   $('#login_modal').modal('hide');
802)   $('#subscribe_modal').modal('show');
803) }
804) 
805) /********************
806)  * Subscribe
807)  ********************/
808) on_close_subscribe_modal=function(e) {
809)   $('#subscribe_modal form')[0].reset();
810) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

811) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

812) sync_server=false;
813) on_valid_subscribe_modal=function(e) {
814)   e.preventDefault();
815)   email=$('#subscribe_modal #subscribe_email')[0].value;
816)   name=$('#subscribe_modal #subscribe_name')[0].value;
817)   pass=$('#subscribe_modal #subscribe_pass')[0].value;
818)   server=$('#subscribe_modal #subscribe_server')[0].value;
819)   $('#subscribe_modal').modal('hide');
820)   pleaseWaitShow();
821)   sync_server.subscribe(server,email,name,pass,
822)     function(data) {
823)       localStorage.user=JSON.stringify({
824)         'name': data.name,
825)         'email': data.email,
826)         'password': data.password,
827)         'server': server,
828)       });
829)       pleaseWaitHide();
830)       logged_menu();
831)       alert('Bienvenu '+data.name+' !');
832)     },
833)     function(data) {
834)       pleaseWaitHide();
835)       if (jQuery.type(data) == 'object' && jQuery.type(data.subscribeerror)!='undefined') {
836)         alert(data.subscribeerror);
837)       }
838)       else {
839)         console.log(data);
840)         alert('Erreur durant la connexion au serveur');
841)       }
842)     }
843)   );
844) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

845) 
846) /********************
847)  * Sync
848)  ********************/
849) on_click_sync_btn=function(e) {
Benjamin Renard Hide navbar after sync btn...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

853)     onsuccess=function(data) {
854)       console.log(data);
855)       if (data.groups) {
856)         groups.import(data.groups);
857)         groups.save();
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

863)         alert('Groupes synchronisés');
864)       }
865)       else {
866)         onerror(data);
867)       }
868)     }
869)     onerror=function(data) {
870)       pleaseWaitHide();
871)       console.log(data);
872)       if (jQuery.type(data['loginerror'])!='undefined') {
873)         alert(data['loginerror']);
874)       }
875)       else if (jQuery.type(data['syncerror'])!='undefined') {
876)         alert(data['syncerror']);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

878)       else {
879)         alert('Erreur durant la synchronisation :(');
880)       }
881)     }
882)     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

883)   }
884)   else {
885)     alert("Vous devez vous connecter pour commencer");
886)     $('#login_modal').modal('show');
887)   }
888) }
889) 
890) /*
891)  * User menu
892)  */
893) user=false;
894) logged_menu=function() {
895)   user=JSON.parse(localStorage.user);
896)   $('#user-name').html(user.name);
897)   $('#user-menu li').remove();
898)   menu=$('#user-menu');
899)   menu.html("<li><a id='myaccount_btn'>Mon compte</a></li>"+
900)   "<li><a id='sync_btn'>Synchroniser</a></li>" +
901)   "<li class='divider'></li>" +
902)   "<li><a id='logoff_btn'>Déconnexion</a></li>");
903)   $('#myaccount_btn').bind('click',on_click_myaccount_btn);
904)   $('#sync_btn').bind('click',on_click_sync_btn);
905)   $('#logoff_btn').bind('click',on_click_logoff_btn);
906) }
907) 
908) logged_out_menu=function() {
Benjamin Renard Manage user global variable

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

910)   $('#user-name').html('Connexion');
911)   $('#user-menu li').remove();
912)   menu=$('#user-menu');
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

917) }
918) 
919) on_click_myaccount_btn=function() {
920)   $('#myaccount_modal #myaccount_email').html(user.email);
921)   $('#myaccount_modal #myaccount_name')[0].value=user.name;
Benjamin Renard Display server in myaccount...

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

923)   if (user.lastsync) {
924)     $('#myaccount_modal #myaccount_lastsync').html(moment(user.lastsync).format('DD/MM/YYYY HH:mm:ss'));
925)   }
926)   else {
927)     $('#myaccount_modal #myaccount_lastsync').html('Jamais synchronis&eacute;');
928)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

929)   $('#myaccount_modal').modal('show');
930) }
931) 
932) on_click_login_btn=function() {
933)   $('#login_modal').modal('show');
934) }
935) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

936) on_click_subscribe_btn=function() {
937)   $('#subscribe_modal').modal('show');
938) }
939) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

940) on_click_logoff_btn=function() {
941)   delete localStorage.user;
942)   logged_out_menu();
943) }
944) 
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 9 years ago

945) is_on_bottom=function(){
946)   var totalHeight, currentScroll, visibleHeight;
947)   
948)   if (document.documentElement.scrollTop) {
949)     currentScroll = document.documentElement.scrollTop;
950)   }
951)   else {
952)     currentScroll = document.body.scrollTop;
953)   }
954)   
955)   totalHeight = document.body.offsetHeight;
956)   visibleHeight = document.documentElement.clientHeight;
957)   
958)   return (totalHeight <= currentScroll + visibleHeight );
959) }
960)   
961) 
Benjamin Renard Add pleaseWaitDialog and fu...

Benjamin Renard authored 10 years ago

962) /*******************
963)  * pleaseWaitDialog
964)  *******************/
965) 
966) pleaseWaitShow=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

968) }
969) 
970) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

972) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

973) 
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

974) /**************************
975)  * Cache / Update
976)  *************************/
977) 
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

980)   if (_checkForUpgrade) {
981)     pleaseWaitHide();
982)   }
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

983)   myconfirm(
984)     "Une nouvelle version de l'application est disponible. Voulez-vous lancer la mise à jour ?",
985)     onConfirmUpdate,null,{} 
986)   );
987) }
988) 
989) onConfirmUpdate=function() {
990)   window.applicationCache.swapCache();
991)   location.reload();  
992) }
993) 
994) updateApp = function() {
Benjamin Renard hide navbar after update bt...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

997)   _checkForUpgrade=true;
998)   window.applicationCache.update();
999) }
1000) 
1001) onNoUpdate = function() {
1002)   if (_checkForUpgrade) {
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

1004)     _checkForUpgrade=false;
1005)     alert('Aucune mise à jour disponible');
1006)   }
1007) }
1008) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1009) /*********************
1010)  * Activate
1011)  *********************/
1012) $( document ).ready( function() {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

1013)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1014)   if(typeof(Storage)!=="undefined"){
1015)     groups=new GroupList();
1016)     groups.loadFromLocalStorage();
1017)     refresh_group_list();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

1018)     if (jQuery.type(localStorage.user)!='undefined') {
1019)       logged_menu();
1020)     }
1021)     else {
1022)       logged_out_menu();
1023)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1024)   }
1025)   else {
1026)     alert('Local storage not supported !');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1028)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1029)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1031) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

1039) 
1040)   $('#clear_local_data').bind('click',clear_local_data);
1041) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

1047)   $('#subscribe_modal').on('hidden.bs.modal',on_close_subscribe_modal);
1048)   $('#subscribe_modal #subscribe_submit').bind('click',on_valid_subscribe_modal);
1049)   $('#subscribe_modal form').bind('submit',on_valid_subscribe_modal);
1050) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

1053) 
1054)   $('#add_contributor_btn').bind('click',on_click_add_contributor_btn);
1055)   $('#add_contributor_submit').bind('click',on_valid_add_contributor_modal);
1056)   $("#add_contributor_modal").on('shown.bs.modal',on_show_add_contributor_modal);
1057)   $("#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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

1060) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1063)   $('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
1064) 
1065)   $('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
1066)   $('#add_contribution_submit').bind('click',on_valid_add_contribution_modal);
1067)   $("#add_contribution_modal").on('shown.bs.modal',on_show_add_contribution_modal);
1068)   $("#add_contribution_modal").on('hidden.bs.modal',on_close_add_contribution_modal);
1069)   $("#add_contribution_modal form").on('submit',on_valid_add_contribution_modal);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1071) 
1072)   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
1073) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

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

1076) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1083)   
1084)   $('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
Benjamin Renard Improve add group's categor...

Benjamin Renard authored 8 years ago

1085)   $('#view-group-categories form').bind('submit',on_categories_group_add_btn_click);
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

1086)   $("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
1087)   
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

1090) 
Benjamin Renard Improve applicationCache ma...

Benjamin Renard authored 8 years ago

1091)   if (window.applicationCache.status==window.applicationCache.UNCACHED) {
1092)     $('#update_app').parent().remove();
1093)   }
1094)   else {
1095)     $('#update_app').bind('click',updateApp);
1096)     window.applicationCache.addEventListener('updateready', onUpdateReady);
1097)     window.applicationCache.addEventListener('noupdate', onNoUpdate);
1098)     if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
1099)       onUpdateReady();
1100)     }
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

1101)   }