ecbc75df0698218df3481d110d3a9e172bf2c8a1
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)   $('.contribution_delete_btn').bind('click',on_contribution_delete_btn_click);
190)   $('.contribution_edit_btn').bind('click',on_contribution_edit_btn_click);
191) }
192) 
193) show_more_contributions=function(count) {
194)   if (!_current_displayed_contributions_group) return;
195)   var tbody=$($('#view-group #contributions tbody')[0]);
196)    if (_current_displayed_contributions.length==0) {
197)     tbody.html('');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

201)     var previous=0;
202)     if (tbody.children('tr').length>0) {
203)       previous=tbody.children('tr').length-1;
204)     }
205)     if (!count) count=20;
206)     for (var i=0; i<count; i++) {
207)       var idx=previous+i;
208)       if (!_current_displayed_contributions[idx]) break;
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

213)       col_actions='<td><div class="btn-group" data-uuid="'+_current_displayed_contributions[idx].uuid+'"><button type="button" class="btn btn-default btn-sm contribution_edit_btn"><span class="glyphicon glyphicon-edit"></span></button><button type="button" class="btn btn-default btn-sm contribution_delete_btn"><span class="glyphicon glyphicon-trash"></span></button></div></td>';
214)       tbody.append('<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>');
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

226)   _view_group_scroll_lock=false;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

227) }
228) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

259)             'radius': .8,
260)             'tilt': .5,
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

266)                 }
267)             }
268)         }
269)     }
270) });
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

336) on_nav_search_form_submit=function(e) {
337)   e.preventDefault();
338) }
339) 
340) on_nav_search_form_input=function(e) {
341)   var ipt=$(e.target);
342)   var pattern=ipt.val();
343) 
344)   group=groups[$('#view-group').data('uuid')];
345)  
346)   var found=group.searchContributions(pattern);
347)   show_contributions(group,null,found);
348) }
349) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

350) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

444) /******************************
445)  * Add/Edit/remove contributor
446)  ******************************/
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

481)     alert('Un contributor utilise déjà cet email !');
482)     return;
483)   }
Benjamin Renard Add contributor's email val...

Benjamin Renard authored 10 years ago

484)   if (!validateEmail(email)) {
485)     alert('Email invalide !');
486)     return;
487)   }
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

493)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

494)   set_contributors(group);
495)   $('#add_contributor_modal').modal('hide');
496)   groups.save();
Benjamin Renard Display contribution of con...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

523)   myconfirm(question,on_confirm_del_contributor,null,contributor);
524) }
525) 
526) on_confirm_del_contributor=function(contributor) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

529)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

560)   $('#add_contribution_modal #add_contribution_title').focus();
561) }
562) 
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

566)   }
567) }
568) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

605)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

623)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

627) 	return;
628)   }
629)   
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

632)   }
633)   else {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

652) }
653) 
654) on_confirm_contribution_delete=function(data) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

656)   groups.save();
657)   on_contributor_change();
658) }
659) 
660) on_contribution_edit_btn_click=function(e) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

663)   $($('#add_contribution_modal h4')[0]).html('Editer une contribution');
664)   $($('#add_contribution_modal #add_contribution_submit')[0]).html('Valider');
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];
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

684)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

689)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

714)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

725)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

764)       logged_menu();
765)     },
766)     function(data) {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

790) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

824) 
825) /********************
826)  * Sync
827)  ********************/
828) on_click_sync_btn=function(e) {
Benjamin Renard Hide navbar after sync btn...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

832)     onsuccess=function(data) {
833)       console.log(data);
834)       if (data.groups) {
835)         groups.import(data.groups);
836)         groups.save();
bn8 Add lastsync information to...

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

857)       else {
858)         alert('Erreur durant la synchronisation :(');
859)       }
860)     }
861)     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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

889)   $('#user-name').html('Connexion');
890)   $('#user-menu li').remove();
891)   menu=$('#user-menu');
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

915) on_click_subscribe_btn=function() {
916)   $('#subscribe_modal').modal('show');
917) }
918) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

919) on_click_logoff_btn=function() {
920)   delete localStorage.user;
921)   logged_out_menu();
922) }
923) 
Benjamin Renard Add scroll progressive page...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

941) /*******************
942)  * pleaseWaitDialog
943)  *******************/
944) 
945) pleaseWaitShow=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

947) }
948) 
949) pleaseWaitHide=function() {
Benjamin Renard Fix please wait modal

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

951) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

952) 
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

953) /**************************
954)  * Cache / Update
955)  *************************/
956) 
Benjamin Renard Display waiting modal durin...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

959)   if (_checkForUpgrade) {
960)     pleaseWaitHide();
961)   }
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

983)     _checkForUpgrade=false;
984)     alert('Aucune mise à jour disponible');
985)   }
986) }
987) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

988) /*********************
989)  * Activate
990)  *********************/
991) $( document ).ready( function() {
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

992)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1003)   }
1004)   else {
1005)     alert('Local storage not supported !');
Benjamin Renard Use pleaseWaitDialog in som...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1007)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1008)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1010) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

1018) 
1019)   $('#clear_local_data').bind('click',clear_local_data);
1020) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

1039) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1050) 
1051)   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
1052) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

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

1055) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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