1 jQuery(document).ready(function() {
3 display_progeny(get_cross_id());
5 get_properties(get_cross_id(), display_properties);
7 function get_cross_id() {
8 var cross_id = jQuery('#cross_id').html();
11 cross_id = cross_id.replace(regex, "");
16 function get_cross_name() {
17 var cross_name = jQuery('#cross_name').html();
19 cross_name = cross_name.replace(regex, "");
23 function display_progeny(cross_id) {
27 url: '/cross/ajax/relationships/'+cross_id,
28 success: function(response) {
30 alert(response.error);
33 if (response.progeny) {
34 var html = '<table class="table borderless" alt="breeder search" border="0" ><tr><td><select multiple class="form-control" id="progeny_data" name="1" size="10" style="min-width: 200px;overflow:auto;"></select></td></tr>'
35 html += '<tr><td><button class="btn btn-default btn-sm" id="progeny_select_all" name="1">Select All</button><br><br>'
36 html += '<div class="well well-sm"><div id="progeny_data_count" name="1">No Selection</div></div>'
37 html += '<div id="progeny_to_list_menu"></div><td><tr></table>'
39 jQuery('#progeny_information_div').html(html);
41 var progeny = response.progeny.sort() || [];
43 progeny.forEach(function(accession_info_array) { // swap position of id and uniquename for each progeny array
44 accession_info_array.reverse();
47 progeny_html = format_options_list(progeny);
48 jQuery('#progeny_data').html(progeny_html);
50 var data = jQuery('#progeny_data').val() || [];;
51 show_list_counts('progeny_data_count', progeny.length, data.length);
53 if (jQuery('#progeny_data').length) {
54 addToListMenu('progeny_to_list_menu', 'progeny_data', {
56 listType: 'accessions'
60 jQuery('#progeny_select_all').click( function() { // select all progeny
61 var data_id = "progeny_data";
62 selectAllOptions(document.getElementById(data_id));
64 var data = jQuery("#"+data_id).val() || [];;
65 var count_id = "progeny_data_count";
66 show_list_counts(count_id, jQuery('#'+data_id).text().split("\n").length-1, data.length);
69 jQuery('#progeny_data').change( function() { // update count when data selections change
70 var data_id = jQuery(this).attr('id');
71 var data = jQuery('#'+data_id).val() || [];;
72 var count_id = "progeny_data_count";
73 show_list_counts(count_id, jQuery('#'+data_id).text().split("\n").length-1, data.length);
76 jQuery('select').dblclick( function() { // open progeny detail page in new window or tab on double-click
77 window.open("../../stock/"+this.value+"/view");
79 } // close if (response.progeny)
82 if (response.maternal_parent) {
83 parent_html = '<img src="/img/Venus_symbol.svg" width="20" /> <a href="/stock/'+response.maternal_parent[1] +'/view">'+response.maternal_parent[0]+'</a><br />';
85 if (response.paternal_parent) {
86 parent_html += '<img src="/img/Mars_symbol.svg" width="20" /> <a href="/stock/'+response.paternal_parent[1] +'/view">'+response.paternal_parent[0]+'</a><br />'; }
87 jQuery('#parents_information_div').html(parent_html);
90 error: function(response, a, b) {
91 jQuery('#progeny_information_div').html('An error occurred. '+a +' '+ b);
96 function display_parents(cross_id) {
99 url: '/cross/ajax/parents/'+cross_id,
100 success: function(response) {
101 if (response.error) {
102 alert(response.error);
105 var html = "<table>";
106 if (response.parents) {
107 for (var i=0; i<response.parents.length; i++) {
108 html += '<td><a href="/stock/'+response.parents[i][1]+'/view">'+response.parents[i][0]+'</a></td></tr>';
112 jQuery('#parents_information_div').html(html);
114 error: function(response, a, b) {
115 jQuery('#parents_information_div').html('An error occurred. '+a +' '+ b);
120 function display_properties(result) {
121 var props = result.props;
125 for (var k in props) {
126 html += '<tr><td>'+k+'</td><td> </td>';
128 for (var n=0; n<props[k].length; n++) {
129 html += '<td><b>'+props[k][n][0]+'</b></td><td> </td></tr>';
133 jQuery('#cross_properties_div').html(html);
140 jQuery('#add_more_progeny_link').click( function() {
141 jQuery('#add_more_progeny_dialog').dialog("open");
142 jQuery('#progeny_count').focus();
145 jQuery('#add_more_progeny_dialog').dialog( {
150 id: 'add_more_progeny_dialog_ok_button',
152 jQuery('#working').dialog("open");
153 add_more_progeny(get_cross_id(), get_cross_name(), jQuery('#basename').val(), jQuery('#start_number').val(), jQuery('#progeny_count').val());
159 id: 'add_more_progeny_dialog_cancel_button',
160 click: function() { jQuery('#add_more_progeny_dialog').dialog("close") },
163 title: 'Add more progeny'
166 function add_more_progeny(cross_id, cross_name, basename, start_number, progeny_count) {
169 url: '/cross/progeny/add/'+cross_id,
170 data: { 'cross_name': cross_name, 'basename': basename, 'start_number': start_number, 'progeny_count': progeny_count },
171 success: function(response) {
172 if (response.error) {
173 alert(response.error);
175 else { alert('Added '+progeny_count+' new progeny');
176 jQuery('#working').dialog("close");
177 display_progeny(get_cross_id());
178 jQuery('#add_more_progeny_dialog').dialog("close");
181 error: function(response, code, error) { alert('error: '+error); }
185 jQuery('#edit_properties_dialog').dialog( {
190 id: 'edit_properties_dialog_done_button',
191 click: function() { jQuery('#edit_properties_dialog').dialog("close") },
195 title: 'Edit cross properties'
198 jQuery('#edit_properties_link').click( function() {
199 jQuery('#edit_properties_dialog').dialog("open");
200 get_properties(get_cross_id(), draw_properties_dialog);
204 jQuery('#property_submit').click( function() {
206 jQuery('#working').dialog("open");
207 check_property(get_cross_id(), jQuery('#properties_select').val(), jQuery('#property_value').val());
208 jQuery('#working').dialog("close");
212 function draw_properties_dialog(response) {
213 var type = jQuery('#properties_select').val();
214 var prop = response.props[type];
215 if (prop instanceof Array) {
216 for (var n=0; n<prop.length; n++) {
217 jQuery('#property_value').val(prop[n][0]);
221 jQuery('#property_value').val('');
225 jQuery('#properties_select').change( function() {
226 var value = jQuery('#properties_select').val();
227 get_properties(get_cross_id(), draw_properties_dialog);
230 function set_properties_select(type) {
231 jQuery('#properties_select').val(type);
234 function set_property_value(value) {
235 jQuery('#property_value').val(value);
238 function get_properties(cross_id, callback) {
240 return jQuery.ajax( {
242 url: '/cross/ajax/properties/'+cross_id,
244 error : error_callback
248 function error_callback(a, b, c) {
249 alert("an error occurred "+c);
252 function check_property(cross_id, type, value) {
253 return jQuery.ajax( {
254 url: '/cross/property/check/'+cross_id,
255 data: { 'cross_id' : cross_id, 'type': type, 'value': value },
256 }).done( function(response) {
257 if (response.error) { alert(response.error); }
259 if (response.message) {
260 yes = confirm(response.message + " Continue? ");
263 save_property(cross_id, type, value);
266 alert("Not saving.");
269 if (response.success) {
270 save_property(cross_id, type, value);
272 }).fail( function() {
273 alert("The request for checking the parameters failed. Please try again.");
277 function save_property(cross_id, type, value) {
278 return jQuery.ajax( {
279 url: '/cross/property/save/'+cross_id,
280 data: { 'cross_id' : cross_id, 'type': type, 'value': value }
282 }).done( function(response) {
283 get_properties(get_cross_id(), display_properties);
284 save_confirm(response);
287 }).fail( function(response, x, y) {
288 alert("An error occurred saving the property. "+y);
292 function save_confirm(response) {
293 if (response.error) {
294 alert(response.error);
298 alert("The property was successfully saved.");