X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fstatic%2Fjs%2Fmyslice.js;h=34a351664369c9e40575fcfdcf0623a766ad6914;hb=d4eb40d1225e2da8306a4ccf111b6140264ca082;hp=7038e53edc6a4cdedf8c4a13baf4daf39b7cb133;hpb=7ae0c099d60e417a77fd8f5fcb8278f087a14d84;p=unfold.git diff --git a/portal/static/js/myslice.js b/portal/static/js/myslice.js index 7038e53e..34a35166 100644 --- a/portal/static/js/myslice.js +++ b/portal/static/js/myslice.js @@ -6,24 +6,6 @@ function list() { this.elements = []; } -list.prototype.save = function() { - for (var prop in this) { - if (typeof this[prop] != 'function') { - console.log("prop: " + prop); - } else { - console.log("func: " + prop); - } - } - //localStorage.setItem(name, JSON.stringify(value)); -}; - -list.prototype.load = function(name) { - this.pending = JSON.parse(localStorage.getItem(name)); - if (!this.pending) { - this.pending = []; - } -}; - list.prototype.add = function(element) { if (!this.has(element)) { this.elements.push(element); @@ -60,14 +42,14 @@ function resources() { }; }; -function users() { +function leases() { this.pending = { toremove: new list(), toadd: new list(), }; }; -function leases() { +function users() { this.pending = { toremove: new list(), toadd: new list(), @@ -83,27 +65,19 @@ function slice(name) { this.users = new users(); this.leases = new leases(); -}; -slice.prototype.pending = function() { - -}; -slice.prototype.reserve = function() { - -}; -slice.prototype.unreserve = function() { - }; + /* * User */ -function user(u) { - this.u = u; - this.testbeds = {}; - this.slices = {}; +function user(user) { + this.user = user; + this.testbeds = new list(); + this.slices = new list(); - for (i = 0; i < this.u.slices.length; i++) { - this.slices[this.u.slices[i]] = new slice(this.u.slices[i]); + for (i = 0; i < this.user.slices.length; i++) { + this.slices[this.user.slices[i]] = new slice(this.user.slices[i]); } }; @@ -113,7 +87,7 @@ user.prototype.slice = function(name) { user.prototype.list = function() { for (s in this.slices) { - for (o in s) { + for (o in s) { if (typeof o != 'function') { console.log(o); } else { @@ -128,7 +102,56 @@ user.prototype.list = function() { */ var myslice = { user: {}, - + + user: function() { + if ($.isEmptyObject(this.user)) { + //this.login(function() { return this.user; }); + if(localStorage.getItem('user')!='undefined'){ + this.user = JSON.parse(localStorage.getItem('user')); + }else{ + return false; + } + } + return this.user; + }, + loadSlices: function(slices) { + if (typeof(slices) == "undefined"){ + + if(myslice.user != null && typeof(myslice.user.slices) != "undefined" && myslice.user.slices.length>0){ + slices = myslice.user.slices + } + } + // myslice.user is in LocalStorage + if(typeof(slices) != "undefined"){ + /* + Launch queries to get the resources and leases in Manifold Cache + */ + $.post("/rest/resource/", function( data ) { + }); + $.post("/rest/lease/", function( data ) { + }); + + $.each( slices, function(i, val) { + /* + Launch a Query for each slice to get resources and leases in Manifold Cache + */ + $.post("/rest/slice/", { 'filters': { 'slice_hrn' : val } }, function(data) { + }); + }); + } + + }, + login: function(fn) { + user = localStorage.getItem('user'); + if($.isEmptyObject(user)){ + // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2 + $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) { + //myslice.user = new user(data[0]); + localStorage.setItem('user', JSON.stringify(data[0])); + myslice.loadSlices(data[0].slices); + }); + } + }, getSlices: function(name) { }, @@ -197,6 +220,8 @@ var myslice = { $(document).ready(function() { + //console.log(myslice.user().slices); + // $.post("/rest/user/",{'filters':{'user_hrn':'$user_hrn'}}, function(data) { // myslice.user = new user(data[0]); // console.log(myslice.user.slices);