b2c343ec0e18f9cb371da4b0d8169f3c89593c37
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) {
Benjamin Renard Improve add group's categor...

Benjamin Renard authored 8 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 8 years ago

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

Benjamin Renard authored 10 years ago

327)   }
328) }
329) 
Benjamin Renard Add export group contributi...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

350)  
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

355) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

449) /******************************
450)  * Add/Edit/remove contributor
451)  ******************************/
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

498)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

534)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 9 years ago

546)   populate_add_contribution_categories(group);
Benjamin Renard Fixed autocomplete

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

584)   }
585) }
586) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

623)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

641)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

645) 	return;
646)   }
647)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

650)   }
651)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

702)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

707)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

732)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

743)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

808) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

965) }
966) 
967) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

969) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

970) 
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

971) /**************************
972)  * Cache / Update
973)  *************************/
974) 
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1010)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1025)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1026)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1028) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

1057) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

1073) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

1087) 
Benjamin Renard Improve applicationCache ma...

Benjamin Renard authored 8 years ago

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

Benjamin Renard authored 9 years ago

1098)   }