fix optional display
[sgn.git] / js / CXGN / BreedersToolbox / AddMultipleTrial.js
blob0f8e2b9b456082b7f8a8b3de5d98e64525e8ae4b
1 /*jslint browser: true, devel: true */
3 /**
5 =head1 AddMultipleTrial.js
7 Dialogs for adding multilocation trials
10 =head1 AUTHOR
12 Alex Ogbonna <aco46@cornell.edu>
14 =cut
19 var $j = jQuery.noConflict();
21 jQuery(document).ready(function ($) {
23     var list = new CXGN.List();
25     var design_json;
27     $(document).on('focusout', '#select_list_multi_list_select', function() {
28         if ($('#select_list_multi_list_select').val()) {
29             var stock_list_id = $('#select_list_multi_list_select').val();
30             var stock_list = JSON.stringify(list.getList(stock_list_id));
31             verify_stock_list(stock_list);
32         }
33     });
35     $(document).on('focusout', '#list_of_checks_section_multi_list_select', function() {
36         if ($('#list_of_checks_section_multi_list_select').val()) {
37             var stock_list_id = $('#list_of_checks_section_multi_list_select').val();
38             var stock_list = JSON.stringify(list.getList(stock_list_id));
39             verify_stock_list(stock_list);
40         }
41     });
43     $(document).on('focusout', '#crbd_list_of_checks_section_multi_list_select', function() {
44         if ($('#crbd_list_of_checks_section_multi_list_select').val()) {
45             var stock_list_id = $('#crbd_list_of_checks_section_multi_list_select').val();
46             var stock_list = JSON.stringify(list.getList(stock_list_id));
47             verify_stock_list(stock_list);
48         }
49     });
51     var stock_list_verified = 0;
52     function verify_stock_list(stock_list) {
53         $.ajax({
54             type: 'POST',
55             timeout: 3000000,
56             url: '/ajax/trial/verify_stock_list',
57             beforeSend: function(){
58                 jQuery('#working_modal').modal('show');
59             },
60             dataType: "json",
61             data: {
62                 'stock_list': stock_list,
63             },
64             success: function (response) {
65                 //console.log(response);
66                 jQuery('#working_modal').modal('hide');
67                 if (response.error) {
68                     alert(response.error);
69                     stock_list_verified = 0;
70                 }
71                 if (response.success){
72                     stock_list_verified = 1;
73                 }
74             },
75             error: function () {
76                 jQuery('#working_modal').modal('hide');
77                 alert('An error occurred. sorry');
78                 stock_list_verified = 0;
79             }
80        });
81     }
83   function generate_multi_experimental_design() {
84       var name = $('#new_multi_trial_name').val();
85       var year = $('#add_multi_project_year').val();
86       var desc = $('#add_multi_project_description').val();
87       var trial_location = $('#add_multi_project_location').val();
88       var block_number = $('#block_number_multi').val();
89       var row_number= $('#row_number_multi').val();
90       var row_number_per_block=$('#row_number_per_block_multi').val();
91       var col_number_per_block=$('#col_number_per_block_multi').val();
92       var col_number=$('#col_number_multi').val();
93       var location_list_id = $('#select_list_locations_multi_list_select').val();
94       var stock_list_id = $('#select_list_multi_list_select').val();
95       var control_list_id = $('#list_of_checks_section_multi_list_select').val();
96       var control_list_id_crbd = $('#crbd_list_of_checks_section_multi_list_select').val();
97       var control_list_crbd;
98       if (control_list_id_crbd != ""){
99           control_list_crbd = JSON.stringify(list.getList(control_list_id_crbd));
100       }
101       var location_list;
102       if (location_list_id != "") {
103           location_list = JSON.stringify(list.getList(location_list_id));
104       } else {
105         location_list = JSON.stringify(trial_location);
106       }
108       var stock_list;
109       if (stock_list_id != "") {
110           stock_list = JSON.stringify(list.getList(stock_list_id));
111       }
112       var control_list;
113       if (control_list_id != "") {
114           control_list = JSON.stringify(list.getList(control_list_id));
115       }
117       var design_type = $('#select_multi-design_method').val();
119       var use_same_layout;
120       if ($('#use_same_layout').is(':checked')) {
121          use_same_layout = $('#use_same_layout').val();
122       }
123       else {
124          use_same_layout = "";
125       }
127       var rep_count = $('#rep_count_multi').val();
128       var block_size = $('#block_size_multi').val();
129       var max_block_size = $('#max_block_size_multi').val();
130       var plot_prefix = $('#plot_prefix_multi').val();
131       var start_number = $('#start_number_multi').val();
132       var increment = $('#increment_multi').val();
134       $.ajax({
135           type: 'POST',
136           timeout: 3000000,
137           url: '/ajax/trial/generate_experimental_design',
138           beforeSend: function(){
139               $('#working_modal').modal("show");
140           },
141           dataType: "json",
142           data: {
143               'project_name': name,
144               'project_description': desc,
145               'year': year,
146               'trial_location': location_list,
147               'stock_list': stock_list,
148               'control_list': control_list,
149               'control_list_crbd': control_list_crbd,
150               'design_type': design_type,
151               'rep_count': rep_count,
152               'block_number': block_number,
153               'row_number': row_number,
154               'row_number_per_block': row_number_per_block,
155               'col_number_per_block': col_number_per_block,
156               'col_number': col_number,
157               'block_size': block_size,
158               'max_block_size': max_block_size,
159               'plot_prefix': plot_prefix,
160               'start_number': start_number,
161               'increment': increment,
162               'use_same_layout': use_same_layout,
163           },
164           success: function (response) {
165               if (response.error) {
166                   alert(response.error);
167                   $('#working_modal').modal("hide");
168               } else {
169                 $('#multi_trial_design_information').html(response.design_info_view_html);
170                 var layout_view = JSON.parse(response.design_layout_view_html);
171                 //console.log(layout_view);
172                 var layout_html = '';
173                 for (var i=0; i<layout_view.length; i++) {
174                   //console.log(layout_view[i]);
175                   layout_html += layout_view[i] + '<br>';
176                 }
177                 $('#multi_trial_design_view_layout_return').html(layout_html);
178                 //$('#multi_trial_design_view_layout_return').html(response.design_layout_view_html);
180                 $('#working_modal').modal("hide");
181                 $('#multi_trial_design_confirm').modal("show");
182                 design_json = response.design_json;
183               }
184           },
185           error: function () {
186             $('#working_modal').modal("hide");
187             alert('An error occurred. sorry.');
188           }
189      });
190   }
192   $(document).on('click', '#new_multi_trial_submit', function () {
193         var name = $('#new_multi_trial_name').val();
194         var year = $('#add_multi-project_year').val();
195         var desc = $('textarea#add_multi-project_description').val();
196         var method_to_use = $('.format_type:checked').val();
198         if (name == '') {
199           alert('Trial name required');
200           return;
201         }
203         if (year === '' || desc === '') {
204           alert('Year and description are required.');
205           return;
206         }
208         if (stock_list_verified == 1){
209             if (method_to_use == "create_with_design_tool") {
210               generate_multi_experimental_design();
211             }
212         } else {
213             alert('Accession list is not valid!');
214             return;
215         }
217   });
219   $(document).on('change', '#select_multi-design_method', function () {
221       var design_method = $("#select_multi-design_method").val();
222       if (design_method == "CRD") {
223           $("#trial_multi-design_more_info").show();
224           $("#show_list_of_checks_section_multi").hide();
225           $("#crbd_show_list_of_checks_section_multi").show();
226           $("#rep_count_section_multi").show();
227           $("#block_number_section_multi").hide();
228           $("#block_size_section_multi").hide();
229           $("#max_block_section_multi").hide();
230           $("#max_block_size_section_multi").hide();
231           $("#row_number_section_multi").hide();
232           $("#row_number_per_block_section_multi").hide();
233           $("#col_number_per_block_section_multi").hide();
234           $("#col_number_section_multi").hide();
235           $("#row_number_per_block_section_multi").hide();
236           $("#other_parameter_section_multi").hide();
237           $("#design_info_multi").show();
238           $("#greenhouse_num_plants_per_accession_section_multi").hide();
239           $("#westcott_num_colm_section").hide();
240           $("#westcott_num_colm_between_check_section").hide();
241           $("#westcott_check_1m_section").hide();
242           $("#westcott_check_2m_section").hide();
243           $("#westcott_section").hide();
244       } else if (design_method == "RCBD") {
245           $("#trial_multi-design_more_info").show();
246           $("#crbd_show_list_of_checks_section_multi").show();
247           $("#show_list_of_checks_section_multi").hide();
248           $("#rep_count_section_multi").hide();
249           $("#block_number_section_multi").show();
250           $("#block_size_section_multi").hide();
251           $("#max_block_size_section_multi").hide();
252           $("#row_number_section_multi").hide();
253           $("#row_number_per_block_section_multi").hide();
254           $("#col_number_per_block_section_multi").hide();
255           $("#col_number_section_multi").hide();
256           $("#row_number_per_block_section_multi").hide();
257           $("#other_parameter_section_multi").hide();
258           $("#design_info_multi").show();
259           $("#greenhouse_num_plants_per_accession_section_multi").hide();
260           $("#westcott_num_colm_section").hide();
261           $("#westcott_num_colm_between_check_section").hide();
262           $("#westcott_check_1m_section").hide();
263           $("#westcott_check_2m_section").hide();
264           $("#westcott_section").hide();
265       } else if (design_method == "Alpha") {
266           $("#trial_multi-design_more_info").show();
267           $("#crbd_show_list_of_checks_section_multi").show();
268           $("#show_list_of_checks_section_multi").hide();
269           $("#rep_count_section_multi").show();
270           $("#block_number_section_multi").hide();
271           $("#block_size_section_multi").show();
272           $("#max_block_size_section_multi").hide();
273           $("#row_number_section_multi").hide();
274           $("#row_number_per_block_section_multi").hide();
275           $("#col_number_per_block_section_multi").hide();
276           $("#col_number_section_multi").hide();
277           $("#row_number_per_block_section_multi").hide();
278           $("#other_parameter_section_multi").hide();
279           $("#design_info_multi").show();
280           $("#greenhouse_num_plants_per_accession_section_multi").hide();
281           $("#westcott_num_colm_section").hide();
282           $("#westcott_num_colm_between_check_section").hide();
283           $("#westcott_check_1m_section").hide();
284           $("#westcott_check_2m_section").hide();
285           $("#westcott_section").hide();
286       } else if (design_method == "Lattice") {
287           $("#FieldMap").show();
288           $("#trial_design_more_info").show();
289           $("#trial_multi-design_more_info").show();
290           $("#crbd_show_list_of_checks_section").show();
291           $("#crbd_show_list_of_checks_section_multi").show();
292           $("#show_list_of_checks_section").hide();
293           $("#show_list_of_checks_section_multi").hide();
294           $("#rep_count_section").show();
295           $("#block_number_section").hide();
296           $("#block_size_section").hide();
297           $("#max_block_size_section").hide();
298           $("#block_size_section_multi").hide();
299           $("#max_block_size_section_multi").hide();
300           $("#row_number_per_block_section_multi").hide();
301           $("#other_parameter_section_multi").hide();
302           $("#row_number_section_multi").hide();
303           $("#row_number_section").hide();
304           $("#rep_count_section_multi").show();
305           $("#row_number_per_block_section").hide();
306           $("#col_number_per_block_section").hide();
307           $("#col_number_section").hide();
308           $("#row_number_per_block_section").hide();
309           $("#other_parameter_section").hide();
310           $("#design_info").show();
311           $("#greenhouse_num_plants_per_accession_section").hide();
312           $('#greenhouse_default_num_plants_per_accession').hide();
313           $("#westcott_num_colm_section").hide();
314           $("#westcott_num_colm_between_check_section").hide();
315           $("#westcott_check_1m_section").hide();
316           $("#westcott_check_2m_section").hide();
317           $("#westcott_section").hide();
318       } else if (design_method == "Augmented") {
319           $("#trial_multi-design_more_info").show();
320           $("#show_list_of_checks_section_multi").show();
321           $("#crbd_show_list_of_checks_section_multi").hide();
322           $("#rep_count_section_multi").hide();
323           $("#block_number_section_multi").hide();
324           $("#block_size_section_multi").hide();
325           $("#max_block_size_section_multi").show();
326           $("#row_number_section_multi").hide();
327           $("#row_number_per_block_section_multi").hide();
328           $("#col_number_per_block_section_multi").hide();
329           $("#col_number_section_multi").hide();
330           $("#row_number_per_block_section_multi").hide();
331           $("#other_parameter_section_multi").hide();
332           $("#design_info_multi").show();
333           $("#greenhouse_num_plants_per_accession_section_multi").hide();
334           $("#westcott_num_colm_section").hide();
335           $("#westcott_num_colm_between_check_section").hide();
336           $("#westcott_check_1m_section").hide();
337           $("#westcott_check_2m_section").hide();
338           $("#westcott_section").hide();
339       } else if (design_method == "") {
340           $("#show_list_of_checks_section_multi").hide();
341           $("#crbd_show_list_of_checks_section_multi").hide();
342           $("#trial_design_more_info_multi").hide();
343           $("#trial_multi-design_more_info_multi").hide();
344           $("#rep_count_section_multi").hide();
345           $("#block_number_section_multi").hide();
346           $("#block_size_section_multi").hide();
347           $("#max_block_size_section_multi").hide();
348           $("#row_number_section_multi").hide();
349           $("#row_number_per_block_section_multi").hide();
350           $("#col_number_per_block_section_multi").hide();
351           $("#col_number_section_multi").hide();
352           $("#row_number_per_block_section_multi").show();
353           $("#other_parameter_section_multi").hide();
354           $("#other_parameter_section_multi").hide();
355           $("#design_info_multi").show();
356           $("#greenhouse_num_plants_per_accession_section_multi").hide();
357           $("#westcott_num_colm_section").hide();
358           $("#westcott_num_colm_between_check_section").hide();
359           $("#westcott_check_1m_section").hide();
360           $("#westcott_check_2m_section").hide();
361           $("#westcott_section").hide();
362       }
363       else if (design_method == "MAD") {
364           $("#trial_multi-design_more_info").show();
365           $("#show_list_of_checks_section_multi").show();
366           $("#crbd_show_list_of_checks_section_multi").hide();
367           $("#rep_count_section_multi").hide();
368           $("#row_number_section_multi").show();
369           $("#block_number_section_multi").hide();
370           $("#block_size_section_multi").hide();
371           $("#row_number_per_block_section_multi").show();
372           $("#col_number_per_block_section_multi").show();
373           $("#col_number_section_multi").show();
374           $("#max_block_size_section_multi").hide();
375           $("#row_number_per_block_section_multi").show();
376           $("#other_parameter_section_multi").show();
377           $("#design_info_multi").show();
378           $("#westcott_num_colm_section").hide();
379           $("#westcott_num_colm_between_check_section").hide();
380           $("#westcott_check_1m_section").hide();
381           $("#westcott_check_2m_section").hide();
382           $("#westcott_section").hide();
384           $("#show_other_parameter_options_multi").click(function () {
385               if ($('#show_other_parameter_options_multi').is(':checked')) {
386                   $("#other_parameter_options_multi").show();
387               }
388               else {
389                   $("#other_parameter_options_multi").hide();
390               }
391           });
392           $("#greenhouse_num_plants_per_accession_section_multi").hide();
393       }
395       else if (design_method == 'greenhouse') {
396           $("#trial_multi-design_more_info").show();
397           $("#show_list_of_checks_section_multi").hide(); 
398           $("#rep_count_section_multi").hide();
399           $("#block_number_section_multi").hide();
400           $("#block_size_section_multi").hide();
401           $("#max_block_section_multi").hide();
402           $("#row_number_section_multi").hide();
403           $("#row_number_per_block_section_multi").hide();
404           $("#col_number_per_block_section_multi").hide();
405           $("#col_number_section_multi").hide();
406           $("#row_number_per_block_section_multi").hide();
407           $("#other_parameter_section_multi").hide();
408           $("#design_info_multi").hide();
409           $("#greenhouse_num_plants_per_accession_section_multi").show();
410           $("#westcott_num_colm_section").hide();
411           $("#westcott_num_colm_between_check_section").hide();
412           $("#westcott_check_1m_section").hide();
413           $("#westcott_check_2m_section").hide();
414           $("#westcott_section").hide();
415           greenhouse_show_num_plants_section_multi();
416       }
417       else if (design_method == 'westcott') {
418           $("#FieldMap").hide();
419           $("#trial_design_more_info").hide();
420           $("#trial_multi-design_more_info").show();
421           $("#crbd_show_list_of_checks_section").hide();
422           $("#show_list_of_checks_section").hide();
423           $("#crbd_show_list_of_checks_section_multi").hide();
424           $("#show_list_of_checks_section_multi").hide();
425           $("#rep_count_section_multi").hide();
426           $("#rep_count_section").hide();
427           $("#row_number_per_block_section_multi").hide();
428           $("#other_parameter_section_multi").hide();
429           $("#row_number_section_multi").hide();
430           $("#block_number_section").hide();
431           $("#block_size_section").hide();
432           $("#block_size_section_multi").hide();
433           $("#max_block_size_section").hide();
434           $("#max_block_size_section_multi").hide();
435           $("#row_number_section").hide();
436           $("#row_number_per_block_section").hide();
437           $("#col_number_per_block_section").hide();
438           $("#col_number_section").hide();
439           $("#row_number_per_block_section").hide();
440           $("#other_parameter_section").hide();
441           $("#design_info").hide();
442           $("#greenhouse_num_plants_per_accession_section").hide();
443           $('#greenhouse_default_num_plants_per_accession').hide();
444           $("#westcott_section").show();
445           $("#westcott_num_colm_section").show();
446           $("#westcott_num_colm_between_check_section").show();
447           $("#westcott_check_1m_section").show();
448           $("#westcott_check_2m_section").show();
450       }
452       else {
453           alert("Unsupported design method");
454       }
455   });
457   $("#show_plot_naming_options_multi").click(function () {
458   if ($('#show_plot_naming_options_multi').is(':checked')) {
459     $("#plot_naming_options_multi").show();
460   }
461   else {
462     $("#plot_naming_options_multi").hide();
463   }
465   });
468   jQuery(document).on('change', '#select_list_multi_list_select', function() {
469       if (jQuery("#select_multi-design_method").val() == 'greenhouse') {
470           greenhouse_show_num_plants_section_multi();
471       }
472   });
474   $("#select_list_locations_multi").append(list.listSelect("select_list_locations_multi", [ 'locations' ], "select location list", 'refresh' ));
476   function open_multilocation_project_dialog() {
477     $('#add_multilocation_project_dialog').modal("show");
478     $("#select_list_multi_list_select").remove();
479     $("#select_seedlot_list_multi_list_select").remove();
480     $("#list_of_checks_section_multi_list_select").remove();
481     $("#crbd_list_of_checks_section_multi_list_select").remove();
482     $("#select_list_multi").append(list.listSelect("select_list_multi", [ 'accessions' ], '', 'refresh' ));
483     $("#select_seedlot_list_multi").append(list.listSelect("select_seedlot_list_multi", [ 'seedlots' ], '', 'refresh'));
484     $("#list_of_checks_section_multi").append(list.listSelect("list_of_checks_section_multi", [ 'accessions' ], '', 'refresh'));
485     $("#crbd_list_of_checks_section_multi").append(list.listSelect("crbd_list_of_checks_section_multi", [ 'accessions' ], "select optional check list", 'refresh'));
487     //add a blank line to location select dropdown that dissappears when dropdown is opened
488     $("#add_project_location").prepend("<option value=''></option>").val('');
489     $("#add_project_location").one('mousedown', function () {
490               $("option:first", this).remove();
491     });
493     //add a blank line to list select dropdown that dissappears when dropdown is opened
494     $("#select_list_multi_list_select").prepend("<option value=''></option>").val('');
495     $("#select_list_multi_list_select").one('mousedown', function () {
496               $("option:first", this).remove();
497     });
499     //add a blank line to list select dropdown that dissappears when dropdown is opened
500     $("#select_seedlot_list_multi_list_select").prepend("<option value=''></option>").val('');
501     $("#select_seedlot_list_multi_list_select").one('mousedown', function () {
502               $("option:first", this).remove();
503     });
505     //add a blank line to list of checks select dropdown that dissappears when dropdown is opened
506     $("#list_of_checks_section_multi_list_select").prepend("<option value=''></option>").val('');
507     $("#list_of_checks_section_multi_list_select").one('mousedown', function () {
508               $("option:first", this).remove();
509     });
511     $("#crbd_list_of_checks_section_multi_list_select").prepend("<option value=''></option>").val('');
512     $("#crbd_list_of_checks_section_multi_list_select").one('mousedown', function () {
513               $("option:first", this).remove();
514     });
516     //add a blank line to design method select dropdown that dissappears when dropdown is opened
517     $("#select_multi-design_method").prepend("<option value=''></option>").val('');
518     $("#select_multi-design_method").one('mousedown', function () {
519               $("option:first", this).remove();
520               $("#trial_multi-design_more_info").show();
521         //trigger design method change events in case the first one is selected after removal of the first blank select item
522         $("#select_multi-design_method").change();
523     });
525     //reset previous selections
526     $("#select_multi-design_method").change();
528     var method_to_use = $('.format_type:checked').val();
529           if (method_to_use == "empty") {
530               $("#trial_multi-design_info").hide();
531               $("#trial_multi-design_more_info").hide();
532               $("#get_file_upload_data").hide();
533           }
534           if (method_to_use == "create_with_upload") {
535               $("#get_file_upload_data").show();
536               $("#trial_multi-design_info").hide();
537               $("#trial_multi-design_more_info").hide();
538           } else {
539               $("#get_file_upload_data").hide();
540           }
541           if (method_to_use == "create_with_design_tool") {
542               $("#trial_multi-design_info").show();
543               $("#select_multi-design_method").change();
544           } else {
545               $("trial_multi-design_info").hide();
546           }
547   }
549   $('#add_multiloc_project_link').click(function () {
550       get_select_box('years', 'add_multi_project_year', {'auto_generate': 1 });
551       get_select_box('trial_types', 'add_multi_project_type', {'empty':1} );
552       open_multilocation_project_dialog();
554   });
557   function save_experimental_design(design_json) {
558   //  var decoded_design = JSON.parse(design_json);
560       var list = new CXGN.List();
561       var name = jQuery('#new_multi_trial_name').val();
562       var year = jQuery('#add_multi_project_year').val();
563       var desc = jQuery('#add_multi_project_description').val();
564       var trial_location = jQuery('#add_multi_project_location').val();
565       //var block_number = jQuery('#block_number_multi').val();
566       var stock_list_id = jQuery('#select_list_multi_list_select').val();
567       var control_list_id = jQuery('#list_of_checks_section_multi_list_select').val();
568       var location_list_id = jQuery('#select_list_locations_multi_list_select').val();
569       var location_list;
570       var num_plants_per_plot = 0;
571       var num_subplots_per_plot = 0;
573       var locations;
574       var location_list_id = jQuery('#select_list_locations_multi_list_select').val();
575       if (location_list_id != "") {
576           location_list = JSON.stringify(list.getList(location_list_id));
577       } else {
578           location_list = JSON.stringify(trial_location);
579       }
581       var design_type = jQuery('#select_multi-design_method').val();
582       var greenhouse_num_plants = [];
583       if (stock_list_id != "" && design_type == 'greenhouse') {
584           for (var i=0; i<stock_list_array.length; i++) {
585               var value = jQuery("input#multi_greenhouse_num_plants_input_" + i).val();
586               if (value == '') {
587                   value = 1;
588               }
589               greenhouse_num_plants.push(value);
590           }
591           //console.log(greenhouse_num_plants);
592       }
594       var use_same_layout;
595       if ($('#use_same_layout').is(':checked')) {
596          use_same_layout = $('#use_same_layout').val();
597       }
598       else {
599          use_same_layout = "";
600       }
602       var breeding_program_name = jQuery('#select_breeding_program_multi').val();
603       var trial_type = jQuery('#add_multi_project_type').val();
605       //var stock_verified = verify_stock_list(stock_list);
606       if (desc == '' || year == '') {
607          alert('Year and description are required.');
608          return;
609       }
610       jQuery.ajax({
611          type: 'POST',
612          timeout: 3000000,
613          url: '/ajax/trial/save_experimental_design',
614          dataType: "json",
615          beforeSend: function() {
616              jQuery('#working_modal').modal("show");
617          },
618          data: {
619               'project_name': name,
620               'project_description': desc,
621               'use_same_layout': use_same_layout,
622               'year': year,
623               'trial_type': trial_type,
624               'trial_location': location_list,
625               'design_type': design_type,
626               'design_json': design_json,
627               'breeding_program_name': breeding_program_name,
628               'greenhouse_num_plants': JSON.stringify(greenhouse_num_plants),
629               'has_plant_entries': num_plants_per_plot,
630               'has_subplot_entries': num_subplots_per_plot,
631           },
632           success: function (response) {
633               if (response.error) {
634                   jQuery('#working_modal').modal("hide");
635                   alert(response.error);
636                   jQuery('#multi_trial_design_confirm').modal("hide");
637               } else {
638                   refreshTrailJsTree(0);
639                   //alert('Trial design saved');
640                   jQuery('#working_modal').modal("hide");
641                   jQuery('#multi_trial_saved_dialog_message').modal("show");
642               }
643           },
644           error: function () {
645               jQuery('#trial_saving_dialog').dialog("close");
646               alert('An error occurred saving the trial.');
647               jQuery('#multi_trial_design_confirm').dialog("close");
648           }
649       });
650   }
652   jQuery('#new_multi_trial_confirm_submit').click(function () {
653           save_experimental_design(design_json);
654   });
656   $('#view_multi_trial_layout_button').click(function () {
657       $('#trial_multi_design_view_layout').modal("show");
658   });
660   $('#redo_multiloc_trial_layout_button').click(function () {
661       generate_multi_experimental_design();
662       $('#trial_multi_design_view_layout').modal("show");
663   });
667 function greenhouse_show_num_plants_section_multi(){
668     var list = new CXGN.List();
669     var stock_list_id = jQuery('#select_list_multi_list_select').val();
670     if (stock_list_id != "") {
671         stock_list = list.getList(stock_list_id);
672         //console.log(stock_list);
673         var html = '<form class="form-horizontal">';
674         for (var i=0; i<stock_list.length; i++){
675             html = html + '<div class="form-group"><label class="col-sm-3 control-label">' + stock_list[i] + ': </label><div class="col-sm-9"><input class="form-control" id="multi_greenhouse_num_plants_input_' + i + '" type="text" placeholder="1" /></div></div>';
676         }
677         html = html + '</form>';
678         jQuery("#greenhouse_num_plants_per_accession_multi").empty().html(html);
679     }