3 @media (min-width: 768px) {
11 <div class="modal fade" id="create_cross_wishlist_dialog" name="create_cross_wishlist_dialog" tabindex="-1" role="dialog" aria-labelledby="createCrossWishlistDialog">
12 <div class="modal-dialog modal-xl" role="document">
13 <div class="modal-content">
14 <div class="modal-header">
15 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
16 <h4 class="modal-title" id="createCrossWishlistDialog">Create Cross Wishlist</h4>
19 <div class="modal-body">
20 <div class="container-fluid">
22 <form class="form-horizontal" id="cross_wishlist_create_select_form_id" name="cross_wishlist_create_select_form_id">
23 <div class="form-group">
24 <label class="col-sm-4 control-label">Select An ODK Form on ONA: </label>
25 <div class="col-sm-8" >
26 <div id="cross_wishlist_create_select_form_id_div">LOADING...</div>
32 <ul class="nav nav-pills nav-justified" id="cross_wishlist_tab_select">
33 <li id="cross_wishlist_list_tab"><a data-toggle="tab" href="#with_lists">Using Accession Lists</a></li>
34 <li class="active" id="cross_wishlist_no_list_tab"><a data-toggle="tab" href="#not_with_lists">Using Crossing Blocks</a></li>
35 <li id="cross_wishlist_upload_tab"><a data-toggle="tab" href="#upload_wishlist">Uploading Cross Combinations</a></li>
38 <div class="tab-content">
40 <div id="with_lists" class="tab-pane fade">
42 <form class="form-horizontal" >
43 <div class="form-group" style="display:none" <!-- location name is coming from the trial they select --> >
44 <label class="col-sm-3 control-label">Location Name (Optional): </label>
45 <div class="col-sm-9" >
46 <div id="cross_wishlist_location_select_list_div">
50 <div class="form-group">
51 <label class="col-sm-3 control-label">Female's Trial Name: </label>
52 <div class="col-sm-9" >
53 <div id="cross_wishlist_female_trial_select_list_div">
57 <div class="form-group">
58 <label class="col-sm-3 control-label">Male's Trial Name: </label>
59 <div class="col-sm-9" >
60 <div id="cross_wishlist_male_trial_select_list_div">
64 <div class="well well-sm">
65 <div class="form-group">
66 <label class="col-sm-6 control-label">Cross plan will be added to the cross wishlist named: </label>
67 <div class="col-sm-6" >
68 <div id="cross_wishlist_trial_select_list_cross_wishlist_name_div">
69 <input class="form-control" type="text" disabled value="Please Select a Trial First" />
74 <div class="form-group">
75 <label class="col-sm-3 control-label">Female Accession List: </label>
76 <div class="col-sm-9" id="female_accession_list_div" name="female_accession_list_div">
79 <div class="form-group">
80 <label class="col-sm-3 control-label">Male Accession List: </label>
81 <div class="col-sm-9" id="male_accession_list_div" name="male_accession_list_div">
86 <div id="cross_wishlist_cross_grid_div"></div>
89 <div id="not_with_lists" class="tab-pane fade in active">
92 <form class="form-horizontal" >
93 <div class="form-group">
94 <label class="col-sm-3 control-label">Female's Trial Name: </label>
95 <div class="col-sm-9" >
96 <div id="cross_wishlist_female_trial_select_no_list_div">
100 <div class="form-group">
101 <label class="col-sm-3 control-label">Male's Trial Name: </label>
102 <div class="col-sm-9" >
103 <div id="cross_wishlist_male_trial_select_no_list_div">
107 <div class="well well-sm">
108 <div class="form-group">
109 <label class="col-sm-6 control-label">Cross plan will be added to the cross wishlist named: </label>
110 <div class="col-sm-6" >
111 <div id="cross_wishlist_trial_select_no_list_cross_wishlist_name_div">
112 <input class="form-control" type="text" disabled value="Please Select a Trial First" />
117 <div class="form-group">
118 <label class="col-sm-3 control-label">Female Accession Name(s):</label>
119 <div class="col-sm-9" >
120 <div id="cross_wishlist_female_accession_select_div">
121 <p>First Select A Trial</p>
125 <div id ="cross_wishlist_male_parent_div">
130 <div id="upload_wishlist" class="tab-pane fade">
132 <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_wishlist_form" name="upload_wishlist_form">
134 <div class="form-group">
135 <label class="col-sm-3 control-label">Female's Trial Name: </label>
136 <div class="col-sm-9" >
137 <div id="cross_wishlist_female_trial_select_upload_div">
141 <div class="form-group">
142 <label class="col-sm-3 control-label">Male's Trial Name: </label>
143 <div class="col-sm-9" >
144 <div id="cross_wishlist_male_trial_select_upload_div">
148 <div class="well well-sm">
149 <div class="form-group">
150 <label class="col-sm-6 control-label">Cross plan will be added to the cross wishlist named: </label>
151 <div class="col-sm-6" >
152 <div id="cross_wishlist_trial_select_upload_cross_wishlist_name_div">
153 <input class="form-control" type="text" disabled value="Please Select a Trial First" />
158 <div class="well well-sm">
160 <div class="col-sm-4">
161 <&| /page/explanation.mas, title=>'Template information' &>
163 <b>File format information</b>
165 <a id="wishlist_format">Spreadsheet format</a>
169 <div class="col-sm-8">
171 <div class="panel panel-default">
172 <div class="panel-body">
173 <div class="form-group">
174 <label class="col-sm-6 control-label">Select an XLS File: </label>
175 <div class="col-sm-6">
176 <input type="file" name="wishlist_file" id="wishlist_file" encoding="multipart/form-data" />
190 <div id="wishlist_lists_footer">
191 <div class="modal-footer">
192 <button class="btn btn-info" id="show_cross_wishlists_select_submits" name="show_cross_wishlists_select_submits">Available Cross Wishlist(s) for ODK Use</button>
193 <button class="btn btn-primary" id="cross_wishlist_submit" name="cross_wishlist_submits">Next</button>
194 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
197 <div id="wishlist_upload_footer" style="display:none">
198 <div class="modal-footer">
199 <button class="btn btn-info" id="upload_show_cross_wishlists_select_submits" name="upload_show_cross_wishlists_select_submits">Available Cross Wishlist(s) for ODK Use</button>
200 <button class="btn btn-primary" id="wishlist_upload_submit" name="wishlist_upload_submit">Upload File</button>
201 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
208 <div class="modal fade" id="create_cross_wishlist_select_dialog" name="create_cross_wishlist_select_dialog" tabindex="-1" role="dialog" aria-labelledby="createCrossWishlistSelectDialog">
209 <div class="modal-dialog modal-xl" role="document">
210 <div class="modal-content">
211 <div class="modal-header">
212 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
213 <h4 class="modal-title" id="createCrossWishlistSelectDialog">Select Plots for Cross Wishlist</h4>
214 <h4>Female Plots are in <span class="bg-primary">Blue</span><!-- and Male Plots are in <span class="bg-success">Green</span>.--></h4>
217 <div class="modal-body">
218 <div class="container-fluid">
219 <div id="cross_wishlist_cross_select_div"></div>
223 <div class="modal-footer">
224 <button class="btn btn-primary" id="cross_wishlist_select_submits" name="cross_wishlist_select_submits">Create Wishlist</button>
225 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
231 <div class="modal fade" id="create_cross_wishlist_response_dialog" name="create_cross_wishlist_response_dialog" tabindex="-1" role="dialog" aria-labelledby="createCrossWishlistResponseDialog">
232 <div class="modal-dialog modal-xl" role="document">
233 <div class="modal-content">
234 <div class="modal-header">
235 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
236 <h4 class="modal-title" id="createCrossWishlistResponseDialog">Cross Wishlist</h4>
239 <div class="modal-body">
240 <div class="container-fluid">
241 <div id="cross_wishlist_response_div"></div>
245 <div class="modal-footer">
246 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
252 <div class="modal fade" id="show_cross_wishlists_response_dialog" name="show_cross_wishlists_response_dialog" tabindex="-1" role="dialog" aria-labelledby="showCrossWishlistsResponseDialog">
253 <div class="modal-dialog modal-xl" role="document">
254 <div class="modal-content">
255 <div class="modal-header">
256 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
257 <h4 class="modal-title" id="showCrossWishlistsResponseDialog">Cross Wishlists Previously Created</h4>
260 <div class="modal-body">
261 <div class="container-fluid">
262 <div id="show_cross_wishlists_response_div"></div>
266 <div class="modal-footer">
267 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
273 <div class="modal fade" id="upload_wishlist_error_display" name="upload_wishlist_error_display" tabindex="-1" role="dialog" aria-labelledby="uploadWishlistErrorDialog">
274 <div class="modal-dialog modal-lg" role="document">
275 <div class="modal-content">
276 <div class="modal-header">
277 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
278 <h4 class="modal-title" id="uploadWishlistErrorDialog">Upload Wishlist File Error</h4>
280 <div class="modal-body">
281 <div class="container-fluid">
287 <div class="modal-footer">
288 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
294 <div class="modal fade" id="upload_wishlist_spreadsheet_info_dialog" name="upload_wishlist_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadWishlistInfoDialog">
295 <div class="modal-dialog modal-lg" role="document">
296 <div class="modal-content">
297 <div class="modal-header">
298 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
299 <h4 class="modal-title" id="uploadWishlistInfoDialog">Template Information</h4>
301 <div class="modal-body">
302 <div class="container-fluid">
304 Cross wishlist may be uploaded in an Excel file (.xls or .xlsx)
311 The first row (header) must contain the following:
314 <table class="table table-bordered table-hover">
317 <td>female_accession</td>
318 <td>male_accession</td>
327 <li><b>female_accession</b> (accession names must exist as <b>uniquenames</b> in the database and are in the selected female trial. Wishlist will include all of the female plots in the trial.)</li>
328 <li><b>male_accession</b> (accession names must exist as <b>uniquenames</b> in the database)</li>
329 <li><b>priority</b> (1 is the most important) </li>
333 <div class="modal-footer">
334 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
343 var lo = new CXGN.List();
345 function draw_cross_grid(female_accessions, male_accessions){
346 console.log("draw cross grid");
347 var cross_grid_html = '<h3>Set Cross Priorities: 1 is highest and 60 is lowest</h3><h4>Female Accessions Are in First Column and Male Accessions Are in Header</h4><table class="table table-bordered"><thead><tr><th>Female Accessions</th>';
348 for(var i=0; i<male_accessions.length; i++){
349 cross_grid_html = cross_grid_html + '<th>' + male_accessions[i] + '</th>';
351 cross_grid_html = cross_grid_html + '</tr></thead><tbody>';
352 for(var i=0; i<female_accessions.length; i++){
353 cross_grid_html = cross_grid_html + '<tr><td>' + female_accessions[i] + '</td>';
354 for(var j=0; j<male_accessions.length; j++){
355 cross_grid_html = cross_grid_html + '<td><input type="text" name="cross_wishlist_cross_grid_inputs" class="form-control" data-female="'+female_accessions[i]+'" data-male="'+male_accessions[j]+'"/></td>';
357 cross_grid_html = cross_grid_html + '</tr>';
359 cross_grid_html = cross_grid_html + '</tbody></table>';
360 jQuery('#cross_wishlist_cross_grid_div').html(cross_grid_html);
363 jQuery(document).ready(function($) {
365 jQuery('#show_cross_wishlists_select_submits').click(function(){
366 jQuery('#show_cross_wishlists_response_dialog').modal('show');
369 url: '/ajax/cross/list_cross_wishlists',
371 beforeSend: function() {
372 jQuery('#working_modal').modal('show');
374 success: function(response) {
375 //console.log(response);
376 jQuery('#working_modal').modal('hide');
378 if(response.success){
379 html += "<table class='table table-bordered table-hover'><thead><tr><th>File</th><th>Updated By</th><th>Date</th></tr></thead><tbody>";
380 for(var i=0; i<response.files.length; i++){
381 html += "<tr><td><a href='/breeders/phenotyping/download/"+response.files[i][0]+"' >"+response.files[i][1]+"</a></td><td><a href='/solpeople/personal-info.pl?sp_person_id="+response.files[i][6]+"' >"+response.files[i][7]+" "+response.files[i][8]+"</a></td><td>"+response.files[i][5]+"</td></tr>";
383 html += "</tbody></table>";
385 html = 'Something went wrong here.'
387 jQuery('#show_cross_wishlists_response_div').html(html);
389 error: function(response) {
390 jQuery('#working_modal').modal('hide');
391 alert("An error occurred getting cross wishlists");
397 jQuery("#create_cross_wishlist").click(function() {
398 jQuery("#create_cross_wishlist_dialog").modal("show");
399 jQuery("#female_accession_list_div").html(lo.listSelect('female_accession_list_div', ["accessions"], "Please select list with < 60 accessions", undefined, undefined ));
400 jQuery("#male_accession_list_div").html(lo.listSelect('male_accession_list_div', ["accessions"], "Please select list with < 60 accessions", undefined, undefined ));
401 var female_accessions;
403 if (jQuery('#female_accession_list_div_list_select').val() != '' && jQuery('#male_accession_list_div_list_select').val() != '' ) {
404 female_accessions = lo.getList(jQuery('#female_accession_list_div_list_select').val());
405 male_accessions = lo.getList(jQuery('#male_accession_list_div_list_select').val());
408 url : '/ajax/odk/get_crossing_available_forms',
409 beforeSend: function() {
410 jQuery("#working_modal").modal("show");
412 success: function(response){
413 console.log(response);
414 jQuery("#working_modal").modal("hide");
417 alert(response.error);
419 if (response.success){
423 url : '/ajax/odk/get_crossing_saved_ona_forms',
424 success: function(response_forms){
425 console.log(response_forms);
427 if (response_forms.error){
428 alert(response.error);
430 if (response_forms.success){
432 var form_dropdown_select_html = '<select class="form-control" id="cross_wishlist_availabe_odk_crossing_forms"><option value="">Not Using ONA</option>';
433 var allowed_forms = response_forms.odk_ona_forms;
434 allowed_forms.push('<% $c->config->{odk_crossing_data_test_form_name} %>');
435 for(var i=0; i<response.forms.length; i++){
436 if (jQuery.inArray(response.forms[i].id_string, allowed_forms) != -1){
437 form_dropdown_select_html = form_dropdown_select_html + '<option value="'+response.forms[i].id+'">'+response.forms[i].id_string+'</option>';
440 form_dropdown_select_html = form_dropdown_select_html + '</select>';
441 jQuery('#cross_wishlist_create_select_form_id_div').html(form_dropdown_select_html);
445 error: function(response_forms){
446 alert("Error retrieving saved ODK ONA forms");
452 error: function(response){
453 jQuery("#working_modal").modal("hide");
454 alert("Error retrieving available ODK crossing forms");
458 if (jQuery('#female_accession_list_div_list_select').val() != '' && jQuery('#male_accession_list_div_list_select').val() != '' ) {
459 draw_cross_grid(female_accessions, male_accessions);
463 // jQuery(document).on('change', '#female_accession_list_div_list_select', function(){
464 // if (jQuery('#female_accession_list_div_list_select').val() != '' && jQuery('#male_accession_list_div_list_select').val() != '' ) {
465 // var female_accessions = lo.getList(jQuery('#female_accession_list_div_list_select').val());
466 // var male_accessions = lo.getList(jQuery('#male_accession_list_div_list_select').val());
467 // draw_cross_grid(female_accessions, male_accessions);
471 jQuery(document).on('change', '#male_accession_list_div_list_select', function(){
472 if (jQuery('#female_accession_list_div_list_select').val() != '' && jQuery('#male_accession_list_div_list_select').val() != '' ) {
473 var female_accessions = lo.getList(jQuery('#female_accession_list_div_list_select').val());
474 var male_accessions = lo.getList(jQuery('#male_accession_list_div_list_select').val());
475 var female_accession_list_id = $('#female_accession_list_div_list_select').val();
476 var male_accession_list_id = $('#male_accession_list_div_list_select').val();
477 var female_trial_id = jQuery('#cross_wishlist_list_female_trial_id').val();
478 if (! lo.legacy_validate(female_accession_list_id, 'accessions', true)) {
479 alert('The female accession list contains elements that are not accessions.');
482 if (! lo.legacy_validate(male_accession_list_id, 'accessions', true)) {
483 alert('The male accession list contains elements that are not accessions.');
487 check_trial_accessions(female_trial_id, female_accession_list_id, female_accessions, male_accessions);
491 get_select_box('locations', 'cross_wishlist_location_select_list_div', { 'name' : 'cross_wishlist_location_id', 'id' : 'cross_wishlist_location_id', 'empty':1 });
492 get_select_box('trials', 'cross_wishlist_female_trial_select_no_list_div', { 'name' : 'cross_wishlist_female_trial_id', 'id' : 'cross_wishlist_female_trial_id', 'empty':1, 'multiple':0 });
493 get_select_box('trials', 'cross_wishlist_male_trial_select_no_list_div', { 'name' : 'cross_wishlist_male_trial_id', 'id' : 'cross_wishlist_male_trial_id', 'empty':1, 'multiple':0 });
495 get_select_box('trials', 'cross_wishlist_female_trial_select_list_div', { 'name' : 'cross_wishlist_list_female_trial_id', 'id' : 'cross_wishlist_list_female_trial_id', 'empty':1, 'multiple':0 });
496 get_select_box('trials', 'cross_wishlist_male_trial_select_list_div', { 'name' : 'cross_wishlist_list_male_trial_id', 'id' : 'cross_wishlist_list_male_trial_id', 'empty':1, 'multiple':0 });
498 get_select_box('trials', 'cross_wishlist_female_trial_select_upload_div', { 'name' : 'cross_wishlist_upload_female_trial_id', 'id' : 'cross_wishlist_upload_female_trial_id', 'empty':1, 'multiple':0 });
499 get_select_box('trials', 'cross_wishlist_male_trial_select_upload_div', { 'name' : 'cross_wishlist_upload_male_trial_id', 'id' : 'cross_wishlist_upload_male_trial_id', 'empty':1, 'multiple':0 });
501 jQuery(document).on('change', "#cross_wishlist_list_female_trial_id", function() {
502 cross_wishlist_change_trials_lists();
505 jQuery(document).on('change', "#cross_wishlist_female_trial_id", function() {
506 cross_wishlist_change_trials();
509 jQuery(document).on('change', "#cross_wishlist_upload_female_trial_id", function() {
510 cross_wishlist_change_trials_upload();
516 var female_male_tracker = {};
517 var selected_plot_ids = [];
518 jQuery('.nav-pills a').on('shown.bs.tab', function(event){
520 female_male_tracker = {};
521 selected_plot_ids = [];
526 var female_trial_ids_array = [];
527 var male_trial_ids_array = [];
528 function cross_wishlist_change_trials () {
529 var female_trial_ids = jQuery('#cross_wishlist_female_trial_id').val();
530 var female_trial_ids_string = '';
531 if ( jQuery.isArray(female_trial_ids) ) {
532 female_trial_ids_array = female_trial_ids;
533 trial_ids_string = female_trial_ids.join();
535 female_trial_ids_array = [female_trial_ids];
536 female_trial_ids_string = female_trial_ids;
540 url: '/ajax/breeders/trial/'+female_trial_ids_array[0]+'/location',
541 success: function(response) {
542 //console.log(response);
543 var cross_wishlist_name;
544 if ('<% $c->config->{odk_crossing_data_test_form_name} %>' == jQuery("#cross_wishlist_availabe_odk_crossing_forms option:selected").text()){
545 cross_wishlist_name = 'cross_wishlist_test.csv';
546 } else if ('<% $c->config->{odk_crossing_data_separate_wishlist_by_location} %>' == '1') {
547 cross_wishlist_name = 'cross_wishlist_'+response.location[1]+'.csv'
549 cross_wishlist_name = 'cross_wishlist_<% $c->config->{project_name} %>.csv';
551 jQuery('#cross_wishlist_trial_select_no_list_cross_wishlist_name_div').html('<input type="text" class="form-control" disabled value="'+cross_wishlist_name+'" />');
553 error: function(response) {
554 alert("An error occurred getting trial location");
558 get_select_box('stocks', 'cross_wishlist_female_accession_select_div', { 'name' : 'cross_wishlist_female_accession_ids', 'id' : 'cross_wishlist_female_accession_ids', 'size' : 7, 'stock_type_name':'accession', 'trial_id_list':female_trial_ids_array, 'names_as_select':1 });
561 function cross_wishlist_change_trials_lists () {
562 var female_trial_ids = jQuery('#cross_wishlist_list_female_trial_id').val();
563 var female_trial_ids_string = '';
564 if ( jQuery.isArray(female_trial_ids) ) {
565 female_trial_ids_array = female_trial_ids;
566 female_trial_ids_string = female_trial_ids.join();
568 female_trial_ids_array = [female_trial_ids];
569 female_trial_ids_string = female_trial_ids;
573 url: '/ajax/breeders/trial/'+female_trial_ids_array[0]+'/location',
574 success: function(response) {
575 //console.log(response);
576 var cross_wishlist_name;
577 if ('<% $c->config->{odk_crossing_data_test_form_name} %>' == jQuery("#cross_wishlist_availabe_odk_crossing_forms option:selected").text()){
578 cross_wishlist_name = 'cross_wishlist_test.csv';
579 } else if ('<% $c->config->{odk_crossing_data_separate_wishlist_by_location} %>' == '1') {
580 cross_wishlist_name = 'cross_wishlist_'+response.location[1]+'.csv'
582 cross_wishlist_name = 'cross_wishlist_<% $c->config->{project_name} %>.csv';
584 jQuery('#cross_wishlist_trial_select_list_cross_wishlist_name_div').html('<input type="text" class="form-control" disabled value="'+cross_wishlist_name+'" />');
586 error: function(response) {
587 alert("An error occurred getting trial location");
592 function cross_wishlist_change_trials_upload () {
593 var female_trial_ids = jQuery('#cross_wishlist_upload_female_trial_id').val();
594 var female_trial_ids_string = '';
595 if ( jQuery.isArray(female_trial_ids) ) {
596 female_trial_ids_array = female_trial_ids;
597 female_trial_ids_string = female_trial_ids.join();
599 female_trial_ids_array = [female_trial_ids];
600 female_trial_ids_string = female_trial_ids;
604 url: '/ajax/breeders/trial/'+female_trial_ids_array[0]+'/location',
605 success: function(response) {
606 //console.log(response);
607 var cross_wishlist_name;
608 if ('<% $c->config->{odk_crossing_data_test_form_name} %>' == jQuery("#cross_wishlist_availabe_odk_crossing_forms option:selected").text()){
609 cross_wishlist_name = 'cross_wishlist_test.csv';
610 } else if ('<% $c->config->{odk_crossing_data_separate_wishlist_by_location} %>' == '1') {
611 cross_wishlist_name = 'cross_wishlist_'+response.location[1]+'.csv'
613 cross_wishlist_name = 'cross_wishlist_<% $c->config->{project_name} %>.csv';
615 jQuery('#cross_wishlist_trial_select_upload_cross_wishlist_name_div').html('<input type="text" class="form-control" disabled value="'+cross_wishlist_name+'" />');
617 error: function(response) {
618 alert("An error occurred getting trial location");
623 jQuery(document).on('change', "#cross_wishlist_female_accession_ids", function() {
624 cross_wishlist_select_females();
627 function cross_wishlist_select_females () {
629 var male_trial_ids = jQuery('#cross_wishlist_male_trial_id').val();
630 var male_trial_ids_string = '';
631 if ( jQuery.isArray(male_trial_ids) ) {
632 male_trial_ids_array = male_trial_ids;
633 male_trial_ids_string = male_trial_ids.join();
635 male_trial_ids_array = [male_trial_ids];
636 male_trial_ids_string = male_trial_ids;
638 if (male_trial_ids.length == 0){
639 alert('Please select a male trial first!');
643 var female_accession_ids = jQuery('#cross_wishlist_female_accession_ids').val();
644 var html = '<table class="table table-bordered" id="cross_wishlist_male_select_table"><thead><tr><th>Female Parent</th><th>Select Male Parent</th><th>Priority ( 1 : highest, 60 : lowest )</th></tr></thead><tbody>';
645 for(var i=0; i<female_accession_ids.length; i++){
646 html = html + '<tr><td>' + female_accession_ids[i] + '</td><td><div name="cross_wishlist_male_selects" id="cross_wishlist_male_select_' +i+ '"></div></td><td><span id="cross_wishlist_male_accession_id_'+ i +'_priority" data-related="'+encodeURI(female_accession_ids[i])+'" >Select Male(s)</span></td></tr>';
648 html = html + '</tbody></table>';
649 jQuery('#cross_wishlist_male_parent_div').html(html);
651 var cross_wishlist_male_parents = jQuery('#cross_wishlist_male_select_table')
653 .map(function() { return this.id; })
655 //console.log(cross_wishlist_male_parents);
656 for(var i=0; i<cross_wishlist_male_parents.length; i++){
657 var female_id = jQuery('#cross_wishlist_male_accession_id_'+ i +'_priority').data('related');
658 get_select_box('stocks', cross_wishlist_male_parents[i], { 'name' : 'cross_wishlist_male_accession_id_select', 'id' : 'cross_wishlist_male_accession_id_'+i, 'size' : 7, 'stock_type_name':'accession', 'trial_id_list':male_trial_ids_array, 'names_as_select':1, 'data-related':female_id });
662 jQuery(document).on('change', "select[name='cross_wishlist_male_accession_id_select']", function() {
663 var div_id = '#' + this.id;
664 var male_ids = jQuery(div_id).val();
665 if (male_ids.length > 0){
666 cross_wishlist_change_males(div_id, div_id + '_priority');
670 function cross_wishlist_change_males(div_id, select_id){
671 var female_accession_ids = jQuery('#cross_wishlist_female_accession_ids').val();
672 var male_ids = jQuery(div_id).val();
673 var female_id = jQuery(div_id).data('related');
674 var html = '<table class="table table-bordered" div="' + div_id +'_table"><thead><tr><th>Male Parent</th><th>Priority</th></tr></thead><tbody>';
675 for (var i=0; i<male_ids.length; i++){
676 html = html + '<tr><td>' + male_ids[i] + '</td><td><input class="form-control" male_id="' + male_ids[i] + '" female_id="' + female_id + '" name ="cross_wishlist_final_priority" id="cross_wishlist_male_priority_'+ i +'" value="1" placeholder="1"/></td></tr>';
678 html = html + '</tbody></table>';
679 jQuery(select_id).html(html);
683 jQuery('#cross_wishlist_submit').click(function(e){
685 var active_tab = jQuery('ul#cross_wishlist_tab_select li.active').attr('id');
686 //console.log(active_tab);
688 female_male_tracker = {};
689 selected_plot_ids = [];
693 var male_accession_limit = 60;
694 if (active_tab == 'cross_wishlist_no_list_tab'){
695 jQuery('input[name="cross_wishlist_final_priority"]').each(function() {
697 var male_id = jQuery(this).attr('male_id');
698 var female_id = jQuery(this).attr('female_id');
699 cross_data.push({ 'female_id':female_id, 'male_id':male_id, 'priority':value });
700 if (female_id in female_male_tracker){
701 female_male_tracker[female_id].push(male_id);
703 female_male_tracker[female_id] = [male_id];
706 female_trial_id = jQuery('#cross_wishlist_female_trial_id').val();
707 male_trial_id = jQuery('#cross_wishlist_male_trial_id').val();
709 if (active_tab == 'cross_wishlist_list_tab'){
710 jQuery('input[name="cross_wishlist_cross_grid_inputs"]').each(function() {
713 var male_id = jQuery(this).data('male');
714 var female_id = jQuery(this).data('female');
715 cross_data.push({ 'female_id':female_id, 'male_id':male_id, 'priority':value });
716 if (female_id in female_male_tracker){
717 female_male_tracker[female_id].push(male_id);
719 female_male_tracker[female_id] = [male_id];
723 female_trial_id = jQuery('#cross_wishlist_list_female_trial_id').val();
724 male_trial_id = jQuery('#cross_wishlist_list_male_trial_id').val();
726 //console.log(cross_data);
727 //console.log(trial_id);
728 //console.log(female_male_tracker);
729 if(!female_trial_id){
730 alert('You must select a female trial!');
734 alert('You must select a male trial! It can be the same trial as the female trial.');
737 for (f in female_male_tracker){
738 var male_array = female_male_tracker[f];
739 if (male_array.length > male_accession_limit){
740 alert('A maximum of 60 male accessions can be selected for each cross!');
745 url: '/ajax/cross/create_cross_wishlist',
748 'crosses': JSON.stringify(cross_data),
749 'female_trial_id': female_trial_id,
750 'male_trial_id': male_trial_id
753 beforeSend: function() {
754 jQuery('#working_modal').modal('show');
756 success: function(response) {
757 //console.log(response);
758 jQuery('#working_modal').modal('hide');
760 alert(response.error);
762 jQuery('#cross_wishlist_cross_select_div').html(response.data);
763 jQuery('#create_cross_wishlist_select_dialog').modal('show');
766 error: function(response) {
767 jQuery('#working_modal').modal('hide');
768 alert("An error occurred submitting plots for cross wishlist");
773 jQuery('#cross_wishlist_select_submits').click(function(){
774 var male_plot_limit = 60;
775 female_male_tracker = {};
776 selected_plot_ids = [];
778 jQuery('input[name="cross_wishlist_plot_select_female_input"]').each(function() {
780 selected_plot_ids.push({
781 'cross_female_accession_name' : jQuery(this).data('female_accession_name'),
782 'female_plot_id' : jQuery(this).val(),
783 'male_genotypes_string' : jQuery(this).data('male_genotypes_string')
787 jQuery('input[name="cross_wishlist_plot_select_male_input"]').each(function() {
789 selected_plot_ids.push({
790 'cross_female_accession_name' : jQuery(this).data('female_accession_name'),
791 'male_plot_id' : jQuery(this).val()
793 if (jQuery(this).data('female_accession_name') in female_male_tracker){
794 female_male_tracker[jQuery(this).data('female_accession_name')].push(jQuery(this).val());
796 female_male_tracker[jQuery(this).data('female_accession_name')] = [jQuery(this).val()];
800 //console.log(selected_plot_ids);
801 //console.log(female_male_tracker);
802 for (f in female_male_tracker){
803 var male_array = female_male_tracker[f];
804 if (male_array.length > male_plot_limit){
805 alert('A maximum of 60 male plots can be selected for each cross!');
811 url: '/ajax/cross/create_cross_wishlist_submit',
814 'crosses': JSON.stringify(cross_data),
815 'selected_plot_ids': JSON.stringify(selected_plot_ids),
816 'female_trial_id': female_trial_id,
817 'male_trial_id': male_trial_id,
818 'form_id': jQuery('#cross_wishlist_availabe_odk_crossing_forms').val(),
819 'form_name': jQuery("#cross_wishlist_availabe_odk_crossing_forms option:selected").text()
822 beforeSend: function() {
823 jQuery('#working_msg').html('Creating cross wishlist files and sending information to ONA... This can take time...');
824 jQuery('#working_modal').modal('show');
826 success: function(response) {
827 //console.log(response);
828 jQuery('#working_msg').html('');
829 jQuery('#working_modal').modal('hide');
830 if (response.filename) {
831 window.location.href = "/download/"+response.filename;
833 if (response.error) {
834 jQuery('#cross_wishlist_response_div').html(response.error);
836 if (response.success){
837 jQuery('#cross_wishlist_response_div').html(response.success);
839 jQuery('#create_cross_wishlist_response_dialog').modal('show');
841 error: function(response) {
842 jQuery('#working_msg').html('');
843 jQuery('#working_modal').modal('hide');
844 alert("An error occurred creating cross wishlist");
849 jQuery('#cross_wishlist_female_trial_select_upload_div').change(function(){
850 jQuery('#wishlist_lists_footer').hide();
851 jQuery('#wishlist_upload_footer').show();
854 jQuery('#wishlist_format').click(function() {
855 jQuery('#upload_wishlist_spreadsheet_info_dialog').modal("show");
858 jQuery('#wishlist_upload_submit').click(function() {
859 upload_wishlist_file();
862 function upload_wishlist_file() {
863 var female_trial_id = $('#cross_wishlist_upload_female_trial_id').val();
864 if (!female_trial_id) {
865 alert('A female trial is required');
869 var male_trial_id = $('#cross_wishlist_upload_male_trial_id').val();
870 if (!male_trial_id) {
871 alert('A male trial is required');
875 var uploadFile = $("#wishlist_file").val();
876 if (uploadFile === ''){
877 alert("Please select a file");
881 jQuery('#upload_wishlist_form').attr("action", "/ajax/cross/create_wishlist_by_uploading");
883 jQuery("#upload_wishlist_form").submit();
887 jQuery('#upload_wishlist_form').iframePostForm({
890 var uploadFile = $('#wishlist_file').val();
891 if (uploadFile === '') {
892 alert("No file selected");
894 jQuery('#working_msg').html('Creating cross wishlist files and sending information to ONA... This can take time...');
895 jQuery('#working_modal').modal('show');
897 complete: function(response) {
898 if (response.error_string) {
899 jQuery('#working_modal').modal('hide');
900 jQuery('#upload_wishlist_error_display tbody').html('');
901 jQuery('#upload_wishlist_error_display tbody').append(response.error_string);
902 jQuery('#upload_wishlist_error_display').modal("show");
905 if (response.error) {
906 jQuery('#working_modal').modal('hide');
907 alert(response.error);
910 if ((response.selected_plot_ids) && (response.cross_combinations)) {
911 var selected_plot_ids = JSON.stringify(response.selected_plot_ids);
912 var cross_combinations = JSON.stringify(response.cross_combinations);
913 var female_trial_id = jQuery('#cross_wishlist_upload_female_trial_id').val();
914 var male_trial_id = jQuery('#cross_wishlist_upload_male_trial_id').val();
915 var form_id = jQuery('#cross_wishlist_availabe_odk_crossing_forms').val();
916 var form_name = jQuery("#cross_wishlist_availabe_odk_crossing_forms option:selected").text();
919 url: '/ajax/cross/create_cross_wishlist_submit',
922 'crosses': cross_combinations,
923 'selected_plot_ids': selected_plot_ids,
924 'female_trial_id': female_trial_id,
925 'male_trial_id': male_trial_id,
927 'form_name': form_name
930 success: function(response) {
931 //console.log(response);
932 jQuery('#working_msg').html('');
933 jQuery('#working_modal').modal('hide');
934 if (response.filename) {
935 window.location.href = "/download/"+response.filename;
937 if (response.error) {
938 jQuery('#cross_wishlist_response_div').html(response.error);
940 if (response.success){
941 jQuery('#cross_wishlist_response_div').html(response.success);
943 jQuery('#create_cross_wishlist_response_dialog').modal('show');
945 error: function(response) {
946 jQuery('#working_msg').html('');
947 jQuery('#working_modal').modal('hide');
948 alert("An error occurred creating cross wishlist");
955 function check_trial_accessions(female_trial_id, female_accession_list_id, female_accessions, male_accessions) {
957 url: '/ajax/cross/check_wishlist_accessions',
960 'female_trial_id': female_trial_id,
961 'female_list_id': female_accession_list_id
963 beforeSend: function() {
964 jQuery('#working_modal').modal('show');
966 success: function(response) {
967 //console.log(response);
968 jQuery('#working_modal').modal('hide');
969 if (response.error_string){
970 alert(response.error_string);
972 draw_cross_grid(female_accessions, male_accessions);
975 error: function(response) {
976 jQuery('#working_modal').modal('hide');
977 alert("An error occurred checking accession list");