5eb426449f564409023a31db54bedba7a948fb4c
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

1) function GroupList() {
Benjamin Renard Add lastChange field in obj...

Benjamin Renard authored 10 years ago

2) 
3)   lastChange=0;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

4)   
5)   this.loadFromLocalStorage=function() {
Benjamin Renard Manage local data loading e...

Benjamin Renard authored 10 years ago

6)     if (jQuery.type(localStorage.groups)!='undefined') {
7)       try {
8)         var data=JSON.parse(localStorage.groups);
9)         this.lastChange=data.lastChange;
10)         for (el in data.groups) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

11)           this[el]=new Group(el,false,data.groups[el]);
Benjamin Renard Manage local data loading e...

Benjamin Renard authored 10 years ago

12)         }
13)       }
14)       catch(e) {
15)         for (el in this) {
16)           if (this.isGroup(this[el])) {
17)             delete this[el];
18)           }
19)         }
20)         myconfirm('Erreur en chargeant les données locales. On les purges ?',
21)           function(data) {
22)             delete localStorage.groups;
23)             location.reload();
24)           }
25)         );
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

26)       }
27)     }
28)   }
29) 
30)   this.export=function() {
Benjamin Renard Add lastChange in GroupList...

Benjamin Renard authored 10 years ago

31)     return {
32)       'lastChange': this.lastChange,
33)       'groups': this.each(function(idx,group) {
34)         return group.export();
35)       })
36)     };
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

37)   }
38) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

39)   this.import=function(groups) {
40)     ret={};
41)     for (el in this) {
42)       if (this.isGroup(this[el])) {
43)         delete ret[el];
44)       }
45)     }
Benjamin Renard Add lastChange in GroupList...

Benjamin Renard authored 10 years ago

46)     this.lastChange=groups.lastChange;
47)     for (el in groups.groups) {
48)       this[el]=new Group(el,false,groups.groups[el]);
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

49)     }
50)     return true;
51)   }
52) 
53) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

54)   this.save=function() {
Benjamin Renard Add lastChange in GroupList...

Benjamin Renard authored 10 years ago

55)     localStorage.groups=JSON.stringify(this.export());
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

56)   }
57) 
58)   this.each=function(fct) {
59)     var idx=0;
Benjamin Renard Improve GroupsList each() m...

Benjamin Renard authored 10 years ago

60)     var ret={};
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

61)     for (el in this) {
62)       if(this.isGroup(this[el])) {
Benjamin Renard Improve GroupsList each() m...

Benjamin Renard authored 10 years ago

63)         ret[el]=fct(idx++,this[el]);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

64)       }
65)     }
Benjamin Renard Improve GroupsList each() m...

Benjamin Renard authored 10 years ago

66)     return ret;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

67)   }
68) 
69)   this.count=function() {
70)     len=0;
Benjamin Renard Improve GroupsList each() m...

Benjamin Renard authored 10 years ago

71)     this.each(function(idx,group) {
72)       len=len+1;
73)     });
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

74)     return len;
75)   }
76) 
77)   this.isGroup=function(el) {
Benjamin Renard Improve GroupList isGroup()...

Benjamin Renard authored 10 years ago

78)     return (jQuery.type(el)=='object' && jQuery.type(el.isGroup)=='function' && el.isGroup());
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

79)   }
80) 
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

81)   this.byName=function(name) {
82)     for (el in this) {
83)       if(this.isGroup(this[el])) {
84)         if (this[el].name==name) {
85)           return this[el];
86)         }
87)       }
88)     }
89)     return false;
90)   }
91) 
92) 
93)   this.removeGroup=function(uuid) {
94)     if (this.isGroup(this[uuid])) {
95)       delete this[uuid];
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

96)       return true;
97)     }
98)     return false;
99)   }
Benjamin Renard Add GroupList balances() me...

Benjamin Renard authored 10 years ago

100) 
101)   this.balances=function(fct) {
102)     return this.each(function(idx,group) {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

103)       bal=group.balance();
104)       bal.name=group.name;
105)       return bal;
Benjamin Renard Add GroupList balances() me...

Benjamin Renard authored 10 years ago

106)     });
107)   }
108) 
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

109)   this.newGroup=function(name,uuid) {
110)     var uuid=uuid||generate_uuid();
111)     this[uuid]=new Group(uuid,name);
112)     return uuid;
113)   }
114) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

115) }
116) 
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

117) function Group(uuid,name,data) {
118)   this.uuid=uuid || generate_uuid();
119)   this.name=name || false;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

120)   this.contributors={};
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

121)   this.deletedContributors={};
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

122)   this.contributions={};
123)   this.deletedContributions={};
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

124)   this.categories={};
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

125)   this.deletedCategories={};
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

126) 
127)   this.isGroup=function() {
128)     return true;
129)   }
130) 
131)   this.export=function() {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

132)     var contributors={};
133)     for (email in this.contributors) {
134)       contributors[email]=this.contributors[email].export();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

136)     var contributions={}
137)     for (uuid in this.contributions) {
138)       contributions[uuid]=this.contributions[uuid].export();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

139)     }
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

140)     var categories={}
141)     for (uuid in this.categories) {
142)       categories[uuid]=this.categories[uuid].export();
143)     }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

144)     return {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

145)       'uuid': this.uuid,
Benjamin Renard Encode/Decode on import/exp...

Benjamin Renard authored 10 years ago

146)       'name': encodeURIComponent(this.name),
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

147)       'contributors': contributors,
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

148)       'deletedContributors': this.deletedContributors,
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

149)       'contributions': contributions,
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

150)       'deletedContributions': this.deletedContributions,
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

151)       'categories': categories,
152)       'deletedCategories': this.deletedCategories
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

153)     };
154)   }
155) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

156)   /*
157)    * Contributors
158)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

159)   this.removeContributor=function(c) {
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

160)     this.deletedContributors[c.email]=c.export();
161)     time=new Date().getTime();
162)     this.deletedContributors[c.email].deletionTime=time;
163)     contributions=this.contributionsByContributorEmail(c.email);
164)     for (idx in contributions) {
165)       this.deleteContribution(contributions[idx].uuid,time);
166)     }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

167)     delete this.contributors[c.email];
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

168)     return true;
169)   }
170) 
171)   this.restoreContributor=function(email) {
172)     if (email in  this.contributors) return;
173)     if (! email in this.deletedContributors) return;
174)     this.contributors[email]=this.importContributor(this.deletedContributors[email]);
175)     contributions=this.deletedContributionsByContributorEmail(email);
176)     for (idx in contributions) {
177)       if (contributions[idx].lastChange==this.deletedContributors[email].deletionTime) {
178)         this.restoreContribution(contributions[idx].uuid);
179)       }
180)     }
181)     delete this.deletedContributors[email];
182)     return true;
183)   }
184) 
185)   this.getDeletedContributors=function() {
186)     var ret=[];
187)     for (email in this.deletedContributors) {
188)       ret.push(this.importContributor(this.deletedContributors[email]));
189)     }
190)     return ret;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

191)   }
192) 
193)   this.contributorByName=function(name) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

194)     for (email in this.contributors) {
195)       if (this.contributors[email].name == name) return this.contributors[email];
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

196)     }
197)     return undefined;
198)   }
199) 
200)   this.contributorByEmail=function(email) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

201)     if (jQuery.type(this.contributors[email])!='undefined') {
202)       return this.contributors[email];
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

203)     }
204)     return undefined;
205)   }
206) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

207)   this.addContributor=function(c) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

208)     this.contributors[c.email]=c;
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

209)   }
210) 
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

211)   this.replaceContributor=function(email,c) {
212)     delete this.contributors[email];
213)     this.contributors[c.email]=c;
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

214)   }
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

215)   
216)   this.importContributor=function(data) {
217)     return new Contributor(
218)       decodeURIComponent(data.name),
219)       data.email
220)     );
221)   }
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

222) 
223)   /*
224)    * Contributions
225)    */
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

226)   this.contributionsByContributorEmail=function(email) {
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

227)     var ret=[];
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

228)     for (uuid in this.contributions) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

229)       if (this.contributions[uuid].contributor.email==email) {
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

230)         ret.push(this.contributions[uuid]);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

231)       }
232)     }
Benjamin Renard Sort contributions search r...

Benjamin Renard authored 9 years ago

233)     return this.sortContributionsByDate(ret);
234)   }
235) 
236)   this.sortContributionsByDate=function(contributions) {
237)     contributions.sort(function(a,b) {
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

238)       if (a.date==b.date) {
239)         return 0;
240)       }
241)       else if(a.date<b.date) {
Benjamin Renard Sort contributions search r...

Benjamin Renard authored 9 years ago

242)         return 1;
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

243)       }
244)       else {
Benjamin Renard Sort contributions search r...

Benjamin Renard authored 9 years ago

245)         return -1;
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

246)       }
247)     });
Benjamin Renard Sort contributions search r...

Benjamin Renard authored 9 years ago

248)     return contributions;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

249)   }
250) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

251)   this.deletedContributionsByContributorEmail=function(email) {
252)     var ret=[];
253)     for (uuid in this.deletedContributions) {
254)       if (this.deletedContributions[uuid].contributor==email) {
255)         ret.push(new Contribution(
256)           this.contributorByEmail(email),
257)           this.deletedContributions[uuid].cost,
258)           decodeURIComponent(this.deletedContributions[uuid].title),
259)           this.deletedContributions[uuid].date,
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

260)           this.deletedContributions[uuid].category,
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

261)           uuid,
262)           this.deletedContributions[uuid].lastChange
263)         ));
264)       }
265)     }
266)     ret.sort(function(a,b) {
267)       if (a.lastChange==b.lastChange) {
268)         return 0;
269)       }
270)       else if(a.lastChange<b.lastChange) {
271)         return -1;
272)       }
273)       else {
274)         return 1;
275)       }
276)     });
277)     return ret;
278)   }
279) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

280)   this.addContribution=function(c) {
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

281)     this.contributions[c.uuid]=c;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

282)   }
283) 
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

284)   this.updateContribution=function(uuid,c) {
285)     c.uuid=uuid;
286)     this.contributions[uuid]=c;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

287)   }
288) 
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

289)   this.deleteContribution=function(uuid,time) {
290)     this.contributions[uuid].lastChange=time || new Date().getTime();
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

291)     this.deletedContributions[uuid]=this.contributions[uuid].export();
292)     delete this.contributions[uuid];
293)   }
294) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

295)   this.restoreContribution=function(uuid) {
296)     this.deletedContributions[uuid].lastChange=new Date().getTime();
297)     this.contributions[uuid]=this.importContribution(this.deletedContributions[uuid]);
298)     delete this.deletedContributions[uuid];
299)   }
300) 
301)   this.importContribution=function(data) {
302)     return new Contribution(
303)       this.contributorByEmail(data.contributor),
304)       data.cost,
305)       decodeURIComponent(data.title),
306)       data.date,
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

307)       data.category,
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

308)       data.uuid,
309)       data.lastChange
310)     );
311)   }
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

312)   
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

313)   this.findContributionByTitleMatches=function() {
314) 	var contributions=this.contributions;
315) 
316)     return function(q, cb) {
317)       var matches, substrRegex;
318)  
319)       // an array that will be populated with substring matches
320)       matches = [];
321)  
322)       // regex used to determine if a string contains the substring `q`
323)       substrRegex = new RegExp(q, 'i');
324) 
325)       var titles=[];
326)       for (uuid in contributions) {
327)         if (substrRegex.test(contributions[uuid].title)) {
328) 		  var title=String(contributions[uuid].title).replace(/^\s+|\s+$/g, '');
329) 		  if (titles.indexOf(title.toLowerCase())!=-1) {
330) 			continue;  
331) 	      }
332) 	      titles.push(title.toLowerCase());
333)           matches.push({
334) 			  value: title,
335) 			  category: contributions[uuid].category
336) 		  });
337)         }
338)       }
339)  
340)       cb(matches);
341)     };
342)   }
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

343) 
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

344)   this.searchContributions=function(pattern,contributor) {
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

345)     var ret=[];
346)     substrRegex = new RegExp(pattern, 'i');
347)     for (uuid in this.contributions) {
Benjamin Renard Filter contributions by cur...

Benjamin Renard authored 9 years ago

348)       if (contributor && contributor!=this.contributions[uuid].contributor.email) {
349)         continue;
350)       }
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

351)       if (substrRegex.test(this.contributions[uuid].title) || substrRegex.test(this.contributions[uuid].cost)) {
352)         ret.push(this.contributions[uuid]);
353)       }
354)     }
Benjamin Renard Sort contributions search r...

Benjamin Renard authored 9 years ago

355)     return this.sortContributionsByDate(ret);
Benjamin Renard Add search contributions fe...

Benjamin Renard authored 10 years ago

356)   }
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

357)   
Benjamin Renard Add getContributionsByCateg...

Benjamin Renard authored 10 years ago

358)   this.getContributionsByCategory=function (category) {
359) 	  var ret={};
360) 	  for (uuid in this.contributions) {
361) 		  if (this.contributions[uuid].category==category.uuid) {
362) 			  ret[uuid]=this.contributions[uuid];
363) 		  }
364) 	  }
365) 	  return ret;
366)   }
367)   
368)   this.findUnusedCategories=function() {
369) 	  var cats={};
370) 	  for (uuid in this.contributions) {
371) 		  cid=this.contributions[uuid].category;
372) 		  if ($.type(cats[cid])=='undefined') {
373) 			  cats[cid]=1;
374) 		  }
375) 		  else {
376) 			  cats[cid]++;
377) 		  }
378) 	  }
379) 	  var ret={};
380) 	  for (cid in this.categories) {
381) 		if ($.type(cats[cid])=='undefined') {
382) 			ret[cid]=this.categories[cid];
383) 		}
384) 	  }
385) 	  return ret;
386)   }
387)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

388)   /*
389)    * Categories
390)    */
391) 
392)   this.addCategory=function(c) {
393)     this.categories[c.uuid]=c;
394)   }
395) 
396)   this.updateCategory=function(uuid,c) {
397)     c.uuid=uuid;
398)     this.categories[uuid]=c;
399)   }
400) 
401)   this.deleteCategory=function(uuid,time) {
402)     this.categories[uuid].lastChange=time || new Date().getTime();
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

403)     this.deletedCategories[uuid]=this.categories[uuid].export();
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

404)     delete this.categories[uuid];
405)   }
406) 
407)   this.restoreCategory=function(uuid) {
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

408)     this.deletedCategories[uuid].lastChange=new Date().getTime();
409)     this.categories[uuid]=this.importCategory(this.deletedCategories[uuid]);
410)     delete this.deletedCategories[uuid];
411)   }
412)   
413)   this.getCategoryByName=function(name,approx) {
414)     if(approx) {
415)       name=String(name).replace(/^\s+|\s+$/g, '').toLowerCase();
416)     }
417)     for (uuid in this.categories) {
418)       if (approx) {
419)         if (String(this.categories[uuid].name).replace(/^\s+|\s+$/g, '').toLowerCase()==name) {
420)           return this.categories[uuid];
421)         }
422)       }
423)       else if(this.categories[uuid].name==name) {
424)         return this.categories[uuid]
425)       }
426)     }
427)     return false;
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

428)   }
429) 
430)   this.importCategory=function(data) {
431)     return new Category(
432)       decodeURIComponent(data.name),
433)       data.color,
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

434)       data.lastChange,
435)       data.uuid
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

436)     );
437)   }
Benjamin Renard Improve category selection

Benjamin Renard authored 10 years ago

438)   
439)   this.getSortedCategories=function() {
440) 	uuids=[];
441) 	for (uuid in this.categories) {
442) 	  uuids.push(uuid);
443) 	}
444) 	tmp_cats=this.categories;
445) 	uuids.sort(function(a,b) {
446) 		return tmp_cats[a]['name'].localeCompare(tmp_cats[b]['name']);
447) 	});
448) 	var ret={};
449) 	for (idx in uuids) {
450)       ret[uuids[idx]]=this.categories[uuids[idx]];
451) 	}
452) 	return ret;
453)   }
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

454)   
455)   this.getCategoriesStats=function() {
456)     var cats={};
457)     for (uuid in this.contributions) {
458)       if (jQuery.type(cats[this.contributions[uuid].category])=='undefined') {
459)         cats[this.contributions[uuid].category]=0;
460)       }
461)       cats[this.contributions[uuid].category]+=this.contributions[uuid].cost;
462)     }
463)     var data=[];
464)     for (cid in cats) {
465)       if (jQuery.type(this.categories[cid])!='undefined') {
466)         data.push({
467)           'label': this.categories[cid].name,
Benjamin Renard Preserve categories's color...

Benjamin Renard authored 10 years ago

468)           'data': cats[cid],
469)           'color': this.categories[cid].color
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

470)         });
471)       }
472)     }
473)     return data;
474)   }
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

475) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

476)   /*
477)    * Balance
478)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

479)   this.balance=function() {
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

480)     total={}
481)     min=-1;
482)     max=0;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

483)     for (email in this.contributors) {
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

484)       var sum=0;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

485)       cl=this.contributionsByContributorEmail(email);
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

486)       for (idx in cl) {
487)         sum+=cl[idx].cost;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

488)       }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

489)       if (min==-1 || min>sum) {
490)           min=sum;
491)         }
492)       if(max<sum) {
493)         max=sum;
494)       }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

495)       total[email]=sum;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

496)     }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

497)     balance={}
498)     var sum=0;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

499)     for (email in total) {
500)       balance[email]={
501)         'name': this.contributors[email].name,
502)         'total': total[email],
503)         'diff': total[email]-max,
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

505)       sum=sum+total[email];
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

506)     }
507)     return {
508)       'balance': balance,
509)       'sum': sum,
510)       'min': min,
511)       'max': max
512)     };
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

513)   }
514) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

515)   /*
516)    * Contructor
517)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

518)   if (jQuery.type(data)=='object') {
519)     try {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

520)       this.uuid=data.uuid;
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

521)       this.name=data.name;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

522)       if (jQuery.type(data.contributors) == 'object') {
523)         for (email in data.contributors) {
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

524)           this.contributors[email]=this.importContributor(data.contributors[email]);
525)         }
526)       }
527)       if (jQuery.type(data.deletedContributors) == 'object') {
528)         for (email in data.deletedContributors) {
529)           this.deletedContributors[email]=data.deletedContributors[email];
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

530)         }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

532)       if (jQuery.type(data.contributions) == 'object') {
533)         for (uuid in data.contributions) {
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

534)           this.contributions[uuid]=this.importContribution(data.contributions[uuid]);
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

535)         }
536)       }
537)       if (jQuery.type(data.deletedContributions) == 'object') {
538)         for (uuid in data.deletedContributions) {
539)           this.deletedContributions[uuid]=data.deletedContributions[uuid];
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

540)         }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

541)       }
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

542)       if (jQuery.type(data.categories) == 'object') {
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

543)         for (uuid in data.categories) {
544)           this.categories[uuid]=this.importCategory(data.categories[uuid]);
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

545)         }
546)       }
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

547)       if (jQuery.type(data.deletedCategories) == 'object') {
548)         for (uuid in data.deletedCategories) {
549)           this.deletedCategories[uuid]=data.deletedCategories[uuid];
550)         }
551)       }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

552)     }
553)     catch (e) {
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

554) 	  console.log(e);
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

555)       alert('Une erreur est survenue en chargeant le groupe '+this.name+' depuis le cache');
556)     }
557)   }
558) }
559) 
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

560) function Contributor(name,email) {
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

561)   this.name=name;
562)   this.email=email;
563)   this.export=function() {
564)     return {
Benjamin Renard Encode/Decode on import/exp...

Benjamin Renard authored 10 years ago

565)       'name': encodeURIComponent(this.name),
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

566)       'email': this.email
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

567)     };
568)   }
569) }
570) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

571) function Category(name,color,lastChange,uuid) {
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

572)   this.name=name;
573)   this.color=color || '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
574)   this.lastChange=lastChange || new Date().getTime();
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

575)   this.uuid=uuid || generate_uuid();
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

576)   this.export=function() {
577)     return {
578)       'name': encodeURIComponent(this.name),
579)       'color': this.color,
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

580)       'lastChange': this.lastChange,
581)       'uuid': this.uuid
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

582)     };
583)   }
584) }
585) 
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

586) function Contribution(contributor,cost,title,date,cat,uuid,lastChange) {
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

587)   this.contributor=contributor;
588)   this.cost=cost;
589)   this.title=title;
Benjamin Renard Transform date of contribut...

Benjamin Renard authored 10 years ago

590)   if (jQuery.type(date)!='date') {
591)     date=moment(date).toDate();
592)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

593)   this.date=date;
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

594)   this.uuid=uuid || generate_uuid();
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

595)   this.category=cat;
Benjamin Renard Add lastChange field in obj...

Benjamin Renard authored 10 years ago

596)   this.lastChange=lastChange || new Date().getTime();
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

597)   this.export=function() {
598)     return {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

599)       'contributor': this.contributor.email,
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

600)       'uuid': this.uuid,
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

601)       'cost': this.cost,
Benjamin Renard Encode/Decode on import/exp...

Benjamin Renard authored 10 years ago

602)       'title': encodeURIComponent(this.title),
Benjamin Renard Transform date of contribut...

Benjamin Renard authored 10 years ago

603)       'date': this.date.getTime(),
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

604)       'category': this.category,
Benjamin Renard Add lastChange field in obj...

Benjamin Renard authored 10 years ago

605)       'lastChange': this.lastChange,
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

606)     };
607)   }
608) 
609)   this.getTitle=function() {
610)     if (jQuery.type(this.title)=='string') {
611)       return this.title;
612)     }
613)     return '';
614)   }
615) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

616) 
617) function SyncServer() {
618)   this.url=false;
619)   this.email=false;
620)   this.password=false;
621)   this.logged=false;
622) 
623)   this.login=function(url,email,password,onsuccess,onerror) {
624)     this.url=url;
625)     this.email=email;
626)     this.password=password;
627) 
628)     try {
629)       jQuery.getJSON(
630)         this.url+'/login',
Benjamin Renard Add time in request to avoi...

Benjamin Renard authored 10 years ago

631)         {'email':email,'password':password, 'time': new Date().getTime()},
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

632)         function(data, textStatus) {
633)           console.log(data);
634)           if (textStatus=='success') {
Benjamin Renard Fixed login error display

Benjamin Renard authored 10 years ago

635)             if(jQuery.type(data.email) != 'undefined' && jQuery.type(data.name) != 'undefined') {
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

636)               console.log('Login success return');
637)               console.log(onsuccess);
638)               onsuccess(data);
639)               return true;
640)             }
641)           }
642)           onerror(data);
643)         }
644)       ).fail(onerror);
645)     }
646)     catch(e) {
647)       if(jQuery.type(onerror)=='function') {
648)         onerror();
649)       }
650)     }
651)   }
652) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

653)   this.subscribe=function(url,email,name,password,onsuccess,onerror) {
654)     this.url=url;
655)     this.email=email;
656)     this.name=name;
657)     this.password=password;
658) 
659)     try {
660)       jQuery.getJSON(
661)         this.url+'/subscribe',
Benjamin Renard Add time in request to avoi...

Benjamin Renard authored 10 years ago

662)         {'email':email,'name': name,'password':password, 'time': new Date().getTime()},
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

663)         function(data, textStatus) {
664)           console.log(data);
665)           if (textStatus=='success') {
666)             if(jQuery.type(data.email) != 'undefined' && jQuery.type(data.name) != 'undefined') {
667)               onsuccess(data);
668)               return true;
669)             }
670)           }
671)           onerror(data);
672)           return false;
673)         }
674)       ).fail(onerror);
675)     }
676)     catch(e) {
677)       if(jQuery.type(onerror)=='function') {
678)         onerror();
679)       }
680)     }
681)   }
682) 
683) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

684)   this.sync=function(url,email,password,groups,onsuccess,onerror) {
685)     this.url=url;
686)     this.email=email;
687)     this.password=password;
688)     try {
Benjamin Renard Use POST instead of GET req...

Benjamin Renard authored 10 years ago

689)       jQuery.post(
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

690)         this.url+'/sync',
691)         {
692)           'email':email,
693)           'password':password,
694)           'groups': JSON.stringify(groups)
695)         },
696)         function(data, textStatus) {
697)           console.log(data);
698)           if (textStatus=='success') {
699)             if(jQuery.type(data.groups)) {
700)               console.log('Sync success return');
701)               onsuccess(data);
702)               return true;
703)             }
704)           }
705)           onerror(data);
Benjamin Renard Use POST instead of GET req...

Benjamin Renard authored 10 years ago

706)         },
707)         'json'