2 /* Table initialisation */
3 $(document).ready(function() {
5 var platformParameters = {};
12 $("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
14 "sScrollY": window.innerHeight - 275,
16 "bScrollCollapse": true,
19 "bLengthChange": false,
25 "fnInitComplete": function(oSettings, json) {
26 for(var i = 0; i < myslice.pending.length; i++) {
27 var el = $('*[data-key="'+myslice.pending[i]+'"]');
28 el.addClass("active");
29 el.find('input[type=checkbox]').prop('checked', true);
30 if (myslice.count() > 0) {
31 $('#badge-pending').text(myslice.count());
32 $('#badge-pending').show();
39 $("input[type=checkbox]").click(function() {
41 var id = $(this).val();
42 var row = $(this).parent().parent()
43 if (row.hasClass("active")) {
44 row.removeClass("active");
46 cnt = myslice.count();
47 $('#badge-pending').text(cnt);
49 $('#badge-pending').hide();
52 row.addClass("active");
54 cnt = myslice.count();
55 $('#badge-pending').text(cnt);
57 $('#badge-pending').show();
66 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
67 //make sure to expose csrf in our outcoming ajax/post requests
69 beforeSend: function(xhr, settings) {
70 function getCookie(name) {
71 var cookieValue = null;
72 if (document.cookie && document.cookie != '') {
73 var cookies = document.cookie.split(';');
74 for (var i = 0; i < cookies.length; i++) {
75 var cookie = jQuery.trim(cookies[i]);
76 // Does this cookie string begin with the name we want?
77 if (cookie.substring(0, name.length + 1) == (name + '=')) {
78 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
85 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
86 // Only send the token to relative URLs i.e. locally.
87 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));