e358209d678cd11c6b11a19abc025699a71310a7
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 Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

138)     }
139)     return {
Benjamin Renard Add uuid to group and refer...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

145)       'deletedContributions': this.deletedContributions,
146)       'categories': this.categories
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

147)     };
148)   }
149) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

150)   /*
151)    * Contributors
152)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

154)     this.deletedContributors[c.email]=c.export();
155)     time=new Date().getTime();
156)     this.deletedContributors[c.email].deletionTime=time;
157)     contributions=this.contributionsByContributorEmail(c.email);
158)     for (idx in contributions) {
159)       this.deleteContribution(contributions[idx].uuid,time);
160)     }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

185)   }
186) 
187)   this.contributorByName=function(name) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

190)     }
191)     return undefined;
192)   }
193) 
194)   this.contributorByEmail=function(email) {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

197)     }
198)     return undefined;
199)   }
200) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

203)   }
204) 
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

205)   this.replaceContributor=function(email,c) {
206)     delete this.contributors[email];
207)     this.contributors[c.email]=c;
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

208)   }
209) 
210)   /*
211)    * Contributions
212)    */
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

218)       }
219)     }
Benjamin Renard Sort contribution by date o...

Benjamin Renard authored 10 years ago

220)     ret.sort(function(a,b) {
221)       if (a.date==b.date) {
222)         return 0;
223)       }
224)       else if(a.date<b.date) {
225)         return -1;
226)       }
227)       else {
228)         return 1;
229)       }
230)     });
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

231)     return ret;
232)   }
233) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

234)   this.deletedContributionsByContributorEmail=function(email) {
235)     var ret=[];
236)     for (uuid in this.deletedContributions) {
237)       if (this.deletedContributions[uuid].contributor==email) {
238)         ret.push(new Contribution(
239)           this.contributorByEmail(email),
240)           this.deletedContributions[uuid].cost,
241)           decodeURIComponent(this.deletedContributions[uuid].title),
242)           this.deletedContributions[uuid].date,
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

243)           this.deletedContributions[uuid].categorie,
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

244)           uuid,
245)           this.deletedContributions[uuid].lastChange
246)         ));
247)       }
248)     }
249)     ret.sort(function(a,b) {
250)       if (a.lastChange==b.lastChange) {
251)         return 0;
252)       }
253)       else if(a.lastChange<b.lastChange) {
254)         return -1;
255)       }
256)       else {
257)         return 1;
258)       }
259)     });
260)     return ret;
261)   }
262) 
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

265)   }
266) 
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

267)   this.updateContribution=function(uuid,c) {
268)     c.uuid=uuid;
269)     this.contributions[uuid]=c;
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

270)   }
271) 
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

274)     this.deletedContributions[uuid]=this.contributions[uuid].export();
275)     delete this.contributions[uuid];
276)   }
277) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

278)   this.restoreContribution=function(uuid) {
279)     this.deletedContributions[uuid].lastChange=new Date().getTime();
280)     this.contributions[uuid]=this.importContribution(this.deletedContributions[uuid]);
281)     delete this.deletedContributions[uuid];
282)   }
283) 
Benjamin Renard Manage group contributors t...

Benjamin Renard authored 10 years ago

284)   this.importContributor=function(data) {
285)     return new Contributor(
286)       decodeURIComponent(data.name),
287)       data.email
288)     );
289)   }
290) 
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

291)   this.importContribution=function(data) {
292)     return new Contribution(
293)       this.contributorByEmail(data.contributor),
294)       data.cost,
295)       decodeURIComponent(data.title),
296)       data.date,
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

297)       data.categorie,
Benjamin Renard Add possibility to view trash

Benjamin Renard authored 10 years ago

298)       data.uuid,
299)       data.lastChange
300)     );
301)   }
Benjamin Renard Use UUID as Contribution id...

Benjamin Renard authored 10 years ago

302) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

303)   /*
304)    * Balance
305)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

307)     total={}
308)     min=-1;
309)     max=0;
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

315)       }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

316)       if (min==-1 || min>sum) {
317)           min=sum;
318)         }
319)       if(max<sum) {
320)         max=sum;
321)       }
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

323)     }
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

326)     for (email in total) {
327)       balance[email]={
328)         'name': this.contributors[email].name,
329)         'total': total[email],
330)         'diff': total[email]-max,
Benjamin Renard Improve balance display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

333)     }
334)     return {
335)       'balance': balance,
336)       'sum': sum,
337)       'min': min,
338)       'max': max
339)     };
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

340)   }
341) 
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

342)   /*
343)    * Categories
344)    */
345)   this.getCategories=function() {
346)     return this.categories;
347)   }
348) 
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

349)   /*
350)    * Contructor
351)    */
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

358)           this.contributors[email]=this.importContributor(data.contributors[email]);
359)         }
360)       }
361)       if (jQuery.type(data.deletedContributors) == 'object') {
362)         for (email in data.deletedContributors) {
363)           this.deletedContributors[email]=data.deletedContributors[email];
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

364)         }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

369)         }
370)       }
371)       if (jQuery.type(data.deletedContributions) == 'object') {
372)         for (uuid in data.deletedContributions) {
373)           this.deletedContributions[uuid]=data.deletedContributions[uuid];
Benjamin Renard Clean code

Benjamin Renard authored 10 years ago

374)         }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

375)       }
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

376)       if (jQuery.type(data.categories) == 'object') {
377)         for (cid in data.categories) {
378)           if (jQuery.type(data.categories[cid]['color'])!='string') {
379)             data.categories[cid]['color']='#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
380)           }
381)           this.categories[cid]=data.categories[cid];
382)         }
383)       }
384)       else {
385) 		categories= {
386)           'Alimentation': '#1f83db',
387)           'Restaurant': '#f07305',
388)           'Loisir': '#d413ce',
389)           'Transport': '#13d413',
390)           'Vacances': '#e9fa00',
391)           'Maison': '#e9fa00',
392)           'Rembourssement': '#8a8b8c',
393)           'Cadeau': '#a700fa'
394)         };
395)         for (c in categories) {
396) 		  this.categories[generate_uuid()]={
397) 	        'name': c,
398) 	        'color': categories[c]
399) 		  };	
400) 	    }
401)       }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

402)     }
403)     catch (e) {
404)       alert('Une erreur est survenue en chargeant le groupe '+this.name+' depuis le cache');
405)     }
406)   }
407) }
408) 
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

410)   this.name=name;
411)   this.email=email;
412)   this.export=function() {
413)     return {
Benjamin Renard Encode/Decode on import/exp...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

416)     };
417)   }
418) }
419) 
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

421)   this.contributor=contributor;
422)   this.cost=cost;
423)   this.title=title;
Benjamin Renard Transform date of contribut...

Benjamin Renard authored 10 years ago

424)   if (jQuery.type(date)!='date') {
425)     date=moment(date).toDate();
426)   }
Benjamin Renard Initial commit

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

428)   this.uuid=uuid || generate_uuid();
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

429)   this.categorie=cat;
Benjamin Renard Add lastChange field in obj...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

431)   this.export=function() {
432)     return {
Benjamin Renard Manage contributor by their...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

437)       'date': this.date.getTime(),
Benjamin Renard Add Categories management

Benjamin Renard authored 10 years ago

438)       'categorie': this.categorie,
Benjamin Renard Add lastChange field in obj...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

440)     };
441)   }
442) 
443)   this.getTitle=function() {
444)     if (jQuery.type(this.title)=='string') {
445)       return this.title;
446)     }
447)     return '';
448)   }
449) }
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

450) 
451) function SyncServer() {
452)   this.url=false;
453)   this.email=false;
454)   this.password=false;
455)   this.logged=false;
456) 
457)   this.login=function(url,email,password,onsuccess,onerror) {
458)     this.url=url;
459)     this.email=email;
460)     this.password=password;
461) 
462)     try {
463)       jQuery.getJSON(
464)         this.url+'/login',
Benjamin Renard Add time in request to avoi...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

466)         function(data, textStatus) {
467)           console.log(data);
468)           if (textStatus=='success') {
Benjamin Renard Fixed login error display

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

470)               console.log('Login success return');
471)               console.log(onsuccess);
472)               onsuccess(data);
473)               return true;
474)             }
475)           }
476)           onerror(data);
477)         }
478)       ).fail(onerror);
479)     }
480)     catch(e) {
481)       if(jQuery.type(onerror)=='function') {
482)         onerror();
483)       }
484)     }
485)   }
486) 
Benjamin Renard Add subscribe feature

Benjamin Renard authored 10 years ago

487)   this.subscribe=function(url,email,name,password,onsuccess,onerror) {
488)     this.url=url;
489)     this.email=email;
490)     this.name=name;
491)     this.password=password;
492) 
493)     try {
494)       jQuery.getJSON(
495)         this.url+'/subscribe',
Benjamin Renard Add time in request to avoi...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

497)         function(data, textStatus) {
498)           console.log(data);
499)           if (textStatus=='success') {
500)             if(jQuery.type(data.email) != 'undefined' && jQuery.type(data.name) != 'undefined') {
501)               onsuccess(data);
502)               return true;
503)             }
504)           }
505)           onerror(data);
506)           return false;
507)         }
508)       ).fail(onerror);
509)     }
510)     catch(e) {
511)       if(jQuery.type(onerror)=='function') {
512)         onerror();
513)       }
514)     }
515)   }
516) 
517) 
Benjamin Renard Add login and sync support

Benjamin Renard authored 10 years ago

518)   this.sync=function(url,email,password,groups,onsuccess,onerror) {
519)     this.url=url;
520)     this.email=email;
521)     this.password=password;
522)     try {
Benjamin Renard Use POST instead of GET req...

Benjamin Renard authored 10 years ago

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

Benjamin Renard authored 10 years ago

524)         this.url+'/sync',
525)         {
526)           'email':email,
527)           'password':password,
528)           'groups': JSON.stringify(groups)
529)         },
530)         function(data, textStatus) {
531)           console.log(data);
532)           if (textStatus=='success') {
533)             if(jQuery.type(data.groups)) {
534)               console.log('Sync success return');
535)               onsuccess(data);
536)               return true;
537)             }
538)           }
539)           onerror(data);
Benjamin Renard Use POST instead of GET req...

Benjamin Renard authored 10 years ago

540)         },
541)         'json'