384ead0025d406c172d15f959ad196015e867bc4
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 contribution by date o...

Benjamin Renard authored 10 years ago

233)     ret.sort(function(a,b) {
234)       if (a.date==b.date) {
235)         return 0;
236)       }
237)       else if(a.date<b.date) {
238)         return -1;
239)       }
240)       else {
241)         return 1;
242)       }
243)     });
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

244)     return ret;
245)   }
246) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

278)   }
279) 
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

280)   this.updateContribution=function(uuid,c) {
281)     c.uuid=uuid;
282)     this.contributions[uuid]=c;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

283)   }
284) 
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

287)     this.deletedContributions[uuid]=this.contributions[uuid].export();
288)     delete this.contributions[uuid];
289)   }
290) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

304)       data.uuid,
305)       data.lastChange
306)     );
307)   }
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

308)   
Benjamin Renard Manage contribution suggest...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

340)   this.getContributionsByCategory=function (category) {
341) 	  var ret={};
342) 	  for (uuid in this.contributions) {
343) 		  if (this.contributions[uuid].category==category.uuid) {
344) 			  ret[uuid]=this.contributions[uuid];
345) 		  }
346) 	  }
347) 	  return ret;
348)   }
349)   
350)   this.findUnusedCategories=function() {
351) 	  var cats={};
352) 	  for (uuid in this.contributions) {
353) 		  cid=this.contributions[uuid].category;
354) 		  if ($.type(cats[cid])=='undefined') {
355) 			  cats[cid]=1;
356) 		  }
357) 		  else {
358) 			  cats[cid]++;
359) 		  }
360) 	  }
361) 	  var ret={};
362) 	  for (cid in this.categories) {
363) 		if ($.type(cats[cid])=='undefined') {
364) 			ret[cid]=this.categories[cid];
365) 		}
366) 	  }
367) 	  return ret;
368)   }
369)   
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

370)   /*
371)    * Categories
372)    */
373) 
374)   this.addCategory=function(c) {
375)     this.categories[c.uuid]=c;
376)   }
377) 
378)   this.updateCategory=function(uuid,c) {
379)     c.uuid=uuid;
380)     this.categories[uuid]=c;
381)   }
382) 
383)   this.deleteCategory=function(uuid,time) {
384)     this.categories[uuid].lastChange=time || new Date().getTime();
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

386)     delete this.categories[uuid];
387)   }
388) 
389)   this.restoreCategory=function(uuid) {
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

390)     this.deletedCategories[uuid].lastChange=new Date().getTime();
391)     this.categories[uuid]=this.importCategory(this.deletedCategories[uuid]);
392)     delete this.deletedCategories[uuid];
393)   }
394)   
395)   this.getCategoryByName=function(name,approx) {
396)     if(approx) {
397)       name=String(name).replace(/^\s+|\s+$/g, '').toLowerCase();
398)     }
399)     for (uuid in this.categories) {
400)       if (approx) {
401)         if (String(this.categories[uuid].name).replace(/^\s+|\s+$/g, '').toLowerCase()==name) {
402)           return this.categories[uuid];
403)         }
404)       }
405)       else if(this.categories[uuid].name==name) {
406)         return this.categories[uuid]
407)       }
408)     }
409)     return false;
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

410)   }
411) 
412)   this.importCategory=function(data) {
413)     return new Category(
414)       decodeURIComponent(data.name),
415)       data.color,
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

416)       data.lastChange,
417)       data.uuid
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

418)     );
419)   }
Benjamin Renard Improve category selection

Benjamin Renard authored 10 years ago

420)   
421)   this.getSortedCategories=function() {
422) 	uuids=[];
423) 	for (uuid in this.categories) {
424) 	  uuids.push(uuid);
425) 	}
426) 	tmp_cats=this.categories;
427) 	uuids.sort(function(a,b) {
428) 		return tmp_cats[a]['name'].localeCompare(tmp_cats[b]['name']);
429) 	});
430) 	var ret={};
431) 	for (idx in uuids) {
432)       ret[uuids[idx]]=this.categories[uuids[idx]];
433) 	}
434) 	return ret;
435)   }
Benjamin Renard Add categories chart

Benjamin Renard authored 10 years ago

436)   
437)   this.getCategoriesStats=function() {
438)     var cats={};
439)     for (uuid in this.contributions) {
440)       if (jQuery.type(cats[this.contributions[uuid].category])=='undefined') {
441)         cats[this.contributions[uuid].category]=0;
442)       }
443)       cats[this.contributions[uuid].category]+=this.contributions[uuid].cost;
444)     }
445)     var data=[];
446)     for (cid in cats) {
447)       if (jQuery.type(this.categories[cid])!='undefined') {
448)         data.push({
449)           'label': this.categories[cid].name,
Benjamin Renard Preserve categories's color...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

452)         });
453)       }
454)     }
455)     return data;
456)   }
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

457) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

458)   /*
459)    * Balance
460)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

462)     total={}
463)     min=-1;
464)     max=0;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

470)       }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

471)       if (min==-1 || min>sum) {
472)           min=sum;
473)         }
474)       if(max<sum) {
475)         max=sum;
476)       }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

478)     }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

481)     for (email in total) {
482)       balance[email]={
483)         'name': this.contributors[email].name,
484)         'total': total[email],
485)         'diff': total[email]-max,
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

488)     }
489)     return {
490)       'balance': balance,
491)       'sum': sum,
492)       'min': min,
493)       'max': max
494)     };
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

495)   }
496) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

497)   /*
498)    * Contructor
499)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

506)           this.contributors[email]=this.importContributor(data.contributors[email]);
507)         }
508)       }
509)       if (jQuery.type(data.deletedContributors) == 'object') {
510)         for (email in data.deletedContributors) {
511)           this.deletedContributors[email]=data.deletedContributors[email];
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

512)         }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

517)         }
518)       }
519)       if (jQuery.type(data.deletedContributions) == 'object') {
520)         for (uuid in data.deletedContributions) {
521)           this.deletedContributions[uuid]=data.deletedContributions[uuid];
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

522)         }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

523)       }
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

527)         }
528)       }
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

529)       if (jQuery.type(data.deletedCategories) == 'object') {
530)         for (uuid in data.deletedCategories) {
531)           this.deletedCategories[uuid]=data.deletedCategories[uuid];
532)         }
533)       }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

534)     }
535)     catch (e) {
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

537)       alert('Une erreur est survenue en chargeant le groupe '+this.name+' depuis le cache');
538)     }
539)   }
540) }
541) 
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

543)   this.name=name;
544)   this.email=email;
545)   this.export=function() {
546)     return {
Benjamin Renard Encode/Decode on import/exp...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

549)     };
550)   }
551) }
552) 
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

558)   this.export=function() {
559)     return {
560)       'name': encodeURIComponent(this.name),
561)       'color': this.color,
Benjamin Renard Replace categories modal by...

Benjamin Renard authored 10 years ago

562)       'lastChange': this.lastChange,
563)       'uuid': this.uuid
Benjamin Renard Fix category management

Benjamin Renard authored 10 years ago

564)     };
565)   }
566) }
567) 
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

569)   this.contributor=contributor;
570)   this.cost=cost;
571)   this.title=title;
Benjamin Renard Transform date of contribut...

Benjamin Renard authored 10 years ago

572)   if (jQuery.type(date)!='date') {
573)     date=moment(date).toDate();
574)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

579)   this.export=function() {
580)     return {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

588)     };
589)   }
590) 
591)   this.getTitle=function() {
592)     if (jQuery.type(this.title)=='string') {
593)       return this.title;
594)     }
595)     return '';
596)   }
597) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

598) 
599) function SyncServer() {
600)   this.url=false;
601)   this.email=false;
602)   this.password=false;
603)   this.logged=false;
604) 
605)   this.login=function(url,email,password,onsuccess,onerror) {
606)     this.url=url;
607)     this.email=email;
608)     this.password=password;
609) 
610)     try {
611)       jQuery.getJSON(
612)         this.url+'/login',
Benjamin Renard Add time in request to avoi...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

614)         function(data, textStatus) {
615)           console.log(data);
616)           if (textStatus=='success') {
Benjamin Renard Fixed login error display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

618)               console.log('Login success return');
619)               console.log(onsuccess);
620)               onsuccess(data);
621)               return true;
622)             }
623)           }
624)           onerror(data);
625)         }
626)       ).fail(onerror);
627)     }
628)     catch(e) {
629)       if(jQuery.type(onerror)=='function') {
630)         onerror();
631)       }
632)     }
633)   }
634) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

635)   this.subscribe=function(url,email,name,password,onsuccess,onerror) {
636)     this.url=url;
637)     this.email=email;
638)     this.name=name;
639)     this.password=password;
640) 
641)     try {
642)       jQuery.getJSON(
643)         this.url+'/subscribe',
Benjamin Renard Add time in request to avoi...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

645)         function(data, textStatus) {
646)           console.log(data);
647)           if (textStatus=='success') {
648)             if(jQuery.type(data.email) != 'undefined' && jQuery.type(data.name) != 'undefined') {
649)               onsuccess(data);
650)               return true;
651)             }
652)           }
653)           onerror(data);
654)           return false;
655)         }
656)       ).fail(onerror);
657)     }
658)     catch(e) {
659)       if(jQuery.type(onerror)=='function') {
660)         onerror();
661)       }
662)     }
663)   }
664) 
665) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

666)   this.sync=function(url,email,password,groups,onsuccess,onerror) {
667)     this.url=url;
668)     this.email=email;
669)     this.password=password;
670)     try {
Benjamin Renard Use POST instead of GET req...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

672)         this.url+'/sync',
673)         {
674)           'email':email,
675)           'password':password,
676)           'groups': JSON.stringify(groups)
677)         },
678)         function(data, textStatus) {
679)           console.log(data);
680)           if (textStatus=='success') {
681)             if(jQuery.type(data.groups)) {
682)               console.log('Sync success return');
683)               onsuccess(data);
684)               return true;
685)             }
686)           }
687)           onerror(data);
Benjamin Renard Use POST instead of GET req...

Benjamin Renard authored 10 years ago

688)         },
689)         'json'