Merging with OneLab latest
[unfold.git] / portal / static / js / onelab_slice-resource-view.js
1 $(document).ready(function() {
2     $('li#GoogleMap').click(function (e) {
3         $('.'+this.id).trigger('show');
4     });
5
6     $('a.sl-platform').click(function (e) {
7         $('.'+this.id).trigger('show');
8     });
9
10
11         $('ul.nav-resources a').click(function() {
12         $('ul.nav-resources li').removeClass('active');
13         $(this).parent().addClass('active');
14         $('div.panel').hide();
15         $('div#'+$(this).data('panel')).show();
16         /*
17         if ($(this).data('panel') == 'map') {
18                 mapInit();
19         }
20         */
21     });
22     $('div.list-resources a').click(function() {
23         $('div.list-resources a').removeClass('active');
24         $(this).addClass('active');
25         $('div.panel').hide();
26         $('div#'+$(this).data('panel')).show();
27        
28     });
29     
30     $.get("/rest/network", function(data) {
31                 var list = '<div class="list-group-item sl-platform"><span class="list-group-item-heading">Testbeds</span></div>';
32                 for(i=0; i<data.length;i++) {
33                         list += '<a href="#" class="list-group-item sl-platform" data-platform="'+data[i].network_hrn+'"><span class="list-group-item-heading">'+data[i].network_longname+'</span><p class="list-group-item-text">'+data[i].network_hrn+'</p></a>';
34                 }
35                 $('#select-platform').html(list);
36         }).done(function() {
37                 
38         });
39         
40         $('button#ApplyPendind').click(function() {
41                 myslice.apply();
42                 // $.each(myslice.pending, function(k, p) {
43                         // console.log(p);
44                 // });
45                 // $.post("/update/slice", {}, function() {
46 //                      
47                 // });
48         });
49         
50    //google.maps.event.addDomListener(window, 'load', initialize);
51 });
52
53 function mapInit() {
54         
55     $.get("/rest/resource/", {"fields" : ["hostname","latitude","longitude"] }, function(data) {
56         
57                 var mapOptions = {
58               center: new google.maps.LatLng(48.8567, 2.3508),
59               zoom: 4,
60               scrollwheel: false
61             };
62             var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
63                  marker = new google.maps.Marker({
64                         position: new google.maps.LatLng(48.8567, 2.3508),
65                         map: map,
66                         icon: '/static/img/marker2.png'
67                     });
68                 
69                 for (i = 0; i < data.length; i++) {  
70                         if (!data[i].longitude) continue;
71                     marker = new google.maps.Marker({
72                         position: new google.maps.LatLng(data[i].latitude, data[i].longitude),
73                         map: map
74                     });
75                         var infowindow = new google.maps.InfoWindow();
76
77                         google.maps.event.addListener(marker, 'click', (function(marker, i) {
78                         return function() {
79                           infowindow.setContent(data[i].hostname);
80                           infowindow.open(map, marker);
81                         };
82                 })(marker, i));
83             }
84           });
85 }