Merge pull request #2754 from solgenomics/topic/fix_homepage_add_accessions_dialog
[sgn.git] / mason / breeders_toolbox / location_table.mas
blob781d4c611494a2ca59446d681efbb77554ead8da
2 <%args>
3 $user_id => undef
4 </%args>
6 <& /util/import_javascript.mas, classes => ['jquery.dataTables-buttons-min', 'jquery.iframe-post-form', 'jszip-min','buttons.bootstrap-min', 'buttons.html5-min', 'buttons.print-min'] &>
7 <br>
8 <div class="table-responsive" style="margin-top: 10px;">
9     <table id="location_table" class="table table-hover table-striped table-bordered" width="100%">
10         <thead>
11             <tr>
12                 <th>Id</th>
13                 <th>Name</th>
14                 <th>Abbreviation</th>
15                 <th>Country</th>
16                 <th>Program</th>
17                 <th>Type</th>
18                 <th>Altitude(m)</th>
19                 <th>Trials</th>
21             </tr>
22         </thead>
23         <!-- <caption class="well well-sm" style="caption-side: bottom;margin-top: 10px;"><center> Locations </center></caption> -->
24     </table>
25 </div>
26 <br>
28 <& /breeders_toolbox/upload_locations_dialogs.mas &>
30 <script defer="defer">
32 jQuery(document).ready(function() {
34     jQuery.ajax( {
35         url: '/ajax/location/all',
36         beforeSend: function() {
37             // put working animation handling here
38         },
39         success: function(response) {
40             var export_message = window.location.href + ' location data.';
41             locationJSON = JSON.parse(response.data);
42             //console.log("Data is "+JSON.stringify(locationJSON, null, 2));
44             var table = jQuery('#location_table').DataTable( {
45                 data: locationJSON,
46                 dom: 'Bfrtip',
47                 select: true,
48                 rowId: 'properties.Id',
49                 "columns": [
50                     { "data": "properties.Id" },
51                     { "data": "properties.Name" },
52                     { "data": "properties.Abbreviation" },
53                     { "data": "properties.Code",
54                         "render":function(data, type, full, meta){
55                            return full.properties.Code + ' ' + full.properties.Country;
56                         }
57                     },
58                     { "data": "properties.Program" },
59                     { "data": "properties.Type" },
60                     { "data": "properties.Altitude" },
61                     { "data": "properties.Trials" },
62                 ],
63                 buttons: [ 'copy','print'],
64                 drawCallback: function( settings ) {
65                    var api = this.api();
66                    var name_data = api.column(1, { search:'applied' } ).data();
67                    var names = [];
68                    for (var i = 0; i < name_data.length; i++) { //extract names from data object
69                        names.push(name_data[i]+'\n');
70                    }
71                    //console.log("Names are: "+JSON.stringify(names));
72                    $('#location_names').html(names);
73                    addToListMenu('locations_to_list_menu', 'location_names', {
74                      listType: 'locations'
75                    });
76                 }
77             });
79             var map = initialize_map('location_map', locationJSON, table);
81         },
82         error: function(response) {
83             alert("An error occurred");
84         }
85     });
87  });
88 </script>