Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[unfold.git] / portal / static / js / myslice.js
1 /*
2  * MySlice Class
3  */
4
5 var myslice = {
6     pending: [],
7     
8     add: function(resource) {
9         if (!this.has(resource)) {
10                 this.pending.push(resource);
11                 this.save();
12         }
13     },
14     
15     del: function(resource) {
16         if (this.has(resource)) {
17                 this.pending.splice(index, 1);
18         }
19     },
20     
21     has: function(resource) {
22         index = jQuery.inArray( resource, this.pending );
23         if (index != -1) {
24                 return true;
25         }
26         return false;
27     },
28     
29     count: function() {
30         return this.pending.length;
31     },
32     
33     save: function() {
34         localStorage.setItem('pending', JSON.stringify(this.pending));
35     },
36     
37     load: function() {
38         this.pending = JSON.parse(localStorage.getItem('pending'));
39         if (!this.pending) {
40                 this.pending = [];
41         }
42     }
43     
44 };
45
46 $(document).ready(function() {
47         // Put the object into storage
48         //localStorage.setItem('testObject', JSON.stringify(testObject));
49
50         // Retrieve the object from storage
51         myslice.load();
52
53 });