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() {
18 $('button[type=submit]').click(function() {
22 var platformParameters = {};
24 $('#myslice-message').bind('closed.bs.alert', function () {
25 $(this).parent().hide();
28 //mysliceAlert('hello','danger');
31 $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
33 "sScrollY": window.innerHeight - 275,
35 "bScrollCollapse": true,
38 "bLengthChange": false,
44 "fnInitComplete": function(oSettings, json) {
45 for(var i = 0; i < myslice.pending.length; i++) {
46 var el = $('*[data-key="'+myslice.pending[i]+'"]');
47 el.addClass("active");
48 el.find('input[type=checkbox]').prop('checked', true);
50 if (myslice.count() > 0) {
51 $('#badge-pending').text(myslice.count());
52 $('#badge-pending').show();
60 $("input[type=checkbox]").click(function() {
62 var id = $(this).val();
63 var row = $(this).parent().parent()
64 if (row.hasClass("active")) {
65 row.removeClass("active");
67 cnt = myslice.count();
69 $('#badge-pending').text(cnt);
71 $('#badge-pending').hide();
74 row.addClass("active");
77 cnt = myslice.count();
78 $('#badge-pending').text(cnt);
80 $('#badge-pending').show();
89 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
90 //make sure to expose csrf in our outcoming ajax/post requests
92 beforeSend: function(xhr, settings) {
93 function getCookie(name) {
94 var cookieValue = null;
95 if (document.cookie && document.cookie != '') {
96 var cookies = document.cookie.split(';');
97 for (var i = 0; i < cookies.length; i++) {
98 var cookie = jQuery.trim(cookies[i]);
99 // Does this cookie string begin with the name we want?
100 if (cookie.substring(0, name.length + 1) == (name + '=')) {
101 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
108 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
109 // Only send the token to relative URLs i.e. locally.
110 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));