1 <& /util/import_javascript.mas, classes => ['jquery','d3.d3v4Min'] &>
2 <form id="available-seedlots">
3 <table class="table table-hover table-bordered">
6 <th rowspan="2" style="text-align: center;">Accessions</th><th colspan="7" style="text-align: center;">Seedlots</th>
10 <th style="text-align: center;">Breeding Program</th>
11 <th style="text-align: center;">Seedlot Name</th>
12 <th style="text-align: center;">Contents</th>
13 <th style="text-align: center;">Seedlot Location</th>
14 <th style="text-align: center;">Count</th>
15 <th style="text-align: center;">Weight(g)</th>
20 <script type="text/javascript">
22 var mainFormSelector = "#available-seedlots";
25 ex.build_table = function(accession_names, list_type){
26 jQuery('#working_modal').modal('show');
29 url: '/ajax/accessions/possible_seedlots',
30 data: {'names': accession_names, 'type': list_type},
32 success: function(response) {
33 _build_table(accession_names,response.seedlots,response.synonyms);
34 jQuery('#working_modal').modal('hide');
36 error: function(response) {
37 jQuery('#working_modal').modal('hide');
38 console.log(response);
39 alert("Something went wrong in the available-seedlots AJAX call. See console for more information.")
43 ex.get_selected = function(){
44 return jQuery(mainFormSelector).serializeArray();
46 var empty_placeholder = new Object();
47 function _build_table(accession_list,seedlot_obj,synonyms){
48 console.log(seedlot_obj);
50 for (var acc_uname in seedlot_obj) {
51 if (seedlot_obj.hasOwnProperty(acc_uname)) {
53 if (accession_list.indexOf(acc_uname)>-1){
56 for (var i = 0; i < synonyms[acc_uname].length; i++) {
57 if (accession_list.indexOf(synonyms[acc_uname][i])>-1){
58 name = synonyms[acc_uname][i];
63 synonymized[name] = seedlot_obj[acc_uname];
66 var row_data = accession_list.map(function(acc){
67 return {'name':acc,'seedlots':synonymized[acc]?synonymized[acc]:[]};
69 var table = d3.select(mainFormSelector).select("table");
70 var groups = table.selectAll("tbody").data(row_data,function(d){return d.name;});
71 groups.exit().remove();
72 var newGroups = groups.enter().append("tbody");
73 var newInitRows = newGroups.append("tr");
74 newInitRows.append("th").classed("as-acc-name",true)
75 .style("text-align","center")
76 .style("vertical-align","middle");
77 var allGroups = newGroups.merge(groups);
78 allGroups.style("border-top","2px solid #999")
79 allGroups.select(".as-acc-name")
80 .attr("rowspan",function(d){return Math.max(1,d.seedlots.length);})
81 .text(function(d){return d.name;});
82 var optionRows = allGroups.selectAll("tr")
84 return d.seedlots.length>0 ? d.seedlots : [empty_placeholder];
86 optionRows.exit().remove();
87 newOptionRows = optionRows.enter().append("tr");
88 allOptionRows = newOptionRows.merge(optionRows);
89 var optionRowCells = allOptionRows.selectAll("td").data(function(d){
90 if (d==empty_placeholder){
91 return ['<input disabled type="checkbox">'," ","No Available Seedlots"," "," "," "," "]
94 cells.push('<input value="'+d.seedlot[0]+'" name="'+d.seedlot[0]+'" type="checkbox">');
95 cells.push(d.program);
96 cells.push('<a href="/breeders/seedlot/'+d.seedlot[1]+'">'+d.seedlot[0]+'</a>');
97 cells.push('<a href="/stock/'+d.contents[1]+'/view">'+d.contents[0]+'</a>');
98 cells.push(d.location);
100 cells.push(d.weight_gram);
103 var newOptionRowCells = optionRowCells.enter().append("td");
104 optionRowCells.exit().remove();
105 var allOptionRowCells = newOptionRowCells.merge(optionRowCells);
106 allOptionRowCells.html(function(d){return d;});
107 allOptionRows.select("td") //select the checkbox cells
108 .style("text-align","center")
109 .style("vertical-align","middle");
111 global.available_seedlots = ex;