Multiple Messages supported when sending Renew to several AMs
[unfold.git] / portal / static / js / myslice-ui.js
index 2990f05..1a3db49 100644 (file)
@@ -1,42 +1,42 @@
 
+/*
+ * Call it with level: success, info, warning, danger
+ */
+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.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();
+            msg_div.remove();
+        },5000);
+       }
+};
 /* Table initialisation */
 $(document).ready(function() {
+       $('button[type=submit]').click(function() {
+               $('form').submit();
+       });
        
        var platformParameters = {};
-       
-               
-       
-       
-       /* Testbeds list */
-       $.post("/rest/network/", { "fields" : ["network_hrn", "network_longname", "description"]}, function(data) {
-               var testbed_data = [];
-               var testbed_row = "<thead>";
-               testbed_row += "<tr>";
-               testbed_row += "<th id=testbed_check><input type=\"checkbox\" name=\"network_hrn\" value=\"all\"/></th>";
-               testbed_row += "<th id=testbed_icon></th>";
-               testbed_row += "<th>network_hrn</th>";
-               testbed_row += "<th>Full name</th>";
-               testbed_row += "<th>Description</th>";
-               testbed_row += "</tr>";
-               testbed_row += "</thead>";
-               testbed_data.push(testbed_row);
-               $.each( data, function(key, val) {
-                       testbed_row = "<tr data-keys=\""+val.network_hrn+"\">"
-                       testbed_row += "<td><input type=\"checkbox\" name=\"network_hrn\" value=\""+val.network_hrn+"\"/></td>";
-                       testbed_row += "<td><img src='/static/img/testbeds/"+val.network_hrn+".png' alt='' /></td>";
-                       testbed_row += "<td>"+val.network_hrn+"</td>";
-                       testbed_row += "<td>"+val.network_longname+"</td>";
-                       testbed_row += "<td>"+val.description+"</td>";
-                       testbed_row += "</thead>";
-
-                       testbed_data.push(testbed_row);
-               });
-       $("table#testbedList").html(testbed_data.join(''));
-       $("div#testbed-list-loaded").css("display","block");
-       $("div#testbed-list-loading").css("display","none");
 
-                       
-       });
+       //mysliceAlert('hello','danger');
        
        $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
                $(this).dataTable( {
@@ -53,7 +53,15 @@ $(document).ready(function() {
                "bAutoHeight": false,
                "fnInitComplete": function(oSettings, json) {
                                for(var i = 0; i < myslice.pending.length; i++) {
-                                       $('*[data-key="'+myslice.pending[i]+'"]').addClass("active");
+                                       var el = $('*[data-key="'+myslice.pending[i]+'"]');
+                                       el.addClass("active");
+                                       el.find('input[type=checkbox]').prop('checked', true);
+                    /*
+                                       if (myslice.count() > 0) {
+                                               $('#badge-pending').text(myslice.count());
+                                               $('#badge-pending').show();
+                                       }
+                    */
                                }
                    }
                } );
@@ -67,18 +75,20 @@ $(document).ready(function() {
                                row.removeClass("active");
                                myslice.del(id);
                                cnt = myslice.count();
+                /*
                                $('#badge-pending').text(cnt);
                                if (cnt <= 0) {
                                        $('#badge-pending').hide();
-                               }
+                               }*/
                        } else {
                                row.addClass("active");
                                myslice.add(id);
+                /*
                                cnt = myslice.count();
                                $('#badge-pending').text(cnt);
                                if (cnt > 0) {
                                        $('#badge-pending').show();
-                               }
+                               }*/
                        }
                });
        });