3 * Call it with level: success, info, warning, danger
5 function mysliceAlert(msg, level, timeout, id) {
6 level = typeof level !== 'undefined' ? level : 'success';
7 timeout = typeof timeout !== 'undefined' ? timeout : false;
8 id = typeof id !== 'undefined' ? id : '';
10 // onelab.upmc.slice the dot is causing a pb in the jQuery selector, so replace it !
11 id = id.replace(/\./g,'');
13 var el = $('#myslice-message');
14 el.append("<div id='msg-"+level+"-"+id+"'></div>");
15 var msg_div = $('#msg-'+level+'-'+id);
16 msg_div.addClass('alert alert-dismissable myslice-message');
17 msg_div.append("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>");
18 msg_div.append("<span class='glyphicon glyphicon-exclamation-sign'></span>");
19 msg_div.append("<span class='message'></span>");
20 msg_div.find('.message').html(msg);
21 msg_div.addClass('alert-' + level);
23 el.parent().fadeIn('fast');
25 setTimeout(function(){
31 /* Table initialisation */
32 $(document).ready(function() {
33 $('button[type=submit]').click(function() {
37 var platformParameters = {};
39 //mysliceAlert('hello','danger');
41 $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
43 "sScrollY": window.innerHeight - 275,
45 "bScrollCollapse": true,
48 "bLengthChange": false,
54 "fnInitComplete": function(oSettings, json) {
55 for(var i = 0; i < myslice.pending.length; i++) {
56 var el = $('*[data-key="'+myslice.pending[i]+'"]');
57 el.addClass("active");
58 el.find('input[type=checkbox]').prop('checked', true);
60 if (myslice.count() > 0) {
61 $('#badge-pending').text(myslice.count());
62 $('#badge-pending').show();
70 $("input[type=checkbox]").click(function() {
72 var id = $(this).val();
73 var row = $(this).parent().parent()
74 if (row.hasClass("active")) {
75 row.removeClass("active");
77 cnt = myslice.count();
79 $('#badge-pending').text(cnt);
81 $('#badge-pending').hide();
84 row.addClass("active");
87 cnt = myslice.count();
88 $('#badge-pending').text(cnt);
90 $('#badge-pending').show();
99 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
100 //make sure to expose csrf in our outcoming ajax/post requests
102 beforeSend: function(xhr, settings) {
103 function getCookie(name) {
104 var cookieValue = null;
105 if (document.cookie && document.cookie != '') {
106 var cookies = document.cookie.split(';');
107 for (var i = 0; i < cookies.length; i++) {
108 var cookie = jQuery.trim(cookies[i]);
109 // Does this cookie string begin with the name we want?
110 if (cookie.substring(0, name.length + 1) == (name + '=')) {
111 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
118 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
119 // Only send the token to relative URLs i.e. locally.
120 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));