Multiple Messages supported when sending Renew to several AMs
authorLoic Baron <loic.baron@lip6.fr>
Mon, 11 May 2015 18:16:14 +0000 (20:16 +0200)
committerLoic Baron <loic.baron@lip6.fr>
Mon, 11 May 2015 18:16:14 +0000 (20:16 +0200)
portal/static/css/myslice.css [new file with mode: 0644]
portal/static/js/institution.js
portal/static/js/myslice-ui.js
portal/templates/_widget-message.html
portal/templates/base.html

diff --git a/portal/static/css/myslice.css b/portal/static/css/myslice.css
new file mode 100644 (file)
index 0000000..e7c200a
--- /dev/null
@@ -0,0 +1,8 @@
+.myslice-message {
+    position:relative;
+    left:-491px;
+    width:980px;
+    margin:0 auto;
+    box-shadow: 10px 10px 5px #888888;
+    margin-bottom: 15px;
+}
index 1545263..c952a7a 100644 (file)
@@ -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']+'<br>';
+                    }
+                    if('value' in val && val['value']!=''){
+                        if(typeof val['value'] == 'string' || val['value'] instanceof String){
+                            txt += index+': '+val['value']+'<br>';
+                        }else{
+                            txt += index+': expiration = '+val['value'][0]['geni_expires']+'<br>';
+                        }
+                    }
+                }else{
+                    if('output' in val && val['output']!=''){
+                        errors += index+': '+val['output']+'<br>';
+                    }
+                    if('value' in val && val['value']!=''){
+                        errors += index+': '+val['value']+'<br>';
+                    }
+                }
+            }
+            if('error' in val){
+                errors += index+': '+val['error_msg']+'<br>';
+            } 
+        });
+        console.log(txt);
+        console.log(record_id);
+        if(txt != ''){
+            mysliceAlert('Success: '+record_id+'<br>'+txt,'success', false, record_id);
+        }
+        if(errors != ''){
+            mysliceAlert('Warning: '+record_id+'<br>'+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
index bd31f5b..1a3db49 100644 (file)
@@ -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("<div id='msg-"+level+"-"+id+"'></div>");
+    var msg_div = $('#msg-'+level+'-'+id);
+    msg_div.addClass('alert alert-dismissable myslice-message');
+    msg_div.append("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>");
+    msg_div.append("<span class='glyphicon glyphicon-exclamation-sign'></span>");
+    msg_div.append("<span class='message'></span>");
+       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 */
index 2fe3d0c..52cee29 100644 (file)
@@ -1,7 +1,2 @@
-<div style="display:none;position:fixed;left:50%;width:0;top:80px;z-index:999;">
-<div class="alert alert-dismissable" id="myslice-message" style="position:relative;left:-491px;width:980px;margin:0 auto;box-shadow: 10px 10px 5px #888888;">
-<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
-<span class="glyphicon glyphicon-exclamation-sign"></span>
-<span class="message"></span>
+<div style="display:none;position:fixed;left:50%;width:0;top:80px;z-index:999;" id="myslice-message">
 </div>
-</div>
\ No newline at end of file
index 4760849..8fbc2bb 100644 (file)
@@ -55,6 +55,7 @@
 {% insert_str prelude "css/topmenu.css" %}
 {% insert_str prelude "js/logout.js" %}
 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/{{ theme }}.css">
+<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/myslice.css">
 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/jquery.qtip.min.css">