layout changes
[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("/table/resource/", {'columns' : ['hostname','country','type'], 'filters' : { 'country' : 'France' } }, function(data) {
39                 $(this).dataTable( {
40                         "sScrollY": window.innerHeight - 275,
41                         "sDom": "frtiS",
42                 "bScrollCollapse": true,
43                 "bStateSave": true,
44                 "bPaginate": false,
45                 "bLengthChange": false,
46                 "bFilter": false,
47                 "bSort": true,
48                 "bInfo": false,
49                 "bAutoWidth": true,
50                 "bAutoHeight": false
51                 } );
52         });
53 } );
54
55 function drawTable(data) {
56         
57 }
58
59 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
60 //make sure to expose csrf in our outcoming ajax/post requests
61 $.ajaxSetup({ 
62      beforeSend: function(xhr, settings) {
63          function getCookie(name) {
64              var cookieValue = null;
65              if (document.cookie && document.cookie != '') {
66                  var cookies = document.cookie.split(';');
67                  for (var i = 0; i < cookies.length; i++) {
68                      var cookie = jQuery.trim(cookies[i]);
69                      // Does this cookie string begin with the name we want?
70                  if (cookie.substring(0, name.length + 1) == (name + '=')) {
71                      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
72                      break;
73                  }
74              }
75          }
76          return cookieValue;
77          }
78          if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
79              // Only send the token to relative URLs i.e. locally.
80              xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
81          }
82      } 
83 });