X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fstatic%2Fjs%2Finstitution.js;h=a48a9a4b0e07d7a73241ffe57f069aba8ba98e73;hb=c457730e8d49ee507846edeb8a474374f0122f25;hp=dc44870299954cd2de68842da323e5b65909e6e3;hpb=b9f2bf8e9dde750eb6348e02f72f78b2248e8e5c;p=unfold.git diff --git a/portal/static/js/institution.js b/portal/static/js/institution.js index dc448702..a48a9a4b 100644 --- a/portal/static/js/institution.js +++ b/portal/static/js/institution.js @@ -1,53 +1,67 @@ $(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(); - } - } + loadedTabs = []; + + $('.nav-tabs a').click(function (e) { + e.preventDefault(); + $(this).tab('show'); + id = $(this).attr('href').substr(1); + if (!(id in loadedTabs)) { + switch(id) { + case 'users': + //loadUsers(); + loadedTabs[id] = true; + break; + } + } + + }); - /* 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) { + var user_email = this.dataset.email; + console.log(this); + // Delete in SFA Registry + $.post("/delete/user/",{'filters':{'user_hrn':record_id}}, function(data) { if(data.success){ - $('tr[id="'+record_id+'"]').fadeOut("slow"); - $('tr[id="'+record_id+'"]').remove(); + $.post("/local_user/delete/",{'filters':{'email':user_email}}, function(data) { + console.log(data); + if (data == true){ + mysliceAlert('Success: user deleted','success', true); + }else{ + mysliceAlert('Local DB Error for: '+record_id,'warning', true); + } + $('tr[id="'+record_id+'"]').fadeOut("slow"); + $('tr[id="'+record_id+'"]').remove(); + }); + //$.post("/delete/local:user/",{'filters':{'user_hrn':this.id}}, function(data) { }else{ - alert("Rest Error for "+record_id+": "+data.error); - } + mysliceAlert('Rest Error for: '+data.error,'warning', true); + //alert("Rest Error for "+record_id+": "+data.error); + } }); - - } + } }); }); + + /* TODO: factorize into functions */ $('button#deleteslices').click(function() { + var flag = false; $('input:checkbox.slice').each(function (index) { if(this.checked){ var record_id = this.id; $.post("/delete/slice/",{'filters':{'slice_hrn':this.id}}, function(data) { if(data.success){ + localStorage.clear(); $('tr[id="'+record_id+'"]').fadeOut("slow"); $('tr[id="'+record_id+'"]').remove(); + mysliceAlert('Success: slice deleted','success', true); }else{ - alert("Rest Error for "+record_id+": "+data.error); + mysliceAlert('Rest Error for: '+data.error,'warning', true); + //alert("Rest Error for "+record_id+": "+data.error); } }); - } }); }); @@ -56,7 +70,6 @@ $(document).ready(function() { /* In Javascript getMonth() gives month[0] = january, month[1] = february, and so on... */ var month = now.getMonth()+2; var one_month_later = now.getFullYear()+"-"+month+"-"+now.getDate()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(); - console.log(one_month_later); $('input:checkbox.slice').each(function (index) { if(this.checked){ var record_id = this.id; @@ -64,8 +77,10 @@ $(document).ready(function() { if(data.success){ // TODO: highlight row after success //$('tr[id="'+record_id+'"]').highlight(); + mysliceAlert('Success: slice renewed','success', true); }else{ - alert("Rest Error for "+record_id+": "+data.error); + mysliceAlert('Rest Error for: '+data.error,'warning', true); + //alert("Rest Error for "+record_id+": "+data.error); } }); @@ -74,13 +89,47 @@ $(document).ready(function() { // TODO: refresh table //window.location="/portal/institution#slices"; }); + $('button#deleteprojects').click(function() { + var flag = false; + $('input:checkbox.project').each(function (index) { + if(this.checked){ + var record_id = this.id; + console.log(record_id); + $.post("/delete/myslice:authority/",{'filters':{'authority_hrn':this.id}}, function(data) { + if(data.success){ + localStorage.clear(); + $('tr[id="'+record_id+'"]').fadeOut("slow"); + $('tr[id="'+record_id+'"]').remove(); + mysliceAlert('Success: project deleted','success', true); + }else{ + mysliceAlert('Rest Error for: '+data.error,'warning', true); + //alert("Rest Error for "+record_id+": "+data.error); + } + }); + } + }); + }); $('button#createslice').click(function() { window.location="/portal/slice_request/"; }); + + $('button#createproject').click(function() { + window.location="/portal/project_request/"; + }); $('button#slicerequestbtn').click(function() { /* window.location="/portal/slice_request/"; */ }); }); + +/*function loadUsers() { + $('div#users table').load('/table/user/', + { + 'fields' : [ 'user_hrn', 'user_first_name', 'user_last_name', 'user_email', 'user_phone' ], + 'filters' : { 'parent_authority' : $('div#users').data('authority') }, + 'options' : [ 'checkbox' ] + } + ); +}*/