request.session.user.pi to know if the user is_pi not to Query everytime
[myslice.git] / portal / templates / base.html
index 82fa444..4b5999e 100644 (file)
@@ -1,6 +1,7 @@
 {% load portal_filters %}
 {# This is required by insert_above #}{% insert_handler %}<!DOCTYPE html>
-<html lang="en"><head>
+<html lang="en">
+<head>
 <title>{{theme}} portal - {{ section }}</title>
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
@@ -20,7 +21,7 @@
 <script src="{{ STATIC_URL }}js/jquery.dataTables.min.js"></script>
 <script src="{{ STATIC_URL }}js/jquery.qtip.min.js"></script>
 <script src="{{ STATIC_URL }}js/bootstrap.datatables.js"></script>
-<!-- <script src="{{ STATIC_URL }}js/stash.min.js"></script> -->
+<script src="{{ STATIC_URL }}js/common.functions.js"></script>
 <script src="{{ STATIC_URL }}js/myslice.js"></script>
 <script src="{{ STATIC_URL }}js/myslice-ui.js"></script>
 
@@ -65,7 +66,7 @@ This list of slices should go into SESSION !
 $(document).ready(function() {
 {% if username %}
     myslice.login(function(){
-        user = myslice.user();
+        user = myslice.get_user();
 
         var slices = [];
         if($.isEmptyObject(user)){
@@ -75,12 +76,15 @@ $(document).ready(function() {
             slices.push("no slice");
         }else{
             slices = user.slices;
+            {% if theme != "fed4fire" %}
             drawSlices(slices);
+            {% endif %}
         }
         {% if theme == "fed4fire" %}
-        p = myslice.projects();
+        p = myslice.get_projects();
         if(p != null){
-            drawProjects(p);
+            //drawProjects(p);
+            drawProjectsTree(p,slices);
         }
         {% endif %}
     });
@@ -105,6 +109,33 @@ $(document).ready(function() {
         $("div#home-project-list").html($( "<ul/>", { html: items.join( "" ) }));
         $("ul#dropdown-project-list").append(items.join( "" ));
     }
+    function drawProjectsTree(projects,slices) {
+        var items = [];
+        var items_sl = [];
+        $.each( projects, function(i, p) {
+            $.each( slices, function(y, s) {
+                console.log(escapeRegExp(p));
+                if (s.match('^' + escapeRegExp(p))) {
+                     items_sl.push( "<li><a href=\"/resources/" + s + "\">" + s.replace(p + '.','') + "</a></li>" );
+                }
+            });
+            el = "<li><a href=\"/portal/project/" + p + "\">" + p + "</a>";
+            if (items_sl.length > 0) {
+                el += "<ul>" + items_sl.join( "" ) + "</ul>";
+            }
+            el += "</li>";
+            items.push(el);
+            items_sl = [];
+        });
+        $("div#home-project-tree").html($( "<ul/>", { html: items.join( "" ) }));
+        if (projects.length > 0) {
+            $('.dashboard-create-slice').show();
+        }
+    }
+    
+    window.setTimeout(function() {
+        $('.projects-loading').hide();
+    },10000);
     {% endif %}
 {% endif %}
        jQuery('[title!=""]').qtip();