b60c7c1cfd47a1a4ec474bb34af253e7c7067500
[myslice.git] / portal / static / js / myslice-ui.js
1
2 /* Table initialisation */
3 $(document).ready(function() {
4         
5         var platformParameters = {};
6         
7         var oTable = $("#objectList");
8                 
9         $.get("/rest/platform", function(data) {
10                 var list = '<div class="list-group-item sl-platfrom"><span class="list-group-item-heading">Testbeds</span></div>';
11                 for(i=0; i<data.length;i++) {
12                         list += '<a href="#" class="list-group-item sl-platfrom" data-platform="'+data[i].platform+'"><span class="list-group-item-heading">'+data[i].platform_longname+'</span><p class="list-group-item-text">'+data[i].platform+'</p></a>';
13                 }
14                 $('#select-platform').html(list);
15         }).done(function() {
16                 // $('a.sl-platfrom').click(function() {
17                         // console.log($(this).data('platform'));
18                         // platformParameters = { "platform" : $(this).data('platform') };
19                         // $('a.sl-platfrom').removeClass('active');
20                         // $(this).addClass('active');
21 //                      
22                         // oTable.load("/list/resource", platformParameters, function(data) {
23                                 // oTable.fnDraw();
24                         // });
25 //                      
26                         // $('body').data('filters',platformParameters);
27                 // });
28         });
29         
30         /* Testbeds list */
31         $('div#testbed-list').ready(function() {
32                 $('table#testbedList').load("/table/testbed", function() {
33                         
34                 });
35         });
36         
37         
38         oTable.load("/list/resource", {}, function(data) {
39                 $(this).dataTable( {
40                         "bScrollInfinite": true,
41                 "bScrollCollapse": true,
42                 "sScrollY": "500px",
43                 "bStateSave": true,
44                 "bPaginate": false,
45                 "bLengthChange": false,
46                 "bFilter": true,
47                 "bSort": true,
48                 "bInfo": false,
49                 "bAutoWidth": false
50                 } );
51         });
52 } );
53
54 function drawTable(data) {
55         
56 }
57
58 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
59 //make sure to expose csrf in our outcoming ajax/post requests
60 $.ajaxSetup({ 
61      beforeSend: function(xhr, settings) {
62          function getCookie(name) {
63              var cookieValue = null;
64              if (document.cookie && document.cookie != '') {
65                  var cookies = document.cookie.split(';');
66                  for (var i = 0; i < cookies.length; i++) {
67                      var cookie = jQuery.trim(cookies[i]);
68                      // Does this cookie string begin with the name we want?
69                  if (cookie.substring(0, name.length + 1) == (name + '=')) {
70                      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
71                      break;
72                  }
73              }
74          }
75          return cookieValue;
76          }
77          if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
78              // Only send the token to relative URLs i.e. locally.
79              xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
80          }
81      } 
82 });