Institution: delete users and slices - this only works if the user has an authority...
authorLoic Baron <loic.baron@lip6.fr>
Sat, 1 Mar 2014 16:34:05 +0000 (17:34 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Sat, 1 Mar 2014 16:34:05 +0000 (17:34 +0100)
portal/static/js/institution.js [new file with mode: 0644]
portal/templates/institution.html

diff --git a/portal/static/js/institution.js b/portal/static/js/institution.js
new file mode 100644 (file)
index 0000000..9190781
--- /dev/null
@@ -0,0 +1,63 @@
+$(document).ready(function() {
+    $('a.home-tab').click(function() {
+        $('ul.nav-tabs li').removeClass('active');
+        $(this).parent().addClass('active');
+        $('div.home-panel').hide();
+        $('div#'+$(this).data('panel')).show();
+    });
+    var url = window.location;
+    if(url.hash) {
+        // Fragment exists 
+        tab = url.href.split("#")[1];
+        tab_exists = $('div#'+tab).length;
+        if (tab_exists) {
+           $('ul.nav-tabs li').removeClass('active');
+           $('li#'+tab+'-tab').addClass('active');
+           $('div.home-panel').hide();            
+           $('div#'+tab).show();
+        }
+    }
+
+    /* TODO: factorize into functions */
+    $('button#deleteusers').click(function() {
+        $('input:checkbox.user').each(function (index) {
+            if(this.checked){
+                var record_id = this.id;
+                $.post("/delete/user/",{'filters':{'user_hrn':this.id}}, function(data) {
+                    if(data.success){
+                        $('tr[id="'+record_id+'"]').fadeOut("slow");
+                        $('tr[id="'+record_id+'"]').remove();
+                    }else{
+                        alert("Rest Error for "+record_id+": "+data.error);
+                    }
+                });
+                
+            }
+        });
+    });
+    $('button#deleteslices').click(function() {
+        $('input:checkbox.slice').each(function (index) {
+            if(this.checked){
+                var record_id = this.id;
+                $.post("/delete/slice/",{'filters':{'user_hrn':this.id}}, function(data) {
+                    if(data.success){
+                        $('tr[id="'+record_id+'"]').fadeOut("slow");
+                        $('tr[id="'+record_id+'"]').remove();
+                    }else{
+                        alert("Rest Error for "+record_id+": "+data.error);
+                    }
+                });
+                
+            }
+        });
+    });
+
+    $('button#createslice').click(function() {
+        window.location="/portal/slice_request/";
+    });
+    $('button#slicerequestbtn').click(function() {
+        /*
+        window.location="/portal/slice_request/";
+        */
+    });
+});
index d8fb1d7..1cef373 100644 (file)
@@ -1,5 +1,7 @@
 {% extends "layout.html" %}
-
+{% block head %} 
+<script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script>
+{% endblock head %}
 {% block content %}
 <div class="row">
        <h1><img src="{{ STATIC_URL }}img/icon_authority_color_small.png" alt="" /> Institution: {{user_details.parent_authority}}</h1>
 </div>
 <script>
     $(document).ready(function() {
-        $('a.home-tab').click(function() {
-            $('ul.nav-tabs li').removeClass('active');
-            $(this).parent().addClass('active');
-            $('div.home-panel').hide();
-            $('div#'+$(this).data('panel')).show();
-        });
-        var url = window.location;
-        if(url.hash) {
-            // Fragment exists 
-            tab = url.href.split("#")[1];
-            tab_exists = $('div#'+tab).length;
-            if (tab_exists) {
-               $('ul.nav-tabs li').removeClass('active');
-               $('li#'+tab+'-tab').addClass('active');
-               $('div.home-panel').hide();            
-               $('div#'+tab).show();
-            }
-        }
-        $('button#createslice').click(function() {
-            window.location="/portal/slice_request/";
-        })
-        ;$('button#slicerequestbtn').click(function() {
-            /*
-            window.location="/portal/slice_request/";
-            */
-        });
         {% if person %}
         {% if user_details.parent_authority %}
         $.post("/rest/authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
                     slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
                 }
                 
-                slice_row = "<tr>";
-                slice_row += "<td><input type='checkbox'></td>";
+                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>"+user_length+"</td>";
                 slice_row += "<td>"+slice_url+"</td>";
                        */
             $.each( data, function( key, val ) {
                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
-                user_row = "<tr>";
-                user_row += "<td><input type='checkbox'></td>";
+
+                user_row = "<tr id='"+val.user_hrn+"'>";
+                user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
                 user_row += "<td>"+val.user_email+"</td>";
                 user_row += "<td>"+val.user_hrn+"</td>";
                 user_row += "<td>"+val.user_first_name+"</td>";