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);
12 el.parent().fadeIn('fast');
14 setTimeout(function(){el.hide();},5000);
17 /* Table initialisation */
18 $(document).ready(function() {
19 $('button[type=submit]').click(function() {
23 var platformParameters = {};
25 //mysliceAlert('hello','danger');
27 $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
29 "sScrollY": window.innerHeight - 275,
31 "bScrollCollapse": true,
34 "bLengthChange": false,
40 "fnInitComplete": function(oSettings, json) {
41 for(var i = 0; i < myslice.pending.length; i++) {
42 var el = $('*[data-key="'+myslice.pending[i]+'"]');
43 el.addClass("active");
44 el.find('input[type=checkbox]').prop('checked', true);
46 if (myslice.count() > 0) {
47 $('#badge-pending').text(myslice.count());
48 $('#badge-pending').show();
56 $("input[type=checkbox]").click(function() {
58 var id = $(this).val();
59 var row = $(this).parent().parent()
60 if (row.hasClass("active")) {
61 row.removeClass("active");
63 cnt = myslice.count();
65 $('#badge-pending').text(cnt);
67 $('#badge-pending').hide();
70 row.addClass("active");
73 cnt = myslice.count();
74 $('#badge-pending').text(cnt);
76 $('#badge-pending').show();
85 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
86 //make sure to expose csrf in our outcoming ajax/post requests
88 beforeSend: function(xhr, settings) {
89 function getCookie(name) {
90 var cookieValue = null;
91 if (document.cookie && document.cookie != '') {
92 var cookies = document.cookie.split(';');
93 for (var i = 0; i < cookies.length; i++) {
94 var cookie = jQuery.trim(cookies[i]);
95 // Does this cookie string begin with the name we want?
96 if (cookie.substring(0, name.length + 1) == (name + '=')) {
97 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
104 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
105 // Only send the token to relative URLs i.e. locally.
106 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));