+ });
+ $.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();
+ }
+ });