From 704e32254264d445727a118d4616f2bf044ec982 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 12 Jan 2014 01:13:30 +0100 Subject: [PATCH] Add lastChange field in objects and their exports --- inc/myco_objects.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/inc/myco_objects.js b/inc/myco_objects.js index ef1c1d1..a8ee650 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -1,10 +1,13 @@ function GroupList() { + + lastChange=0; this.loadFromLocalStorage=function() { if (localStorage.groups!==undefined) { - var groups=JSON.parse(localStorage.groups); - for (el in groups) { - this[el]=new Group(el,groups[el]); + var data=JSON.parse(localStorage.groups); + this.lastChange=data.lastChange; + for (el in data.groups) { + this[el]=new Group(el,data.groups[el]); } } } @@ -20,7 +23,10 @@ function GroupList() { } this.save=function() { - localStorage.groups=JSON.stringify(this.export()); + localStorage.groups=JSON.stringify({ + 'lastChange': new Date().getTime(), + 'groups': this.export() + }); } this.each=function(fct) { @@ -174,7 +180,8 @@ function Group(name,data) { data.contributions[idx].cost, data.contributions[idx].title, data.contributions[idx].date, - idx + idx, + data.contributions[idx].lastChange )); } } @@ -198,18 +205,20 @@ function Contributor(name,email,id) { } } -function Contribution(contributor,cost,title,date,id) { +function Contribution(contributor,cost,title,date,id,lastChange) { this.contributor=contributor; this.cost=cost; this.title=title; this.date=date; this.id=id; + this.lastChange=lastChange || new Date().getTime(); this.export=function() { return { 'contributor': this.contributor.name, 'cost': this.cost, 'title': this.title, 'date': this.date, + 'lastChange': this.lastChange, }; }