Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[unfold.git] / portal / static / js / myslice-ui.js
index 1195969..4437941 100644 (file)
@@ -4,7 +4,6 @@ $(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>';
@@ -13,29 +12,17 @@ $(document).ready(function() {
                }
                $('#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);
-               // });
+               
        });
        
        /* Testbeds list */
-       $('div#testbed-list').ready(function() {
-               $('table#testbedList').load("/table/testbed", function() {
+       $("div#testbed-list").ready(function() {
+               $("table#testbedList").load("/table/network/", { "fields" : ["network_hrn","description"], "options": ["checkbox"] }, function() {
                        
                });
        });
        
-       //{'columns' : ['hostname','country','type'], 'filters' : { 'country' : 'France' } }
-       oTable.load("/table/resource/", {'fields' : ['hostname','hrn','country','type'], 'options': ['checkbox'] }, 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 +34,41 @@ $(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++) {
+                                       $('*[data-key="'+myslice.pending[i]+'"]').addClass("active");
+                               }
+                   }
                } );
+               
+               
+               $("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
@@ -80,4 +94,4 @@ $.ajaxSetup({
              xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
          }
      } 
-});
\ No newline at end of file
+});