X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fstatic%2Fjs%2Fmyslice.js;h=d97d6b08ebc39b2f6a51b1a34bf28ff11742a9ee;hb=9923754657b1e28fab15ac658f500f4c6b90b751;hp=aa5df439545787c31a45f52358af70c0da59cb11;hpb=7c013fef45846d3174409ddf03679196885dc4f9;p=myslice.git diff --git a/portal/static/js/myslice.js b/portal/static/js/myslice.js index aa5df439..d97d6b08 100644 --- a/portal/static/js/myslice.js +++ b/portal/static/js/myslice.js @@ -107,7 +107,7 @@ user.prototype.list = function() { var myslice = { user: {}, - user: function() { + get_user: function() { if ($.isEmptyObject(this.user)) { //this.login(function() { return this.user; }); if(localStorage.getItem('user')!='undefined'){ @@ -120,7 +120,7 @@ var myslice = { }, projects: {}, - projects: function() { + get_projects: function() { if ($.isEmptyObject(this.projects)) { //this.login(function() { return this.user; }); if(localStorage.getItem('projects')!='undefined'){ @@ -172,42 +172,46 @@ var myslice = { if($.isEmptyObject(user)){ // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2 $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) { - localStorage.setItem('user', JSON.stringify(data[0])); - myslice.loadSlices(data[0].slices); - if(isFunction(fn)){ - fn(); + if (data.length > 0) { + localStorage.setItem('user', JSON.stringify(data[0])); + projects = []; + $.each(data[0].pi_authorities, function(idx, auth) { + // PI on projects + if(auth.split('.').length>2){ + if($.inArray(auth,projects) == -1){ + projects.push(auth); + } + }else if (auth.split('.').length>1){ + // PI on authorities + // What are the projects under this authority? + $.post("/rest/myslice:authority/",{'fields':['authority_hrn'],'filters':{'authority_hrn':'CONTAINS'+auth}}, function( data ) { + $.each(data, function(idx, project) { + if($.inArray(project.authority_hrn,projects) == -1){ + projects.push(project.authority_hrn); + } + }); + }); + }else{ + console.log("admin account - we don't list all from root"); + } + }); + localStorage.setItem('projects', JSON.stringify(projects)); + myslice.loadSlices(data[0].slices); + if(isFunction(fn)){ + fn(); + } + }else{ + $('#credentials_msg').css('display','block'); } }); }else{ + $('#credentials_msg').css('display','block'); if(isFunction(fn)){ fn(); } } - }, - loadProjects: function(fn) { - user = JSON.parse(localStorage.getItem('user')); - projects = localStorage.getItem('projects'); - if($.isEmptyObject(projects)){ - if($.isEmptyObject(user) || $.isEmptyObject(user.parent_authority)){ - $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'},'fields':['parent_authority']}, function( data ) { - parent_authority = data[0].parent_authority; - - }); - }else{ - parent_authority = user.parent_authority; - } - // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2 - $.post("/rest/myslice:authority/",{'fields':['authority_hrn'],'filters':{'authority_hrn':'CONTAINS'+parent_authority}}, function( data ) { - localStorage.setItem('projects', JSON.stringify(data)); - }); - }else{ - if(isFunction(fn)){ - fn(); - } - } - }, getSlices: function(name) {