2 function mysliceAlert(msg) {
3 $('#myslice-message').find('.message').text(msg);
4 $('#myslice-message').fadeIn('fast');
6 /* Table initialisation */
7 $(document).ready(function() {
9 var platformParameters = {};
16 $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
18 "sScrollY": window.innerHeight - 275,
20 "bScrollCollapse": true,
23 "bLengthChange": false,
29 "fnInitComplete": function(oSettings, json) {
30 for(var i = 0; i < myslice.pending.length; i++) {
31 var el = $('*[data-key="'+myslice.pending[i]+'"]');
32 el.addClass("active");
33 el.find('input[type=checkbox]').prop('checked', true);
34 if (myslice.count() > 0) {
35 $('#badge-pending').text(myslice.count());
36 $('#badge-pending').show();
43 $("input[type=checkbox]").click(function() {
45 var id = $(this).val();
46 var row = $(this).parent().parent()
47 if (row.hasClass("active")) {
48 row.removeClass("active");
50 cnt = myslice.count();
51 $('#badge-pending').text(cnt);
53 $('#badge-pending').hide();
56 row.addClass("active");
58 cnt = myslice.count();
59 $('#badge-pending').text(cnt);
61 $('#badge-pending').show();
70 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
71 //make sure to expose csrf in our outcoming ajax/post requests
73 beforeSend: function(xhr, settings) {
74 function getCookie(name) {
75 var cookieValue = null;
76 if (document.cookie && document.cookie != '') {
77 var cookies = document.cookie.split(';');
78 for (var i = 0; i < cookies.length; i++) {
79 var cookie = jQuery.trim(cookies[i]);
80 // Does this cookie string begin with the name we want?
81 if (cookie.substring(0, name.length + 1) == (name + '=')) {
82 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
89 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
90 // Only send the token to relative URLs i.e. locally.
91 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));