2 /* Table initialisation */
3 $(document).ready(function() {
5 var platformParameters = {};
11 $("table#testbedList").load("/table/network/", { "fields" : ["network_hrn","description"], "options": ["checkbox"] }, function() {
13 "sScrollY": window.innerHeight - 275,
15 "bScrollCollapse": true,
18 "bLengthChange": false,
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);
45 if (myslice.count() > 0) {
46 $('#badge-pending').text(myslice.count());
47 $('#badge-pending').show();
54 $("input[type=checkbox]").click(function() {
56 var id = $(this).val();
57 var row = $(this).parent().parent()
58 if (row.hasClass("active")) {
59 row.removeClass("active");
61 cnt = myslice.count();
62 $('#badge-pending').text(cnt);
64 $('#badge-pending').hide();
67 row.addClass("active");
69 cnt = myslice.count();
70 $('#badge-pending').text(cnt);
72 $('#badge-pending').show();
81 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
82 //make sure to expose csrf in our outcoming ajax/post requests
84 beforeSend: function(xhr, settings) {
85 function getCookie(name) {
86 var cookieValue = null;
87 if (document.cookie && document.cookie != '') {
88 var cookies = document.cookie.split(';');
89 for (var i = 0; i < cookies.length; i++) {
90 var cookie = jQuery.trim(cookies[i]);
91 // Does this cookie string begin with the name we want?
92 if (cookie.substring(0, name.length + 1) == (name + '=')) {
93 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
100 if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
101 // Only send the token to relative URLs i.e. locally.
102 xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));