X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=portal%2Fstatic%2Fjs%2Fmyslice-ui.js;h=1c91ccd2983d6a7c17475fa95529f55b16238978;hb=e7c6e9d4d40c322684dc0433eb85a7bf85f68f7f;hp=3b9ef5db6490f0597f8c84d921698a44d33411ba;hpb=e1968e52032e00a276b4cc583b5f90d6cdd98844;p=unfold.git diff --git a/portal/static/js/myslice-ui.js b/portal/static/js/myslice-ui.js index 3b9ef5db..1c91ccd2 100644 --- a/portal/static/js/myslice-ui.js +++ b/portal/static/js/myslice-ui.js @@ -1,70 +1,83 @@ +/* + * Call it with level: success, info, warning, danger + */ +function mysliceAlert(msg, level, timeout) { + level = typeof level !== 'undefined' ? level : 'success'; + timeout = typeof timeout !== 'undefined' ? timeout : false; + var el = $('#myslice-message'); + el.find('.message').text(msg); + el.addClass('alert-' + level); + el.parent().fadeIn('fast'); + if (timeout) { + setTimeout(function(){el.alert('close');},5000); + } +}; /* Table initialisation */ $(document).ready(function() { var platformParameters = {}; - var oTable = $("#objectList"); - - $.get("/rest/platform", function(data) { - var list = '
Testbeds
'; - for(i=0; i'+data[i].platform_longname+'

'+data[i].platform+'

'; - } - $('#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(data) { - $(this).dataTable( { - "bScrollInfinite": true, - "bScrollCollapse": true, - "sScrollY": "500px", - "bStateSave": true, - "bPaginate": false, - "bLengthChange": false, - "bFilter": true, - "bSort": true, - "bInfo": false, - "bAutoWidth": false - } ); - }); + $('#myslice-message').bind('closed.bs.alert', function () { + $(this).parent().hide(); }); + + mysliceAlert('hello','danger'); - oTable.load("/list/resource", {}, function(data) { + $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) { $(this).dataTable( { - "bScrollInfinite": true, + "sScrollY": window.innerHeight - 275, + "sDom": "frtiS", "bScrollCollapse": true, - "sScrollY": "500px", "bStateSave": true, "bPaginate": false, "bLengthChange": false, - "bFilter": true, + "bFilter": false, "bSort": true, "bInfo": false, - "bAutoWidth": false + "bAutoWidth": true, + "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 @@ -90,4 +103,4 @@ $.ajaxSetup({ xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); } } -}); \ No newline at end of file +});