Institution: generic template
authorLoic Baron <loic.baron@lip6.fr>
Mon, 11 May 2015 09:05:05 +0000 (11:05 +0200)
committerLoic Baron <loic.baron@lip6.fr>
Mon, 11 May 2015 09:05:05 +0000 (11:05 +0200)
portal/templates/fed4fire/fed4fire_institution.html [deleted file]
portal/templates/institution.html

diff --git a/portal/templates/fed4fire/fed4fire_institution.html b/portal/templates/fed4fire/fed4fire_institution.html
deleted file mode 100644 (file)
index facc118..0000000
+++ /dev/null
@@ -1,360 +0,0 @@
-{% extends "layout_wide.html" %}
-
-{% block head %} 
-<script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script>
-<script type="text/javascript" src="{{STATIC_URL}}js/requests.js"></script>
-{% endblock head %}
-
-{% block content %}
-<div class="container">
-       <div class="row">
-               <div class="col-md-12">
-                        <div class="breadcrumbs">
-                {% if project %}
-                               Management &nbsp;>&nbsp; Project: <span id="authority_name">{{user_details.parent_authority}}</span>
-                {% else %}
-                               Management &nbsp;>&nbsp; Institution: <span id="authority_name">{{user_details.parent_authority}}</span>
-                {% endif %}
-                        </div>
-               </div>
-       </div>
-</div>
-<div class="container">
-       <div class="row">
-               <div class="col-md-12">
-                       <ul class="nav nav-tabs nav-section">
-                               <li class="active"><a href="#about">About</a></li>
-                               <li><a href="#users">Users</a></li>
-                {% if not project %}
-                               <li><a href="#projects">Projects</a></li>
-                {% else %}
-                               <li><a href="#slices">Slices</a></li>
-                {% endif %}
-                               <li><a href="#requests">Requests</a></li>
-                       </ul>
-           </div>
-       </div>
-</div>
-<div class="container tab-content">
-       <div class="tab-pane active row" id="about">
-        <div class="col-md-12 el">
-        <h2>{{user_details.parent_authority}}</h2>
-        </div>
-       </div>
-       
-       <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
-               <div class="col-md-12 el">
-                       <div id="user-tab-loading" style="padding-bottom:10px;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
-                               <div id="user-tab-loaded" style="display:none;">
-                               <table id="user-tab" class="table">
-                                       <tr>
-                                       <th>+/-</th>
-                            {% if not project %}
-                                       <th>Email</th>
-                            {% endif %}
-                                       <th>User hrn</th>
-                            <!--
-                                       <th>First name</th>
-                                       <th>Last name</th>
-                                       <th>Enabled</th>
-                            -->
-                                       </tr>
-                               </table>
-                               
-                       </div>
-                       {%if  pi %}     
-                       <div>
-                {% if project %}
-                               <button id="removepi" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove from project</button>
-                {% else %}
-                               <button id="makepi" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-up"></span> Upgrade to PI</button>
-                               <button id="removepi" type="button" class="btn"><span class="glyphicon glyphicon-arrow-down"></span> Downgrade to  user</button>
-                               <button id="deleteusers" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected users</button>
-                {% endif %}
-                       </div>
-                       {% endif %}
-               </div>
-       </div>
-
-    {% if not project %}
-       <div class="tab-pane row" id="projects" data-authority="{{user_details.parent_authority}}">
-               <div class="col-md-12 el">
-                       <div id="project-tab-loading" style="padding-bottom:10px;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Projects" /></div>
-                               <div id="project-tab-loaded" style="display:none;">
-                               <table id="project-tab" class="table">
-                                       <tr>
-                                       <th>+/-</th>
-                                       <th>Project hrn</th>
-                                       </tr>
-                               </table>
-                               
-                       </div>
-                       <div>
-               {% if  pi %}
-                       <button id="createproject" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create project</button>
-                       <button id="deleteprojects" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected projects</button>
-                       {% else %}
-                       <button id="createproject" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request project</button>
-                       {% endif %}
-                       </div>
-               </div>
-       </div>
-   {% endif %}
-       <div class="tab-pane row" id="slices">
-               <div class="col-md-12 el">
-           <div id="slice-tab-loading" style="padding-bottom:10px;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
-           <div id="slice-tab-loaded" style="display:none;">
-               <table id="slice-tab" class="table">
-                   <tr>
-                       <th>+/-</th>
-                       <th>Slice hrn</th>
-                       <th>Users</th>
-                       <th>Url</th>
-                       <!-- <th>nodes</th> -->
-                       <th>Creation</th>
-                   </tr>
-               </table>                        
-           </div>
-        <div>
-               {% if pi %}
-                       <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
-            <button id="renewslices" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
-            <button id="deleteslices" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
-                       {% else %}
-                       <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
-                       {% endif %}
-        </div>
-          </div>
-       </div>
-       <div class="tab-pane row" id="requests">
-        <div id="spinner" style="padding-top:40px; padding-left:40px;"></div>
-       </div>
-</div>
-<script>
-$(document).ready(function() {
-    {% if person %}
-    {% if user_details.parent_authority %}
-        $('#spinner').spin();
-        
-        $.post("/rest/myslice:slice/",{'fields':['slice_hrn','users','url','slice_date_created'],'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
-            var list_slices = [];
-            var table_slices = [];
-            /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
-            $.each( data, function( key, val ) {
-                list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
-                if(val.nodes=="undefined" || val.nodes==null){
-                    nodes_length=0;
-                }else{
-                    nodes_length=val.nodes.length;
-                }
-                if(val.users=="undefined" || val.users==null){
-                    users_length=0;
-                }else{
-                    users_length=val.users.length;
-                }
-
-                if(val.url=="undefined" || val.url==null){
-                    slice_url="";
-                }else{
-                    slice_url="<a href='"+val.url+"' target='_blank'>"+val.url+"</a>";
-                }
-                
-                slice_row = "<tr id='"+val.slice_hrn+"'>";
-                slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'><div id='"+val.slice_hrn+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
-
-                // filter links to slices, only those that the user has credentials for
-                s = myslice.user.slices;
-                if(s.length > 0 && $.inArray(val.slice_hrn, myslice.user.slices)!=-1){
-                    slice_row += "<td><a href='/slice/"+val.slice_hrn+"'>" + val.slice_hrn + "</a></td>";
-                }else{
-                    slice_row += "<td>" + val.slice_hrn + "</td>";
-                }
-                slice_row += "<td>"+users_length+"</td>";
-                slice_row += "<td>"+slice_url+"</td>";
-                //slice_row += "<td>"+nodes_length+"</td>";
-                slice_row += "<td>"+val.slice_date_created+"</td>";
-                slice_row += "</tr>";
-                table_slices.push(slice_row);
-                
-            });
-           
-            /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
-            $("table#slice-tab tr:last").after(table_slices.join( "" ));
-            $("div#slice-tab-loaded").css("display","block");
-            $("div#slice-tab-loading").css("display","none");
-        });
-               
-        {% if project %}
-               $.post("/rest/myslice:authority/",{'fields':['pi_users'],'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
-           
-            var table_users = [];
-            $.each( data[0].pi_users, function( key, val ) {
-                user_row = "<tr id='"+val+"'>";
-                user_row += "<td><input type='checkbox' class='user' id='"+val+"'><div id='"+val+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
-                user_row += "<td>"+val+"</td>";
-                user_row += "</tr>";
-                table_users.push(user_row);
-            });
-            $("table#user-tab tr:last").after(table_users.join( "" ));
-            $("div#user-tab-loaded").css("display","block");
-            $("div#user-tab-loading").css("display","none");
-
-        });
-        {% else %}
-        $.post("/rest/myslice:user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
-            var list_users = [];
-            var table_users = [];
-                   /* Available fields
-                   user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
-                   user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
-                   */
-            $.each( data, function( key, val ) {
-                list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
-                user_row = "<tr id='"+val.user_hrn+"'>";
-                user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"' data-email='"+val.user_email+"'><div id='"+val.user_hrn+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
-                user_row += "<td>"+val.user_email+"</td>";
-                user_row += "<td>"+val.user_hrn+"</td>";
-                /*
-                user_row += "<td>"+val.user_first_name+"</td>";
-                user_row += "<td>"+val.user_last_name+"</td>";
-                           user_row += "<td>"+val.user_enabled+"</td>";
-                */
-                user_row += "</tr>";
-                table_users.push(user_row);
-            });
-            $("table#user-tab tr:last").after(table_users.join( "" ));
-            $("div#user-tab-loaded").css("display","block");
-            $("div#user-tab-loading").css("display","none");
-        });
-               $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS{{user_details.parent_authority}}'}}, function( data ) {
-           
-            var table_projects = [];
-            $.each( data, function( key, val ) {
-                project_row = "<tr id='"+val.authority_hrn+"'>";
-                project_row += "<td><input type='checkbox' class='project' id='"+val.authority_hrn+"'><div id='"+val.authority_hrn+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
-
-                // filter links to projects, only those that the user has credentials for
-                p = myslice.projects;
-                if(p.length > 0 && $.inArray(val.authority_hrn, p)!=-1){
-                    project_row += "<td><a href='/portal/project/"+val.authority_hrn+"'>"+val.authority_hrn+"</a></td>";
-                }else{
-                    project_row += "<td>"+val.authority_hrn+"</td>";
-                }
-                project_row += "</tr>";
-                table_projects.push(project_row);
-            });
-            $("table#project-tab tr:last").after(table_projects.join( "" ));
-            $("div#project-tab-loaded").css("display","block");
-            $("div#project-tab-loading").css("display","none");
-
-        });
-
-        {% endif %}
-    {% endif %}
-    {% endif %}
-
-}); // End document.ready
-
-$(document).ready(function() {
-       $('.nav-tabs a').click(function (e) {
-               e.preventDefault();
-               $(this).tab('show');
-       var id = $(this).attr('href').substr(1);
-       if ((id == 'requests')){
-               $("#" + id).load('/management/' + id);
-        }
-        /*
-       if ((id == 'requests') || (id == 'about'))
-               $("#" + id).load('/management/' + id);
-        */
-       });
-       var hash = window.location.hash;
-       if (hash) {
-               $('.nav-tabs a[href='+hash+']').click();
-       } else {
-               $('.nav-tabs a[href=#about]').click();
-       }
-
-    //upgrade users to PI
-    $('button#makepi').click(function() {
-        spin_all();
-        var flag = false;
-        var pi_users = [];
-        $.post("/rest/myslice:authority/",{'filters':{'authority_hrn': '{{user_details.parent_authority}}'}}, function( data ) {
-            pi_users = data[0]["pi_users"];
-            $('input:checkbox.user').each(function (index) {
-                if(this.checked){
-                    var record_id = this.id;
-                    pi_users.push(record_id)
-                    $.post("/credentials/clear/",{'emails':[this.dataset['email']]}, function(data) {
-                    }); // post credentials clear
-                    flag = true;                
-                }
-            });
-            if(flag == true){
-                $.post("/update/myslice:authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'},'params':{'pi_users':pi_users}}, function(data) {
-                    if(data.success){
-                        mysliceAlert('Success: User rights added to: {{user_details.parent_authority}}','success', true);
-                    }else{
-                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
-                        //alert("Rest Error for "+record_id+": "+data.error);
-                    }
-                    unspin_all();
-                });
-            }
-        });
-    });
-//downgrade to user [in projects:remove from project]
-    $('button#removepi').click(function() {
-        spin_all();
-        var flag = false;
-        var pi_users = [];
-        $.post("/rest/myslice:authority/",{'filters':{'authority_hrn': '{{user_details.parent_authority}}'}}, function( data ) {
-            pi_users = data[0]["pi_users"];
-                       // http://stackoverflow.com/questions/9792927/javascript-array-search-and-remove-string
-            $('input:checkbox.user').each(function (index) {
-                if(this.checked){
-                    var record_id = this.id;
-                                       for (var i=pi_users.length-1; i>=0; i--) {
-                                       if (pi_users[i] === record_id) {
-                                               pi_users.splice(i, 1);
-                            $.post("/credentials/clear/",{'emails':[this.dataset['email']]}, function(data) {
-                            }); // post credentials clear
-                            flag = true;                
-                                       }
-                                       }
-                }
-            });
-            if(flag == true){
-                $.post("/update/myslice:authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'},'params':{'pi_users':pi_users}}, function(data) {
-                    if(data.success){
-                        mysliceAlert('Success: User rights removed from: {{user_details.parent_authority}}','success', true);
-                        {% if project %}
-                        // remove the user from the list of pis of the project displayed
-                        $('input:checkbox.user').each(function (index) {
-                           if(this.checked){
-                               var record_id = this.id;
-                               $('tr[id="'+record_id+'"]').fadeOut("slow");
-                               $('tr[id="'+record_id+'"]').remove();
-                            }
-
-                        });
-                        {% endif %}
-                    }else{
-                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
-                        //alert("Rest Error for "+record_id+": "+data.error);
-                    }
-                    unspin_all();
-                });
-            }else{
-                mysliceAlert('No action: User had no rights on: {{user_details.parent_authority}}','success', true);
-                unspin_all();
-            }
-        });
-    });
-});
-
-
-
-</script>
-{% endblock %}
index 1675654..facc118 100644 (file)
@@ -2,6 +2,7 @@
 
 {% block head %} 
 <script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script>
+<script type="text/javascript" src="{{STATIC_URL}}js/requests.js"></script>
 {% endblock head %}
 
 {% block content %}
@@ -9,7 +10,11 @@
        <div class="row">
                <div class="col-md-12">
                         <div class="breadcrumbs">
-                                Management &nbsp;>&nbsp; Institution: <span id="authority_name">{{user_details.parent_authority}}</span>
+                {% if project %}
+                               Management &nbsp;>&nbsp; Project: <span id="authority_name">{{user_details.parent_authority}}</span>
+                {% else %}
+                               Management &nbsp;>&nbsp; Institution: <span id="authority_name">{{user_details.parent_authority}}</span>
+                {% endif %}
                         </div>
                </div>
        </div>
                        <ul class="nav nav-tabs nav-section">
                                <li class="active"><a href="#about">About</a></li>
                                <li><a href="#users">Users</a></li>
+                {% if not project %}
+                               <li><a href="#projects">Projects</a></li>
+                {% else %}
                                <li><a href="#slices">Slices</a></li>
+                {% endif %}
                                <li><a href="#requests">Requests</a></li>
                        </ul>
            </div>
        
        <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
                <div class="col-md-12 el">
-                       <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
+                       <div id="user-tab-loading" style="padding-bottom:10px;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
                                <div id="user-tab-loaded" style="display:none;">
                                <table id="user-tab" class="table">
                                        <tr>
                                        <th>+/-</th>
+                            {% if not project %}
                                        <th>Email</th>
+                            {% endif %}
                                        <th>User hrn</th>
                             <!--
                                        <th>First name</th>
                        </div>
                        {%if  pi %}     
                        <div>
+                {% if project %}
+                               <button id="removepi" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Remove from project</button>
+                {% else %}
                                <button id="makepi" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-up"></span> Upgrade to PI</button>
                                <button id="removepi" type="button" class="btn"><span class="glyphicon glyphicon-arrow-down"></span> Downgrade to  user</button>
                                <button id="deleteusers" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected users</button>
+                {% endif %}
                        </div>
                        {% endif %}
                </div>
        </div>
 
+    {% if not project %}
+       <div class="tab-pane row" id="projects" data-authority="{{user_details.parent_authority}}">
+               <div class="col-md-12 el">
+                       <div id="project-tab-loading" style="padding-bottom:10px;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Projects" /></div>
+                               <div id="project-tab-loaded" style="display:none;">
+                               <table id="project-tab" class="table">
+                                       <tr>
+                                       <th>+/-</th>
+                                       <th>Project hrn</th>
+                                       </tr>
+                               </table>
+                               
+                       </div>
+                       <div>
+               {% if  pi %}
+                       <button id="createproject" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create project</button>
+                       <button id="deleteprojects" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected projects</button>
+                       {% else %}
+                       <button id="createproject" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request project</button>
+                       {% endif %}
+                       </div>
+               </div>
+       </div>
+   {% endif %}
        <div class="tab-pane row" id="slices">
                <div class="col-md-12 el">
-           <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
+           <div id="slice-tab-loading" style="padding-bottom:10px;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
            <div id="slice-tab-loaded" style="display:none;">
                <table id="slice-tab" class="table">
                    <tr>
                    </tr>
                </table>                        
            </div>
-       {% if pi %}
         <div>
-               {% if  pi %}
+               {% if pi %}
                        <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
+            <button id="renewslices" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
+            <button id="deleteslices" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
                        {% else %}
                        <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
                        {% endif %}
-            <button id="renewslices" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
-            <button id="deleteslices" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
         </div>
-               {% endif %} 
           </div>
        </div>
        <div class="tab-pane row" id="requests">
@@ -98,7 +135,7 @@ $(document).ready(function() {
     {% if person %}
     {% if user_details.parent_authority %}
         $('#spinner').spin();
-
+        
         $.post("/rest/myslice:slice/",{'fields':['slice_hrn','users','url','slice_date_created'],'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
             var list_slices = [];
             var table_slices = [];
@@ -110,7 +147,6 @@ $(document).ready(function() {
                 }else{
                     nodes_length=val.nodes.length;
                 }
-                //console.log(val);
                 if(val.users=="undefined" || val.users==null){
                     users_length=0;
                 }else{
@@ -124,8 +160,15 @@ $(document).ready(function() {
                 }
                 
                 slice_row = "<tr id='"+val.slice_hrn+"'>";
-                slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
-                slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
+                slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'><div id='"+val.slice_hrn+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
+
+                // filter links to slices, only those that the user has credentials for
+                s = myslice.user.slices;
+                if(s.length > 0 && $.inArray(val.slice_hrn, myslice.user.slices)!=-1){
+                    slice_row += "<td><a href='/slice/"+val.slice_hrn+"'>" + val.slice_hrn + "</a></td>";
+                }else{
+                    slice_row += "<td>" + val.slice_hrn + "</td>";
+                }
                 slice_row += "<td>"+users_length+"</td>";
                 slice_row += "<td>"+slice_url+"</td>";
                 //slice_row += "<td>"+nodes_length+"</td>";
@@ -142,15 +185,12 @@ $(document).ready(function() {
         });
                
         {% if project %}
-        // XXX LOIC CACHE PB IF PREFIXED !
-               $.post("/rest/authority/",{'fields':['pi_users'],'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
+               $.post("/rest/myslice:authority/",{'fields':['pi_users'],'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
            
             var table_users = [];
             $.each( data[0].pi_users, function( key, val ) {
-                console.log(val);
                 user_row = "<tr id='"+val+"'>";
-                user_row += "<td><input type='checkbox' class='user' id='"+val+"'></td>";
-                user_row += "<td></td>";
+                user_row += "<td><input type='checkbox' class='user' id='"+val+"'><div id='"+val+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
                 user_row += "<td>"+val+"</td>";
                 user_row += "</tr>";
                 table_users.push(user_row);
@@ -161,7 +201,7 @@ $(document).ready(function() {
 
         });
         {% else %}
-        $.post("/rest/user/",{'fields':['user_hrn','user_email'],'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
+        $.post("/rest/myslice:user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
             var list_users = [];
             var table_users = [];
                    /* Available fields
@@ -171,7 +211,7 @@ $(document).ready(function() {
             $.each( data, function( key, val ) {
                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
                 user_row = "<tr id='"+val.user_hrn+"'>";
-                user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"' data-email='"+val.user_email+"'></td>";
+                user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"' data-email='"+val.user_email+"'><div id='"+val.user_hrn+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
                 user_row += "<td>"+val.user_email+"</td>";
                 user_row += "<td>"+val.user_hrn+"</td>";
                 /*
@@ -185,6 +225,28 @@ $(document).ready(function() {
             $("table#user-tab tr:last").after(table_users.join( "" ));
             $("div#user-tab-loaded").css("display","block");
             $("div#user-tab-loading").css("display","none");
+        });
+               $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS{{user_details.parent_authority}}'}}, function( data ) {
+           
+            var table_projects = [];
+            $.each( data, function( key, val ) {
+                project_row = "<tr id='"+val.authority_hrn+"'>";
+                project_row += "<td><input type='checkbox' class='project' id='"+val.authority_hrn+"'><div id='"+val.authority_hrn+"-loading' style='display:none;padding-left:3px;'><img src='{{ STATIC_URL }}img/loading.gif'></div></td>";
+
+                // filter links to projects, only those that the user has credentials for
+                p = myslice.projects;
+                if(p.length > 0 && $.inArray(val.authority_hrn, p)!=-1){
+                    project_row += "<td><a href='/portal/project/"+val.authority_hrn+"'>"+val.authority_hrn+"</a></td>";
+                }else{
+                    project_row += "<td>"+val.authority_hrn+"</td>";
+                }
+                project_row += "</tr>";
+                table_projects.push(project_row);
+            });
+            $("table#project-tab tr:last").after(table_projects.join( "" ));
+            $("div#project-tab-loaded").css("display","block");
+            $("div#project-tab-loading").css("display","none");
+
         });
 
         {% endif %}
@@ -212,6 +274,87 @@ $(document).ready(function() {
        } else {
                $('.nav-tabs a[href=#about]').click();
        }
+
+    //upgrade users to PI
+    $('button#makepi').click(function() {
+        spin_all();
+        var flag = false;
+        var pi_users = [];
+        $.post("/rest/myslice:authority/",{'filters':{'authority_hrn': '{{user_details.parent_authority}}'}}, function( data ) {
+            pi_users = data[0]["pi_users"];
+            $('input:checkbox.user').each(function (index) {
+                if(this.checked){
+                    var record_id = this.id;
+                    pi_users.push(record_id)
+                    $.post("/credentials/clear/",{'emails':[this.dataset['email']]}, function(data) {
+                    }); // post credentials clear
+                    flag = true;                
+                }
+            });
+            if(flag == true){
+                $.post("/update/myslice:authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'},'params':{'pi_users':pi_users}}, function(data) {
+                    if(data.success){
+                        mysliceAlert('Success: User rights added to: {{user_details.parent_authority}}','success', true);
+                    }else{
+                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                        //alert("Rest Error for "+record_id+": "+data.error);
+                    }
+                    unspin_all();
+                });
+            }
+        });
+    });
+//downgrade to user [in projects:remove from project]
+    $('button#removepi').click(function() {
+        spin_all();
+        var flag = false;
+        var pi_users = [];
+        $.post("/rest/myslice:authority/",{'filters':{'authority_hrn': '{{user_details.parent_authority}}'}}, function( data ) {
+            pi_users = data[0]["pi_users"];
+                       // http://stackoverflow.com/questions/9792927/javascript-array-search-and-remove-string
+            $('input:checkbox.user').each(function (index) {
+                if(this.checked){
+                    var record_id = this.id;
+                                       for (var i=pi_users.length-1; i>=0; i--) {
+                                       if (pi_users[i] === record_id) {
+                                               pi_users.splice(i, 1);
+                            $.post("/credentials/clear/",{'emails':[this.dataset['email']]}, function(data) {
+                            }); // post credentials clear
+                            flag = true;                
+                                       }
+                                       }
+                }
+            });
+            if(flag == true){
+                $.post("/update/myslice:authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'},'params':{'pi_users':pi_users}}, function(data) {
+                    if(data.success){
+                        mysliceAlert('Success: User rights removed from: {{user_details.parent_authority}}','success', true);
+                        {% if project %}
+                        // remove the user from the list of pis of the project displayed
+                        $('input:checkbox.user').each(function (index) {
+                           if(this.checked){
+                               var record_id = this.id;
+                               $('tr[id="'+record_id+'"]').fadeOut("slow");
+                               $('tr[id="'+record_id+'"]').remove();
+                            }
+
+                        });
+                        {% endif %}
+                    }else{
+                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                        //alert("Rest Error for "+record_id+": "+data.error);
+                    }
+                    unspin_all();
+                });
+            }else{
+                mysliceAlert('No action: User had no rights on: {{user_details.parent_authority}}','success', true);
+                unspin_all();
+            }
+        });
+    });
 });
+
+
+
 </script>
 {% endblock %}