Add lastChange field in objects and their exports
Benjamin Renard

Benjamin Renard commited on 2014-01-12 00:13:30
Showing 1 changed files, with 15 additions and 6 deletions.

... ...
@@ -1,10 +1,13 @@
1 1
 function GroupList() {
2 2
 
3
+  lastChange=0;
4
+  
3 5
   this.loadFromLocalStorage=function() {
4 6
     if (localStorage.groups!==undefined) {
5
-      var groups=JSON.parse(localStorage.groups);
6
-      for (el in groups) {
7
-        this[el]=new Group(el,groups[el]);
7
+      var data=JSON.parse(localStorage.groups);
8
+      this.lastChange=data.lastChange;
9
+      for (el in data.groups) {
10
+        this[el]=new Group(el,data.groups[el]);
8 11
       }
9 12
     }
10 13
   }
... ...
@@ -20,7 +23,10 @@ function GroupList() {
20 23
   }
21 24
 
22 25
   this.save=function() {
23
-    localStorage.groups=JSON.stringify(this.export());
26
+    localStorage.groups=JSON.stringify({
27
+      'lastChange': new Date().getTime(),
28
+      'groups': this.export()
29
+    });
24 30
   }
25 31
 
26 32
   this.each=function(fct) {
... ...
@@ -174,7 +180,8 @@ function Group(name,data) {
174 180
             data.contributions[idx].cost,
175 181
             data.contributions[idx].title,
176 182
             data.contributions[idx].date,
177
-            idx
183
+            idx,
184
+            data.contributions[idx].lastChange
178 185
           ));
179 186
         }
180 187
       }
... ...
@@ -198,18 +205,20 @@ function Contributor(name,email,id) {
198 205
   }
199 206
 }
200 207
 
201
-function Contribution(contributor,cost,title,date,id) {
208
+function Contribution(contributor,cost,title,date,id,lastChange) {
202 209
   this.contributor=contributor;
203 210
   this.cost=cost;
204 211
   this.title=title;
205 212
   this.date=date;
206 213
   this.id=id;
214
+  this.lastChange=lastChange || new Date().getTime();
207 215
   this.export=function() {
208 216
     return {
209 217
       'contributor': this.contributor.name,
210 218
       'cost': this.cost,
211 219
       'title': this.title,
212 220
       'date': this.date,
221
+      'lastChange': this.lastChange,
213 222
     };
214 223
   }
215 224
 
216 225