From 225a0f7799c43d63e04ec5639f14690bc941b5b2 Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Mon, 11 May 2015 20:16:14 +0200 Subject: [PATCH] Multiple Messages supported when sending Renew to several AMs --- portal/static/css/myslice.css | 8 ++++ portal/static/js/institution.js | 63 +++++++++++++++++++++------ portal/static/js/myslice-ui.js | 22 ++++++++-- portal/templates/_widget-message.html | 7 +-- portal/templates/base.html | 1 + 5 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 portal/static/css/myslice.css diff --git a/portal/static/css/myslice.css b/portal/static/css/myslice.css new file mode 100644 index 00000000..e7c200ac --- /dev/null +++ b/portal/static/css/myslice.css @@ -0,0 +1,8 @@ +.myslice-message { + position:relative; + left:-491px; + width:980px; + margin:0 auto; + box-shadow: 10px 10px 5px #888888; + margin-bottom: 15px; +} diff --git a/portal/static/js/institution.js b/portal/static/js/institution.js index 1545263f..c952a7a4 100644 --- a/portal/static/js/institution.js +++ b/portal/static/js/institution.js @@ -12,6 +12,49 @@ function spin_all(){ } }); } +function post_renew(obj){ + var record_id = obj.id; + $.post("/sfa/Renew/",{'hrn':record_id,'type':'slice'}, function(data) { + txt = ''; + errors = ''; + $.each(data, function (index, val) { + console.log(index, val); + if (index != 'columns' && !('error' in val)){ + if('code' in val && val['code']['geni_code']==0){ + if('output' in val && val['output']!=''){ + txt += index+': '+val['output']+'
'; + } + if('value' in val && val['value']!=''){ + if(typeof val['value'] == 'string' || val['value'] instanceof String){ + txt += index+': '+val['value']+'
'; + }else{ + txt += index+': expiration = '+val['value'][0]['geni_expires']+'
'; + } + } + }else{ + if('output' in val && val['output']!=''){ + errors += index+': '+val['output']+'
'; + } + if('value' in val && val['value']!=''){ + errors += index+': '+val['value']+'
'; + } + } + } + if('error' in val){ + errors += index+': '+val['error_msg']+'
'; + } + }); + console.log(txt); + console.log(record_id); + if(txt != ''){ + mysliceAlert('Success: '+record_id+'
'+txt,'success', false, record_id); + } + if(errors != ''){ + mysliceAlert('Warning: '+record_id+'
'+errors,'warning', false, record_id); + } + unspin_all(); + }); +} $(document).ready(function() { loadedTabs = []; @@ -85,6 +128,7 @@ $(document).ready(function() { }); }); $('button#renewslices').click(function() { + var record_id; spin_all(); var now = new Date(); /* In Javascript getMonth() gives month[0] = january, month[1] = february, and so on... */ @@ -92,20 +136,11 @@ $(document).ready(function() { 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; - $('#'+record_id+'-loading').spin(); - $.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); - } - unspin_all(); - }); - + console.log(this.id); + record_id = $(this).attr('id'); + $('#'+this.id+'-loading').spin(); + // /sfa/Renew?hrn=onelab.upmc.projectx.slicex&type=slice + post_renew(this); } }); // TODO: refresh table diff --git a/portal/static/js/myslice-ui.js b/portal/static/js/myslice-ui.js index bd31f5be..1a3db498 100644 --- a/portal/static/js/myslice-ui.js +++ b/portal/static/js/myslice-ui.js @@ -2,16 +2,30 @@ /* * Call it with level: success, info, warning, danger */ -function mysliceAlert(msg, level, timeout) { +function mysliceAlert(msg, level, timeout, id) { level = typeof level !== 'undefined' ? level : 'success'; timeout = typeof timeout !== 'undefined' ? timeout : false; + id = typeof id !== 'undefined' ? id : ''; + + // onelab.upmc.slice the dot is causing a pb in the jQuery selector, so replace it ! + id = id.replace(/\./g,''); + var el = $('#myslice-message'); - el.find('.message').text(msg); - el.addClass('alert-' + level); + el.append("
"); + var msg_div = $('#msg-'+level+'-'+id); + msg_div.addClass('alert alert-dismissable myslice-message'); + msg_div.append(""); + msg_div.append(""); + msg_div.append(""); + msg_div.find('.message').html(msg); + msg_div.addClass('alert-' + level); el.fadeIn('fast'); el.parent().fadeIn('fast'); if (timeout) { - setTimeout(function(){el.hide();},5000); + setTimeout(function(){ + el.hide(); + msg_div.remove(); + },5000); } }; /* Table initialisation */ diff --git a/portal/templates/_widget-message.html b/portal/templates/_widget-message.html index 2fe3d0c7..52cee290 100644 --- a/portal/templates/_widget-message.html +++ b/portal/templates/_widget-message.html @@ -1,7 +1,2 @@ -
-
- - - + -
\ No newline at end of file diff --git a/portal/templates/base.html b/portal/templates/base.html index 47608496..8fbc2bbf 100644 --- a/portal/templates/base.html +++ b/portal/templates/base.html @@ -55,6 +55,7 @@ {% insert_str prelude "css/topmenu.css" %} {% insert_str prelude "js/logout.js" %} + -- 2.43.0