3 * Call it with level: success, info, warning, danger
5 function mysliceAlert(msg, level, timeout) {
6 level = typeof level !== 'undefined' ? level : 'success';
7 timeout = typeof timeout !== 'undefined' ? timeout : false;
8 var el = $('#myslice-message');
9 el.find('.message').text(msg);
10 el.addClass('alert-' + level);
11 el.parent().fadeIn('fast');
13 setTimeout(function(){el.alert('close');},5000);
16 /* Table initialisation */
17 $(document).ready(function() {
19 var platformParameters = {};
21 $('#myslice-message').bind('closed.bs.alert', function () {
22 $(this).parent().hide();
25 //mysliceAlert('hello','danger');
28 $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
30 "sScrollY": window.innerHeight - 275,
32 "bScrollCollapse": true,
35 "bLengthChange": false,
41 "fnInitComplete": function(oSettings, json) {
42 for(var i = 0; i < myslice.pending.length; i++) {
43 var el = $('*[data-key="'+myslice.pending[i]+'"]');
44 el.addClass("active");
45 el.find('input[type=checkbox]').prop('checked', true);
47 if (myslice.count() > 0) {
48 $('#badge-pending').text(myslice.count());
49 $('#badge-pending').show();
57 $("input[type=checkbox]").click(function() {
59 var id = $(this).val();
60 var row = $(this).parent().parent()
61 if (row.hasClass("active")) {
62 row.removeClass("active");
64 cnt = myslice.count();
66 $('#badge-pending').text(cnt);
68 $('#badge-pending').hide();
71 row.addClass("active");
74 cnt = myslice.count();
75 $('#badge-pending').text(cnt);
77 $('#badge-pending').show();
86 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
87 //make sure to expose csrf in our outcoming ajax/post requests
89 beforeSend: function(xhr, settings) {
90 function getCookie(name) {
91 var cookieValue = null;
92 if (document.cookie && document.cookie != '') {
93 var cookies = document.cookie.split(';');
94 for (var i = 0; i < cookies.length; i++) {
95 var cookie = jQuery.trim(cookies[i]);
96 // Does this cookie string begin with the name we want?
97 if (cookie.substring(0, name.length + 1) == (name + '=')) {
98 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
105 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
106 // Only send the token to relative URLs i.e. locally.
107 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));