da6aab014683afc14fde6e0017a9df429823c411
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 9 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 9 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 9 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 9 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 9 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 9 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 9 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 9 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');
Benjamin Renard Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

454)   $('#add_contributor_modal').data('edit-id','-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 Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

472)   var edit_id=$('#add_contributor_modal').data('edit-id');
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 Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

483)   if (duplicate!=undefined && edit_id=='-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);
Benjamin Renard Fix add/edit contributor mo...

Benjamin Renard authored 9 years ago

513)   $('#add_contributor_modal').data('edit-id',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 Fix add contribution modal...

Benjamin Renard authored 9 years ago

544)   populate_add_contribution_categories(group);
Benjamin Renard Fixed autocomplete

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

546)   $('#add_contribution_modal #add_contribution_title').typeahead({
547)     hint: true,
548)     highlight: true,
549)     minLength: 1
550)   },
551)   {
552)     name: 'titles',
553)     displayKey: 'value',
554)     source: group.findContributionByTitleMatches()
555)   });
556) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

557)   $('#add_contribution_modal #add_contribution_title').focus();
558) }
559) 
Benjamin Renard Fix add contribution modal...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

582)   }
583) }
584) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

591)   $('#add_contribution_modal').modal('show');
592) }
593) 
594) on_valid_add_contribution_modal=function(e) {
595)   e.preventDefault();
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

616)     $('#add_contribution_cost')[0].focus();
617)     alert('Coût incorrect !');
618)     return;
619)   }
620)   cost=parseFloat(cost.replace(',','.'));
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

621)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

639)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

643) 	return;
644)   }
645)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

648)   }
649)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

654)   $('#add_contribution_modal').modal('hide');
655)   $('#add_contribution_modal form')[0].reset();
656)   groups.save();
657) }
658) 
659) on_close_add_contribution_modal=function () {
660)   $('#add_contribution_modal form')[0].reset();
661) }
662) 
663) on_contribution_delete_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')];
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

668) }
669) 
670) on_confirm_contribution_delete=function(data) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

672)   groups.save();
673)   on_contributor_change();
674) }
675) 
676) on_contribution_edit_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

691)   $('#add_contribution_modal').modal('show');
692) }
693) 
694) 
695) 
696) /********************
697)  * Clear local data
698)  ********************/
699) clear_local_data=function() {
Benjamin Renard Add function navbar_collaps...

Benjamin Renard authored 10 years ago

700)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

705)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

706)   location.reload();
707) }
708) 
709) /*********************
710)  * View balance
711)  *********************/
712) 
713) on_display_balance_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

715)   display_balance(group);
716) }
717) 
718) display_balance=function(group) {
719)   bal=group.balance();
720)   tbody=$($('#display_balance_modal tbody')[0]);
721)   tbody.html('');
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

730)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

732)   $('#display_balance_modal').modal('show');
733) }
734) 
735) /*********************
736)  * Remove group
737)  *********************/
738) 
739) on_remove_group_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

741)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

747)     groups.save();
748)     location.reload();
749)   }
750)   else {
751)     alert('Erreur en supprimant le groupe '+group.name+' :(');
752)   }
753) }
754) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

755) /********************
756)  * Login
757)  ********************/
758) on_close_login_modal=function(e) {
759)   $('#login_modal form')[0].reset();
760) }
761) 
762) sync_server=false;
763) on_valid_login_modal=function(e) {
Benjamin Renard Manage submit event in moda...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

765)   email=$('#login_modal #login_email')[0].value;
766)   pass=$('#login_modal #login_pass')[0].value;
767)   server=$('#login_modal #login_server')[0].value;
768)   $('#login_modal').modal('hide');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

770)   sync_server.login(server,email,pass,
771)     function(data) {
772)       localStorage.user=JSON.stringify({
773)         'name': data.name,
774)         'email': email,
775)         'password': pass,
776)         'server': server,
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

780)       logged_menu();
781)     },
782)     function(data) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

784)       if (jQuery.type(data) != 'object' && data.loginerror) {
785)         alert(data.loginerror);
786)       }
787)       else {
788)         console.log(data);
789)         alert('Erreur durant la connexion au serveur');
790)       }
791)     }
792)   );
793) }
794) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

806) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

840) 
841) /********************
842)  * Sync
843)  ********************/
844) on_click_sync_btn=function(e) {
Benjamin Renard Hide navbar after sync btn...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

848)     onsuccess=function(data) {
849)       console.log(data);
850)       if (data.groups) {
851)         groups.import(data.groups);
852)         groups.save();
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

873)       else {
874)         alert('Erreur durant la synchronisation :(');
875)       }
876)     }
877)     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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

905)   $('#user-name').html('Connexion');
906)   $('#user-menu li').remove();
907)   menu=$('#user-menu');
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

912) }
913) 
914) on_click_myaccount_btn=function() {
915)   $('#myaccount_modal #myaccount_email').html(user.email);
916)   $('#myaccount_modal #myaccount_name')[0].value=user.name;
Benjamin Renard Display server in myaccount...

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

918)   if (user.lastsync) {
919)     $('#myaccount_modal #myaccount_lastsync').html(moment(user.lastsync).format('DD/MM/YYYY HH:mm:ss'));
920)   }
921)   else {
922)     $('#myaccount_modal #myaccount_lastsync').html('Jamais synchronis&eacute;');
923)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

924)   $('#myaccount_modal').modal('show');
925) }
926) 
927) on_click_login_btn=function() {
928)   $('#login_modal').modal('show');
929) }
930) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

931) on_click_subscribe_btn=function() {
932)   $('#subscribe_modal').modal('show');
933) }
934) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

935) on_click_logoff_btn=function() {
936)   delete localStorage.user;
937)   logged_out_menu();
938) }
939) 
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

957) /*******************
958)  * pleaseWaitDialog
959)  *******************/
960) 
961) pleaseWaitShow=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

963) }
964) 
965) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

967) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

968) 
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

969) /**************************
970)  * Cache / Update
971)  *************************/
972) 
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

975)   if (_checkForUpgrade) {
976)     pleaseWaitHide();
977)   }
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

992)   _checkForUpgrade=true;
993)   window.applicationCache.update();
994) }
995) 
996) onNoUpdate = function() {
997)   if (_checkForUpgrade) {
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

999)     _checkForUpgrade=false;
1000)     alert('Aucune mise à jour disponible');
1001)   }
1002) }
1003) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1004) /*********************
1005)  * Activate
1006)  *********************/
1007) $( document ).ready( function() {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

1008)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1009)   if(typeof(Storage)!=="undefined"){
1010)     groups=new GroupList();
1011)     groups.loadFromLocalStorage();
1012)     refresh_group_list();
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

1013)     if (jQuery.type(localStorage.user)!='undefined') {
1014)       logged_menu();
1015)     }
1016)     else {
1017)       logged_out_menu();
1018)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1019)   }
1020)   else {
1021)     alert('Local storage not supported !');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1023)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1024)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1026) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

1034) 
1035)   $('#clear_local_data').bind('click',clear_local_data);
1036) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

1042)   $('#subscribe_modal').on('hidden.bs.modal',on_close_subscribe_modal);
1043)   $('#subscribe_modal #subscribe_submit').bind('click',on_valid_subscribe_modal);
1044)   $('#subscribe_modal form').bind('submit',on_valid_subscribe_modal);
1045) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

1048) 
1049)   $('#add_contributor_btn').bind('click',on_click_add_contributor_btn);
1050)   $('#add_contributor_submit').bind('click',on_valid_add_contributor_modal);
1051)   $("#add_contributor_modal").on('shown.bs.modal',on_show_add_contributor_modal);
1052)   $("#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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

1055) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1058)   $('#del_contributor_btn').bind('click',on_click_del_contributor_btn);
1059) 
1060)   $('#add_contribution_btn').bind('click',on_click_add_contribution_btn);
1061)   $('#add_contribution_submit').bind('click',on_valid_add_contribution_modal);
1062)   $("#add_contribution_modal").on('shown.bs.modal',on_show_add_contribution_modal);
1063)   $("#add_contribution_modal").on('hidden.bs.modal',on_close_add_contribution_modal);
1064)   $("#add_contribution_modal form").on('submit',on_valid_add_contribution_modal);
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1066) 
1067)   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
1068) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

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

1071) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1078)   
1079)   $('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
1080)   $("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
1081)   
Benjamin Renard Manage multiple screen part...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

1084) 
Benjamin Renard Improve applicationCache ma...

Benjamin Renard authored 8 years ago

1085)   if (window.applicationCache.status==window.applicationCache.UNCACHED) {
1086)     $('#update_app').parent().remove();
1087)   }
1088)   else {
1089)     $('#update_app').bind('click',updateApp);
1090)     window.applicationCache.addEventListener('updateready', onUpdateReady);
1091)     window.applicationCache.addEventListener('noupdate', onNoUpdate);
1092)     if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
1093)       onUpdateReady();
1094)     }
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

1095)   }