1 // Depends on CXGN.BreedersToolbox.HTMLSelect
3 function delete_phenotype_data_by_trial_id(trial_id) {
4 var yes = confirm("Are you sure you want to delete all phenotypic data associated with trial "+trial_id+" ? This action cannot be undone.");
6 jQuery('#working').dialog("open");
8 url: '/ajax/breeders/trial/'+trial_id+'/delete/phenotypes',
9 success: function(response) {
11 jQuery('#working').dialog("close");
12 alert(response.error);
15 jQuery('#working').dialog("close");
16 alert('The phenotypic data has been deleted.'); // to do: give some idea how many items were deleted.
17 window.location.href="/breeders/trial/"+trial_id;
20 error: function(response) {
21 jQuery('#working').dialog("close");
22 alert("An error occurred.");
29 function delete_layout_data_by_trial_id(trial_id) {
30 var yes = confirm("Are you sure you want to delete the layout data associated with trial "+trial_id+" ? This action cannot be undone.");
32 jQuery('#working').dialog("open");
35 url: '/ajax/breeders/trial/'+trial_id+'/delete/layout',
36 success: function(response) {
38 jQuery('#working').dialog("close");
39 alert(response.error);
42 jQuery('#working').dialog("close");
43 alert('The layout data has been deleted.'); // to do: give some idea how many items were deleted.
44 window.location.href="/breeders/trial/"+trial_id;
47 error: function(response) {
48 jQuery('#working').dialog("close");
49 alert("An error occurred.");
55 function delete_project_entry_by_trial_id(trial_id) {
56 var yes = confirm("Are you sure you want to delete the trial entry for trial "+trial_id+" ? This action cannot be undone.");
58 jQuery('#working').dialog("open");
61 url: '/ajax/breeders/trial/'+trial_id+'/delete/entry',
62 success: function(response) {
64 jQuery('#working').dialog("close");
65 alert(response.error);
68 jQuery('#working').dialog("close");
69 alert('The project entry has been deleted.'); // to do: give some idea how many items were deleted.
70 window.location.href="/breeders/trial/"+trial_id;
73 error: function(response) {
74 jQuery('#working').dialog("close");
75 alert("An error occurred.");
82 function associate_breeding_program() {
83 var program = jQuery('#breeding_program_select').val();
85 var trial_id = get_trial_id();
87 url: '/breeders/program/associate/'+program+'/'+ trial_id,
89 success: function(response) {
90 alert("Associated program with id "+program + " to trial with id "+ trial_id);
96 function load_breeding_program_info(trial_id) {
98 url:'/breeders/programs_by_trial/'+trial_id,
99 success: function(response) {
100 if (response.error) {
101 jQuery('#breeding_programs').html('[ An error occurred fetching the breeding program information ]');
104 var programs = response.projects;
105 for (var i=0; i< programs.length; i++) {
106 var html = programs[0][1] + ' (' + programs[0][2] + ') ';
108 if (programs.length == 0) { html = "(none)"; }
109 jQuery('#breeding_programs').html(html);
113 jQuery('#breeding_programs').html('[ An error occurred ]');
119 function open_create_fieldbook_dialog() {
120 var trialID = parseInt(jQuery('#trialIDDiv').text());
123 url: '/ajax/fieldbook/create',
128 beforeSend: function() {
129 jQuery("#working_modal").modal("show");
131 success: function (response) {
132 jQuery("#working_modal").modal("hide");
133 if (response.error) {
134 alert(response.error);
135 jQuery('#open_create_fieldbook_dialog').dialog("close");
137 jQuery('#tablet_layout_download_link').attr('href',"/fieldbook");
138 jQuery("#tablet_field_layout_saved_dialog_message").dialog("open");
139 //alert(response.file);
140 jQuery('#open_create_fieldbook_dialog').dialog("close");
144 jQuery("#working_modal").modal("hide");
145 alert('An error occurred creating the field book.');
146 jQuery('#open_create_fieldbook_dialog').dialog("close");
151 function open_create_DataCollector_dialog() {
152 //jQuery('#working').dialog("open");
153 jQuery('#working_modal').modal("show");
154 var list = new CXGN.List();
155 jQuery("#trait_list_dc").html(list.listSelect("trait_list", [ 'traits' ]));
156 //jQuery('#working').dialog("close");
157 jQuery('#working_modal').modal("hide");
158 jQuery('#create_DataCollector_dialog').dialog("open");
162 function create_DataCollector() {
163 //jQuery('#working').dialog("open");
164 jQuery('#working_modal').modal("show");
165 var trialID = parseInt(jQuery('#trialIDDiv').text());
166 var list = new CXGN.List();
167 var trait_list_id = jQuery('#trait_list_list_select').val();
169 if (! trait_list_id == "") {
170 trait_list = JSON.stringify(list.getList(trait_list_id));
174 url: '/ajax/phenotype/create_DataCollector',
178 'trait_list': trait_list,
181 success: function (response) {
182 //console.log("success "+JSON.stringify(response));
183 jQuery('#working_modal').modal("hide");
185 if (response.error) {
186 console.log("error: "+response.error);
187 alert("error: "+response.error);
188 jQuery('#open_create_DataCollector_dialog').dialog("close");
190 //alert("success: "+response.filename);
191 jQuery('#open_create_DataCollector_dialog').dialog("close");
192 jQuery('#working_modal').modal("hide");
193 window.location.href = "/download/"+response.filename;
197 //jQuery('#working').dialog("close");
198 jQuery('#working_modal').modal("hide");
199 alert('An error occurred creating a DataCollector file.');
200 jQuery('#open_download_DataCollector_dialog').dialog("close");
205 function open_derived_trait_dialog() {
206 jQuery('#working_modal').modal("show");
207 jQuery('#compute_derived_trait_dialog').dialog("open");
208 var trait = jQuery('#sel1').val();
209 jQuery("#test_xyz").html(trait);
210 jQuery('#working_modal').modal("hide");
214 function compute_derived_trait() {
215 jQuery('#working_modal').modal("show");
216 var trait = jQuery('#derived_trait_select').val();
217 var trialID = parseInt(jQuery('#trialIDDiv').text());
219 alert("No trait selected");
224 url: '/ajax/phenotype/create_derived_trait',
231 success: function (response) {
232 jQuery('#working_modal').modal("hide");
234 if (response.error) {
235 alert("Computation stopped: "+response.error);
236 //alert("Computation for "+trait+" stopped: "+response.error);
237 jQuery('#open_derived_trait_dialog').dialog("close");
240 jQuery('#open_derived_trait_dialog').dialog("close");
241 jQuery('#working_modal').modal("hide");
242 jQuery('derived_trait_saved_dialog_message');
243 alert("Successfully derived and uploaded phenotype");
244 // alert("Successfully derived and uploaded ' "+trait+" ' values for this trial");
248 jQuery('#working_modal').modal("hide");
249 alert('An error occurred creating trait.');
255 function trial_detail_page_setup_dialogs() {
257 jQuery('#change_breeding_program_dialog').dialog( {
260 title: 'Select Breeding Program',
265 id: "edit_trial_breeding_program_submit",
267 associate_breeding_program();
268 jQuery('#change_breeding_program_dialog').dialog("close");
269 var trial_id = get_trial_id();
270 load_breeding_program_info(trial_id);
273 'Cancel': function() { jQuery('#change_breeding_program_dialog').dialog("close"); }
277 jQuery( "#tablet_field_layout_saved_dialog_message" ).dialog({
282 jQuery( this ).dialog( "close" );
288 jQuery( "#data_collector_saved_dialog_message" ).dialog({
293 jQuery( this ).dialog( "close" );
300 // jQuery('#create_spreadsheet_dialog').dialog({
305 // position: ['top', 75],
308 // Cancel: function() {
309 // jQuery( this ).dialog( "close" );
312 // Create: {text: "Ok", id:"create_phenotyping_ok_button", click:function() {
313 // create_spreadsheet();
314 // //save_experimental_design(design_json);
315 // jQuery( this ).dialog( "close" );
321 // jQuery('#create_DataCollector_dialog').dialog({
326 // position: ['top', 75],
329 // Cancel: function() {
330 // jQuery( this ).dialog( "close" );
333 // Create: {text: "Create", id:"create_DataCollector_submit_button", click:function() {
334 // create_DataCollector();
335 // //save_experimental_design(design_json);
336 // jQuery( this ).dialog( "close" );
342 jQuery('#compute_derived_trait_dialog').dialog({
347 position: ['top', 75],
351 jQuery( this ).dialog( "close" );
354 Create: {text: "Create", id:"create_derived_trait_submit_button", click:function() {
355 compute_derived_trait();
356 jQuery( this ).dialog( "close" );
363 jQuery('#show_change_breeding_program_link').click(
365 jQuery('#change_breeding_program_dialog').dialog("open");
366 get_select_box('breeding_programs', 'change_breeding_program_select_div');
370 jQuery('#delete_phenotype_data_by_trial_id').click(
372 var trial_id = get_trial_id();
373 delete_phenotype_data_by_trial_id(trial_id);
377 jQuery('#delete_layout_data_by_trial_id').click(
379 var trial_id = get_trial_id();
380 delete_layout_data_by_trial_id(trial_id);
383 jQuery('#delete_trial_entry_by_trial_id').click(
385 var trial_id = get_trial_id();
386 delete_project_entry_by_trial_id(trial_id);
389 jQuery('#create_fieldbook_link').click(function () {
390 open_create_fieldbook_dialog();
394 jQuery('#view_layout_link').click(function () {
395 jQuery('#trial_design_view_layout').dialog("open");
398 jQuery('#edit_trial_description').click( function () {
399 jQuery('#edit_trial_description_dialog').dialog("open");
403 jQuery('#change_trial_year_dialog').dialog( {
408 title: "Change trial year",
410 cancel: { text: "Cancel",
411 click: function() { jQuery( this ).dialog("close"); },
412 id: "change_trial_year_cancel_button"
414 save: { text: "Save",
417 display_trial_year();
418 jQuery('#change_trial_year_dialog').dialog("close");
420 id: "change_trial_year_save_button"
426 jQuery('#change_year_link').click( function() {
427 jQuery('#change_trial_year_dialog').dialog("open");
428 get_select_box('years', 'change_year_select_div', { 'name' : 'year_select'});
431 jQuery('#change_trial_location_link').click( function() {
432 jQuery('#change_trial_location_dialog').dialog("open");
433 get_select_box('locations', 'trial_location_select_div', { 'name' : 'trial_location_select' });
436 jQuery('#change_planting_date_dialog').dialog( {
441 title: 'Change planting date',
443 cancel: { text: "Cancel",
444 click: function() { jQuery( this ).dialog("close"); },
445 id: "change_planting_date_button"
447 save: { text: "Save",
449 save_planting_date();
451 id: "change_planting_date_button"
456 jQuery('#planting_date_picker').datepicker();
458 jQuery('#change_planting_date_link').click( function() {
459 jQuery('#change_planting_date_dialog').dialog("open");
462 jQuery('#change_harvest_date_dialog').dialog( {
467 title: 'Change harvest date',
469 cancel: { text: "Cancel",
470 click: function() { jQuery( this ).dialog("close"); },
471 id: "change_harvest_date_button"
473 save: { text: "Save",
477 id: "change_harvest_date_button"
482 jQuery('#harvest_date_picker').datepicker();
484 jQuery('#change_harvest_date_link').click( function() {
485 jQuery('#change_harvest_date_dialog').dialog("open");
488 jQuery('#edit_trial_description_dialog').dialog( {
493 title: "Change trial description",
495 cancel: { text: "Cancel",
496 click: function() { jQuery( this ).dialog("close"); },
497 id: "edit_description_cancel_button"
499 save: { text: "Save",
500 click: function() { save_trial_description(); },
501 id: "edit_description_save_button"
507 jQuery('#edit_trial_type').click( function () {
508 jQuery('#edit_trial_type_dialog').dialog("open");
510 url: '/ajax/breeders/trial/alltypes',
511 success: function(response) {
512 if (response.error) {
513 alert(response.error);
517 if (response.types) {
518 var selected = 'selected="selected"';
519 for(var n=0; n<response.types.length; n++) {
521 html += '<option value="'+response.types[n][1]+'" >'+response.types[n][1]+'</option>';
525 html = '<option active="false">No trial types available</option>';
528 jQuery('#trial_type_select').html(html);
530 error: function(response) {
531 alert("An error occurred trying to retrieve trial types.");
538 // jQuery('#trial_type_select').change( {
542 jQuery('#edit_trial_type_dialog').dialog( {
547 title: "Change trial type",
549 cancel: { text: "Cancel",
550 click: function() { jQuery( this ).dialog("close"); },
551 id: "edit_type_cancel_button"
553 save: { text: "Save",
555 var type = jQuery('#trial_type_select').val();
556 save_trial_type(type);
557 display_trial_type(type);
558 jQuery('#edit_trial_type_dialog').dialog("close");
561 id: "edit_type_save_button"
566 jQuery('#change_trial_location_dialog').dialog( {
571 title: "Change trial location",
573 cancel: { text: "Cancel",
574 click: function() { jQuery( this ).dialog("close"); },
575 id: "change_location_cancel_button",
577 save: { text: "Save",
578 id: "edit_trial_location_submit",
580 var new_location = jQuery('#location_select').val();
581 save_trial_location(new_location);
582 display_trial_location(get_trial_id());
583 jQuery('#change_trial_location_dialog').dialog("close");
589 jQuery('#compute_derived_trait_link').click( function () {
590 jQuery('#compute_derived_trait_dialog').dialog("open");
592 url: '/ajax/breeders/trial/trait_formula',
593 success: function(response) {
594 //console.log(response);
595 if (response.error) {
596 alert(response.error);
600 if (response.derived_traits) {
601 var selected = 'selected="selected"';
602 for(var n=0; n<response.derived_traits.length; n++) {
603 //alert("derived trait: +derived_traits"+response.derived_traits[n]);
604 html += '<option value="'+response.derived_traits[n]+'" title="'+response.formula[n]+'" >'+response.derived_traits[n]+' </option> ';
609 html = '<option active="false">No derived trait available</option>';
612 jQuery('#derived_trait_select').html(html);
614 error: function(response) {
615 alert("An error occurred trying to retrieve derived traits.");
625 function save_trial_type(type) {
626 var trial_id = get_trial_id();
628 url: '/ajax/breeders/trial/'+trial_id+'/type/',
629 //url: '/ajax/breeders/trial/'+trial_id+'/type/'+type,
632 //async: false, //async=false because it needs to finish before page is updated again.
633 data: { 'type' : type },
634 success: function(response) {
635 if (response.error) {
636 alert(response.error);
639 alert('New trial type set successfully');
642 error: function(response) {
643 alert('An error occurred setting the trial type.');
650 function save_trial_year() {
651 var trial_id = get_trial_id();
652 var year = jQuery('#year_select').val();
654 url: '/ajax/breeders/trial/'+trial_id+'/year/'+year,
656 success: function(response) {
658 alert(response.error);
661 alert("Successfully changed year.");
664 error: function(response) {
665 alert('An error occurred.');
670 function save_harvest_date() {
671 var trial_id = get_trial_id();
672 var harvest_date = jQuery('#harvest_date_picker').val();
673 var checked_date = check_date(harvest_date);
677 url : '/ajax/breeders/trial/'+trial_id+'/harvest_date',
678 data: { 'harvest_date' : checked_date },
680 success: function(response){
681 if (response.error) {
682 alert(response.error);
685 alert("Successfully stored harvest date.");
686 display_harvest_date();
687 jQuery('#change_harvest_date_dialog').dialog("close");
690 error: function(response) {
691 alert('An error occurred.');
698 function display_harvest_date() {
699 var trial_id = get_trial_id();
701 url : '/ajax/breeders/trial/'+trial_id+'/harvest_date',
703 success: function(response) {
704 jQuery('#harvest_date').html("<a href='/calendar/personal?currentDate="+response.harvest_date+"' target=_blank>"+response.harvest_date+"</a>");
706 error: function(response) {
707 jQuery('#harvest_date').html('[ Protocol error. ]');
712 function save_planting_date() {
713 var trial_id = get_trial_id();
714 var planting_date = jQuery('#planting_date_picker').val();
715 var checked_date = check_date(planting_date);
719 url : '/ajax/breeders/trial/'+trial_id+'/planting_date',
720 data: { 'planting_date' : checked_date },
722 success: function(response){
723 if (response.error) {
724 alert(response.error);
727 alert("Successfully stored planting date.");
728 display_planting_date();
729 jQuery('#change_planting_date_dialog').dialog("close");
732 error: function(response) {
733 alert('An error test.');
741 function display_planting_date() {
742 var trial_id = get_trial_id();
744 url : '/ajax/breeders/trial/'+trial_id+'/planting_date',
746 success: function(response) {
747 jQuery('#planting_date').html("<a href='/calendar/personal?currentDate="+response.planting_date+"' target=_blank>"+response.planting_date+"</a>");
749 error: function(response) {
750 jQuery('#planting_date').html('[ Protocol error. ]');
755 function check_date(d) {
756 var regex = new RegExp("^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$");
758 var match = regex.exec(d);
759 if (match === null || match[1] > 12 || match[1] < 1 || match[2] >31 || match[2] < 1 || match[3]>2030 || match[3] < 1950) {
760 alert("This is not a valid date!");
763 // save as year/month/day plus time
764 return match[3]+'/'+match[1]+'/'+match[2]+" 00:00:00";
769 function display_trial_year() {
770 var trial_id = get_trial_id();
773 url: '/ajax/breeders/trial/'+trial_id+'/year',
775 success: function(response) {
776 if (response.error) {
777 jQuery('#trial_year').html('[ An error occurred fetching the trial year information. ]');
780 jQuery('#trial_year').html(response.year);
783 error: function(response) {
784 jQuery('#trial_year').html('[ Protocol error ]');
789 function display_trial_description(trial_id) {
791 url: '/ajax/breeders/trial/'+trial_id+'/description',
792 success: function(response) {
793 if (response.error) {
794 jQuery('#trial_description').html('[ An error occurred. ]');
797 jQuery('#trial_description').html(response.description);
798 jQuery('#trial_description_input').html(response.description);
801 error: function(response) {
802 jQuery('#trial_description').html('An error occurred trying to display the description.');
807 function save_trial_description() {
808 var trial_id = parseInt(jQuery('#trialIDDiv').text());
809 var description = jQuery('#trial_description_input').val();
810 alert('New description = '+description);
812 url: '/ajax/breeders/trial/'+trial_id+'/description/',
813 data: {description:description},
815 data: {'description' : description},
816 success: function(response) {
817 if (response.error) {
818 alert(response.error);
822 alert("Successfully updated description");
823 jQuery('#edit_trial_description_dialog').dialog("close");
824 display_trial_description(trial_id);
827 error: function(response) {
828 alert("An error occurred updating the trial description");
834 function display_trial_location(trial_id) {
836 url: '/ajax/breeders/trial/'+trial_id+'/location',
838 success: function(response) {
839 if (response.error) {
840 jQuery('#trial_location').html('[ An error occurred fetching the location. ]');
844 if (response.location[1]) {
845 html = response.location[1];
847 jQuery('#trial_location').html(html);
850 error: function(response) {
851 jQuery('#trial_location').html('[ Protocol error ]');
856 function save_trial_location(location_id) {
857 var trial_id = get_trial_id();
859 url: '/ajax/breeders/trial/'+trial_id+'/location/'+location_id,
860 //data: { 'location_id' : location_id },
862 success: function(response) {
863 if (response.message) { alert(response.message); }
864 if (response.error) { alert(response.error); }
866 error: function(response) {
867 alert("An error occurred.");
872 function get_trial_type(trial_id) {
875 url: '/ajax/breeders/trial/type/'+trial_id,
876 success: function(response) {
877 if (response.error) {
878 alert(response.error);
881 var type = "[type not set]";
883 type = response.type[1];
885 display_trial_type(type);
889 error: function(response) {
890 display_trial_type('[ Protocol error. ]');
895 function display_trial_type(type) {
896 jQuery('#trial_type').html(type);
899 function trial_folder_dialog() {
900 jQuery('#set_folder_dialog').dialog("open");
905 function get_trial_id() {
906 var trial_id = parseInt(jQuery('#trialIDDiv').text());
911 var $j = jQuery.noConflict();
913 jQuery(document).ready(function ($) {
915 $('#upload_trial_coords_link').click(function () {
916 open_upload_trial_coord_dialog();
919 jQuery("#upload_trial_coord_dialog").dialog({
924 position: ['top', 75],
926 "Cancel": function () {
927 jQuery('#upload_trial_coord_dialog').dialog("close");
929 "Ok": {text: "Ok", id:"upload_trial_coords_ok_button", click:function () {
930 upload_trial_coord_file();
931 jQuery('#upload_trial_coord_dialog').dialog("close");
938 $("#trial_coord_upload_spreadsheet_info_dialog").dialog( {
940 buttons: { "OK" : function() { $("#trial_coord_upload_spreadsheet_info_dialog").dialog("close"); },},
942 position: ['top', 75],
947 $("#trial_coordinates_upload_spreadsheet_format_info").click( function () {
948 $("#trial_coord_upload_spreadsheet_info_dialog" ).dialog("open");
952 $("#trial_coord_upload_success_dialog_message").dialog({
956 Ok: { id: "dismiss_trial_coord_upload_dialog",
958 //$("#upload_trial_form").dialog("close");
959 //$( this ).dialog( "close" );
969 $('#upload_trial_coordinates_form').iframePostForm({
972 var uploadedtrialcoordFile = $("#trial_coordinates_uploaded_file").val();
973 $('#working_modal').modal("show");
974 if (uploadedtrialcoordFile === '') {
975 $('#working_modal').modal("hide");
976 alert("No file selected");
979 complete: function (response) {
980 $('#working_modal').modal("hide");
981 if (response.error_string) {
982 $("#upload_trial_coord_error_display tbody").html('');
983 $("#upload_trial_coord_error_display tbody").append(response.error_string);
987 $("#upload_trial_coord_error_display").dialog({
991 position: ['top', 250],
992 title: "Errors in uploaded file",
995 $(this).dialog("close");
1002 if (response.error) {
1003 alert(response.error);
1006 if (response.success) {
1007 $('#trial_coord_upload_success_dialog_message').dialog("open");
1008 //alert("File uploaded successfully");
1013 function upload_trial_coord_file() {
1014 var uploadFile = $("#trial_coordinates_uploaded_file").val();
1015 $('#upload_trial_coordinates_form').attr("action", "/ajax/breeders/trial/coordsupload");
1016 if (uploadFile === '') {
1017 alert("Please select a file");
1020 $("#upload_trial_coordinates_form").submit();
1023 function open_upload_trial_coord_dialog() {
1024 $('#upload_trial_coord_dialog').dialog("open");