</table>
</div>
- {% if pi %}
<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 %}
}else{
nodes_length=val.nodes.length;
}
- console.log(val);
+ //console.log(val);
if(val.users=="undefined" || val.users==null){
users_length=0;
}else{
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>";
+
+ // 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>";
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>";
});
{% 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
console.log(val);
project_row = "<tr id='"+val.authority_hrn+"'>";
project_row += "<td><input type='checkbox' class='project' id='"+val.authority_hrn+"'></td>";
- project_row += "<td><a href='/portal/project/"+val.authority_hrn+"'>"+val.authority_hrn+"</a></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);
});
$('.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);
+ {% 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);
+ }
+ });
+ }
+ });
+ });
+});
+
+
+
</script>
{% endblock %}