From: Loic Baron Date: Tue, 20 Jan 2015 16:04:27 +0000 (+0100) Subject: Projects on the Dashboard for Fed4Fire X-Git-Tag: myslice-1.3~113^2~7 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3669e3329a72f94940f4bbf6aa94781d973332d9;p=myslice.git Projects on the Dashboard for Fed4Fire --- diff --git a/portal/static/js/myslice.js b/portal/static/js/myslice.js index 1ccc1c1a..4b8fc83b 100644 --- a/portal/static/js/myslice.js +++ b/portal/static/js/myslice.js @@ -1,6 +1,10 @@ /* * MySlice Class */ +function isFunction(functionToCheck) { + var getType = {}; + return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; +} function list() { this.elements = []; @@ -114,6 +118,20 @@ var myslice = { } return this.user; }, + projects: {}, + + projects: function() { + if ($.isEmptyObject(this.projects)) { + //this.login(function() { return this.user; }); + if(localStorage.getItem('projects')!='undefined'){ + this.projects = JSON.parse(localStorage.getItem('projects')); + }else{ + return false; + } + } + return this.projects; + }, + loadSlices: function(slices) { if (typeof(slices) == "undefined"){ @@ -154,12 +172,43 @@ var myslice = { 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); + if(isFunction(fn)){ + fn(); + } }); + }else{ + 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/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) { }, diff --git a/portal/templates/base.html b/portal/templates/base.html index 0bf9ab4e..a4f146cc 100644 --- a/portal/templates/base.html +++ b/portal/templates/base.html @@ -48,48 +48,50 @@ XXX TODO: session This list of slices should go into SESSION ! */ $(document).ready(function() { - {% if username %} - myslice.login(); +{% if username %} + myslice.login(function(){ + user = myslice.user(); - user = myslice.user(); + var slices = []; + if($.isEmptyObject(user)){ + $("div#home-slice-list").html( + "
You do not yet have a slice
"); + $("ul#dropdown-slice-list").append("
  • no slice
  • "); + slices.push("no slice"); + }else{ + slices = user.slices; + drawSlices(slices); + } + {% if theme == "fed4fire" %} + myslice.loadProjects(function(){ + p = myslice.projects(); + drawProjects(p); + }); + {% endif %} + }); - var slices = []; - if($.isEmptyObject(user)){ - $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) { - if(data.length > 0){ - drawSlices(data[0].slices); - }else{ - $("div#home-slice-list").html( - "
    You do not yet have a slice
    "); - $("ul#dropdown-slice-list").append("
  • no slice
  • "); - slices.push("no slice"); - } - }); - }else{ - slices = user.slices; - drawSlices(slices); - } - - /* - Launch queries to get the resources and leases in Manifold Cache - */ - function drawSlices(slices){ var items = []; $.each( slices, function(i, val) { items.push( "
  • " + val + "
  • " ); - /* - // Launch a Query for each slice to get resources and leases in Manifold Cache - // Now only done in Homeview to speed up the other pages - $.post("/rest/slice/", { 'filters': { 'slice_hrn' : val } }, function(data) { - }); - */ }); $("div#home-slice-list").html($( "