668ec09cadc1b6cf966121529e9d10ce46dfdde7
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) {
Benjamin Renard Fix duplicated contribution...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

346)  
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

351) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

494)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

530)   view_group(group);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

606)   
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

624)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

685)   navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

690)   delete localStorage.groups;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

715)   }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

726)   bottom_navbar_collapse_hide();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

791) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

952) }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

953) 
Benjamin Renard Add method to manage cache

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

993)   pleaseWaitShow();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1008)     return;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1009)   }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

1011) 
Benjamin Renard Add link on App Name in Navbar

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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

Benjamin Renard authored 10 years ago

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

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

bn8 authored 10 years ago

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

Benjamin Renard authored 10 years ago

1040) 
Benjamin Renard Add edit contributor feature

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

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

1056) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 9 years ago

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