refactor phenotypes brapi calls
[sgn.git] / mason / breeders_toolbox / genotyping_trials / layout.mas
blobfccdca6c1cfd6c7b1121f95d2731699e0e1d31f9
3 <%args>
4 $trial_id
5 $genotyping_plate_format => '96'
6 </%args>
8 <& /util/import_javascript.mas, classes => [  ] &>
11 <div id="trial_plate_layout_html">
12 <div class="well">
13 [LOADING...]
14 </div>
15 </div>
17 <script>
19 jQuery(document).ready(function () {
21     jQuery.ajax ({
22         url : '/ajax/breeders/trial/'+<% $trial_id %>+'/design',
23         beforeSend: function() {
24             jQuery("#working_modal").modal("show");
25         },
26         success: function(response){
27             //console.log(response);
28             jQuery("#working_modal").modal("hide");
29             var trial_plate_layout_html = "<table class='table table-hover table-condensed table-bordered' id='trial_plate_layout_table'><thead><tr><th>Well</th><th>Accession Name</th></tr></thead><tbody>";
31             var col_max = 1;
32             if (<% $genotyping_plate_format %> == '96'){
33                 col_max = 13;
34             }
35             if (<% $genotyping_plate_format %> == '384'){
36                 col_max = 25;
37             }
39             var rows;
40             if (<% $genotyping_plate_format %> == '96'){
41                 rows = "ABCDEFGH".split("");
42             }
43             if (<% $genotyping_plate_format %> == '384'){
44                 rows = "ABCDEFGHIJKLMNOP".split("");
45             }
47             jQuery.each(rows, function(row) {
48                 for (col=1; col<col_max; col++) {
49                     var formatted_col = (col < 10 ? '0' : '') + col;
50                     var well = rows[row] + formatted_col;
51                     if (response.design[well]) {
52                         if (response.design[well].accession_name) {
53                             var accession_name = response.design[well].accession_name;
54                             trial_plate_layout_html = trial_plate_layout_html + "<tr><td>" + well + "</td><td>" + accession_name + "</td></tr>";
55                         }
56                     }
57                 }
58             });
60             trial_plate_layout_html = trial_plate_layout_html + "</tbody></table>";
61             jQuery('#trial_plate_layout_html').empty();
62             jQuery('#trial_plate_layout_html').html(trial_plate_layout_html);
63             jQuery('#trial_plate_layout_table').DataTable();
64         },
65         error: function(response){
66             jQuery("#working_modal").modal("hide");
67             alert("Error retrieving plate layout.");
68         }
69     });
71 });
73 </script>