X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fstatic%2Fjs%2Finstitution.js;h=a48a9a4b0e07d7a73241ffe57f069aba8ba98e73;hb=c457730e8d49ee507846edeb8a474374f0122f25;hp=17858fed2b3fbd8bc43f93f32036bc2b8b95da41;hpb=d251934bd71c678f552dc9a1d49c3f8efe102e1e;p=unfold.git diff --git a/portal/static/js/institution.js b/portal/static/js/institution.js index 17858fed..a48a9a4b 100644 --- a/portal/static/js/institution.js +++ b/portal/static/js/institution.js @@ -1,53 +1,111 @@ $(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){ + $.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{ + 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); } }); - } }); }); - $('button#deleteslices').click(function() { + $('button#renewslices').click(function() { + var now = new Date(); + /* 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(); $('input:checkbox.slice').each(function (index) { if(this.checked){ var record_id = this.id; - $.post("/delete/slice/",{'filters':{'slice_hrn':this.id}}, function(data) { + $.post("/update/slice/",{'filters':{'slice_hrn':this.id},'params':{'expires':one_month_later}}, function(data) { if(data.success){ + // TODO: highlight row after success + //$('tr[id="'+record_id+'"]').highlight(); + mysliceAlert('Success: slice renewed','success', true); + }else{ + mysliceAlert('Rest Error for: '+data.error,'warning', true); + //alert("Rest Error for "+record_id+": "+data.error); + } + }); + + } + }); + // 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{ - alert("Rest Error for "+record_id+": "+data.error); + mysliceAlert('Rest Error for: '+data.error,'warning', true); + //alert("Rest Error for "+record_id+": "+data.error); } }); - } }); }); @@ -55,9 +113,23 @@ $(document).ready(function() { $('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' ] + } + ); +}*/