Institution:Remove PI/Project added
[myslice.git] / portal / templates / fed4fire / fed4fire_institution.html
index 021e3ee..d402586 100644 (file)
@@ -143,7 +143,7 @@ $(document).ready(function() {
                 }else{
                     nodes_length=val.nodes.length;
                 }
-                console.log(val);
+                //console.log(val);
                 if(val.users=="undefined" || val.users==null){
                     users_length=0;
                 }else{
@@ -179,7 +179,7 @@ $(document).ready(function() {
            
             var table_users = [];
             $.each( data[0].pi_users, function( key, val ) {
-                console.log(val);
+                //console.log(val);
                 user_row = "<tr id='"+val+"'>";
                 user_row += "<td><input type='checkbox' class='user' id='"+val+"'></td>";
                 user_row += "<td>"+val+"</td>";
@@ -260,5 +260,68 @@ $(document).ready(function() {
                $('.nav-tabs a[href=#about]').click();
        }
 });
+
+//upgrade users to PI
+$(document).ready(function() {
+    $('button#makepi').click(function() {
+        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)
+                    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);
+                    }
+                });
+            }
+        });
+    });
+});
+//downgrade to user [in projects:remove from project]
+$(document).ready(function() {
+    $('button#removepi').click(function() {
+        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);
+                                       }
+                                       }
+                    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);
+                    }else{
+                        mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                        //alert("Rest Error for "+record_id+": "+data.error);
+                    }
+                });
+            }
+        });
+    });
+});
+
+
+
 </script>
 {% endblock %}