Multiple Messages supported when sending Renew to several AMs
[unfold.git] / portal / static / js / myslice-ui.js
index f1492e3..1a3db49 100644 (file)
@@ -1,41 +1,44 @@
 
+/*
+ * 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() {
-       
-       var platformParameters = {};
-       
-       var oTable = $("#objectList");
-               
-       $.get("/rest/platform", function(data) {
-               var list = '<div class="list-group-item sl-platfrom"><span class="list-group-item-heading">Testbeds</span></div>';
-               for(i=0; i<data.length;i++) {
-                       list += '<a href="#" class="list-group-item sl-platfrom" data-platform="'+data[i].platform+'"><span class="list-group-item-heading">'+data[i].platform_longname+'</span><p class="list-group-item-text">'+data[i].platform+'</p></a>';
-               }
-               $('#select-platform').html(list);
-       }).done(function() {
-               // $('a.sl-platfrom').click(function() {
-                       // console.log($(this).data('platform'));
-                       // platformParameters = { "platform" : $(this).data('platform') };
-                       // $('a.sl-platfrom').removeClass('active');
-                       // $(this).addClass('active');
-//                     
-                       // oTable.load("/list/resource", platformParameters, function(data) {
-                               // oTable.fnDraw();
-                       // });
-//                     
-                       // $('body').data('filters',platformParameters);
-               // });
+       $('button[type=submit]').click(function() {
+               $('form').submit();
        });
        
-       /* Testbeds list */
-       $('div#testbed-list').ready(function() {
-               $('table#testbedList').load("/table/network/",{'fields' : ['platform'], 'options': ['checkbox']}, function() {
-                       
-               });
-       });
+       var platformParameters = {};
+
+       //mysliceAlert('hello','danger');
        
-       //{'columns' : ['hostname','country','type'], 'filters' : { 'country' : 'France' } }
-       oTable.load("/table/resource/", {'columns' : ['hostname','country','type'] }, function(data) {
+       $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
                $(this).dataTable( {
                        "sScrollY": window.innerHeight - 275,
                        "sDom": "frtiS",
@@ -47,14 +50,51 @@ $(document).ready(function() {
                "bSort": true,
                "bInfo": false,
                "bAutoWidth": true,
-               "bAutoHeight": false
+               "bAutoHeight": false,
+               "fnInitComplete": function(oSettings, json) {
+                               for(var i = 0; i < myslice.pending.length; i++) {
+                                       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();
+                                       }
+                    */
+                               }
+                   }
                } );
+               
+               
+               $("input[type=checkbox]").click(function() {
+                       var cnt = 0;
+                       var id = $(this).val();
+                       var row = $(this).parent().parent()
+                       if (row.hasClass("active")) {
+                               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();
+                               }*/
+                       }
+               });
        });
-} );
-
-function drawTable(data) {
        
-}
+       
+});
 
 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
 //make sure to expose csrf in our outcoming ajax/post requests