1 /*jslint browser: true, devel: true */
7 Dialogs for adding and uploading crosses
11 Jeremy D. Edwards <jde22@cornell.edu>
17 var $j = jQuery.noConflict();
19 jQuery(document).ready(function($) {
21 $('#program').change(function(){
22 get_select_box('folders', 'add_cross_folder_select_div', {
23 'name': 'add_cross_folder_id',
24 'id': 'add_cross_folder_id',
25 'folder_for_crosses' : true,
27 'breeding_program_id': jQuery('#program').val()
31 $("#create_cross_link").click(function() {
33 $("#cross_type_info").click(function() {
34 $("#cross_type_dialog").modal("show");
37 get_select_box('folders', 'add_cross_folder_select_div', {
38 'name': 'add_cross_folder_id',
39 'id': 'add_cross_folder_id',
40 'folder_for_crosses' : true,
42 'breeding_program_id': jQuery('#program').val()
45 var lo = new CXGN.List();
46 $('#polycross_accession_list').html(lo.listSelect('polycross_accessions', ['accessions'], 'select'));
47 $('#reciprocal_accession_list').html(lo.listSelect('reciprocal_accessions', ['accessions'], 'select'));
48 $('#maternal_accession_list').html(lo.listSelect('maternal_accessions', ['accessions'], 'select'));
49 $('#paternal_accession_list').html(lo.listSelect('paternal_accessions', ['accessions'], 'select'));
51 $("#create_cross").modal("show");
53 $("#cross_type").change(function() { // show cross_type specific inputs depending on cross type selected
54 $("#get_maternal_parent").toggle($("#cross_type").val() == "biparental");
55 $("#get_paternal_parent").toggle($("#cross_type").val() == "biparental");
56 $("#get_selfed_parent").toggle($("#cross_type").val() == "self");
57 $("#get_open_maternal_parent").toggle($("#cross_type").val() == "open");
58 $("#get_open_paternal_population").toggle($("#cross_type").val() == "open");
59 $("#get_bulk_maternal_population").toggle($("#cross_type").val() == "bulk");
60 $("#get_bulk_paternal_parent").toggle($("#cross_type").val() == "bulk");
61 $("#get_bulk_selfed_population").toggle($("#cross_type").val() == "bulk_self");
62 $("#get_bulk_open_maternal_population").toggle($("#cross_type").val() == "bulk_open");
63 $("#get_bulk_open_paternal_population").toggle($("#cross_type").val() == "bulk_open");
64 $("#get_doubled_haploid_parent").toggle($("#cross_type").val() == "doubled_haploid");
65 $("#polycross_accessions").toggle($("#cross_type").val() == "polycross");
66 $("#reciprocal_accessions").toggle($("#cross_type").val() == "reciprocal");
67 $("#maternal_accessions").toggle($("#cross_type").val() == "multicross");
68 $("#paternal_accessions").toggle($("#cross_type").val() == "multicross");
71 $('input[id*="_parent"]').autocomplete({
72 source: '/ajax/stock/accession_autocomplete'
75 $('input[id*="_population"]').autocomplete({
76 source: '/ajax/stock/stock_autocomplete'
79 $("#flower_number_checkbox").change(function() {
80 $("#get_flower_number").toggle(this.checked); // show if it is checked, otherwise hide
83 $("#fruit_number_checkbox").change(function() {
84 $("#get_fruit_number").toggle(this.checked); // show if it is checked, otherwise hide
87 $("#use_folders_checkbox").change(function() {
88 $("#folder_section").toggle(this.checked); // show if it is checked, otherwise hide
91 $("#seed_number_checkbox").change(function() {
92 $("#get_seed_number").toggle(this.checked); // show if it is checked, otherwise hide
95 $("#create_progeny_checkbox").change(function() {
96 $("#create_progeny_number").toggle(this.checked); // show if it is checked, otherwise hide
97 $("#use_prefix_suffix").toggle(this.checked); // show if it is checked, otherwise hide
98 $("#get_prefix_suffix").toggle(this.checked); // show if it is checked, otherwise hide
101 $("#use_prefix_suffix_checkbox").change(function() {
102 $("#get_prefix_suffix").toggle(this.checked); // show if it is checked, otherwise hide
105 // $("#data_access_checkbox").change(function() {
106 // $("#show_visible_to_role_selection").toggle(this.checked); // show if it is checked, otherwise hide
111 $('#create_cross_submit').click(function() {
113 var crossType = $("#cross_type").val();
115 alert("No type was selected, please select a type before saving a cross/crosses");
119 var crossName = $("#cross_name").val();
120 crossName = crossName.trim();
122 alert("A cross name is required");
126 var breeding_program_id = $("#program").val();
127 if (!breeding_program_id) {
128 alert("A breeding program is required");
132 var visibleToRole = $("#visible_to_role").val();
133 var location = $("#location").val();
134 var folder_name = $("#add_cross_folder_name").val();
136 if (folder_name) { // get id if folder with this name already exisits
137 folder_id = $('#add_cross_folder_id option').filter(function () { return $(this).html() == folder_name; }).val();
140 folder_id = $("#add_cross_folder_id").val();
142 add_cross(crossType, crossName, breeding_program_id, visibleToRole, location, folder_name, folder_id);
146 $('#cross_upload_breeding_program').change(function(){
147 get_select_box('folders', 'cross_folder_select_div', {
148 'name': 'upload_folder_id',
149 'id': 'upload_folder_id',
150 'folder_for_crosses': true,
152 'breeding_program_id': jQuery('#cross_upload_breeding_program').val()
156 $("#upload_crosses_link").click(function() {
158 $("#cross_upload_spreadsheet_format_info").click(function() {
159 $("#cross_upload_spreadsheet_info_dialog").modal("show");
162 get_select_box('folders', 'cross_folder_select_div', {
163 'name': 'upload_folder_id',
164 'id': 'upload_folder_id',
165 'folder_for_crosses': true,
167 'breeding_program_id': jQuery('#cross_upload_breeding_program').val()
169 $("#upload_crosses_dialog").modal("show");
172 $("#upload_crosses_submit").click(function() {
173 $("#upload_crosses_dialog").modal("hide");
174 upload_crosses_file();
177 $('#upload_crosses_form').iframePostForm({
180 var uploadFile = $("#crosses_upload_file").val();
181 if (uploadFile === '') {
182 alert("No file selected");
184 jQuery("#working_modal").modal("show");
186 complete: function(response) {
187 jQuery("#working_modal").modal("hide");
188 if (response.error_string) {
189 $("#upload_cross_error_display tbody").html('');
190 $("#upload_cross_error_display tbody").append(response.error_string);
191 $("#upload_cross_error_display").modal("show");
195 if (response.error) {
196 alert(response.error);
199 if (response.success) {
200 $('#cross_saved_dialog_message').modal("show");
205 jQuery("#refresh_crosstree_button").click(function() {
207 url: '/ajax/breeders/get_crosses_with_folders',
208 beforeSend: function() {
209 jQuery("#working_modal").modal("show");
211 success: function(response) {
212 jQuery("#working_modal").modal("hide");
215 error: function(response) {
216 jQuery("#working_modal").modal("hide");
217 alert('An error occurred refreshing crosses jstree html');
222 function add_cross(crossType, crossName, breeding_program_id, visibleToRole, location, folder_name, folder_id) {
224 var progenyNumber = $("#progeny_number").val();
225 var flowerNumber = $("#flower_number").val();
226 var fruitNumber = $("#fruit_number").val();
227 var seedNumber = $("#seed_number").val();
228 var prefix = $("#prefix").val();
229 var suffix = $("#suffix").val();
232 var maternal_parents;
233 var paternal_parents;
237 maternal = $("#maternal_parent").val();
238 paternal = $("#paternal_parent").val();
241 var selfedParent = $("#selfed_parent").val();
242 maternal = selfedParent;
243 paternal = selfedParent;
246 maternal = $("#open_maternal_parent").val();
247 paternal = $("#open_paternal_population").val();
250 maternal = $("#bulk_maternal_population").val();
251 paternal = $("#bulk_paternal_parent").val();
254 var bulkedSelfedPopulation = $("#bulk_selfed_population").val();
255 maternal = bulkedSelfedPopulation;
256 paternal = bulkedSelfedPopulation;
259 maternal = $("#bulk_open_maternal_population").val();
260 paternal = $("#bulk_open_paternal_population").val();
262 case 'doubled_haploid':
263 var doubledHaploidParent = $("#doubled_haploid_parent").val();
264 maternal = doubledHaploidParent;
265 paternal = doubledHaploidParent;
268 maternal_parents = get_accession_names('polycross_accessions_list_select');
269 if (!Array.isArray(maternal_parents)) { alert(maternal_parents); return; }
272 maternal_parents = get_accession_names('reciprocal_accessions_list_select');
273 if (!Array.isArray(maternal_parents)) { alert(maternal_parents); return; }
276 maternal_parents = get_accession_names('maternal_accessions_list_select');
277 if (!Array.isArray(maternal_parents)) { alert(maternal_parents); return; }
278 paternal_parents = get_accession_names('paternal_accessions_list_select');
279 if (!Array.isArray(paternal_parents)) { alert(paternal_parents); return; }
284 url: '/ajax/cross/add_cross',
288 data: 'cross_name=' + crossName + '&cross_type=' + crossType + '&maternal=' + maternal + '&paternal=' + paternal + '&maternal_parents=' + maternal_parents + '&paternal_parents=' + paternal_parents + '&progeny_number=' + progenyNumber + '&flower_number=' + flowerNumber + '&fruit_number=' + fruitNumber + '&seed_number=' + seedNumber + '&prefix=' + prefix + '&suffix=' + suffix + '&visible_to_role' + visibleToRole + '&breeding_program_id=' + breeding_program_id + '&location=' + location + '&folder_name=' + folder_name + '&folder_id=' + folder_id,
289 beforeSend: function() {
290 jQuery("#create_cross").modal("hide");
291 jQuery("#working_modal").modal("show");
293 error: function(response) {
294 alert("An error occurred. Please try again later!" + JSON.stringify(response));
296 parseerror: function(response) {
297 alert("A parse error occurred. Please try again." + response);
299 success: function(response) {
300 jQuery("#working_modal").modal("hide");
301 if (response.error) {
302 alert(response.error);
304 $('#cross_saved_dialog_message').modal("show");
311 function upload_crosses_file() {
312 var uploadFile = $("#crosses_upload_file").val();
313 $('#upload_crosses_form').attr("action", "/ajax/cross/upload_crosses_file");
314 if (uploadFile === '') {
315 alert("Please select a file");
318 $("#upload_crosses_form").submit();
321 function get_accession_names(accession_select_id) {
323 var accession_list_id = $('#' + accession_select_id).val();
324 var lo = new CXGN.List();
325 var accession_validation = 1;
326 if (accession_list_id) {
327 accession_validation = lo.validate(accession_list_id, 'accessions', true);
330 if (!accession_list_id) {
331 //alert("You need to select an accession list!");
332 return "You need to select an accession list!";
335 if (accession_validation != 1) {
336 //alert("The accession list did not pass validation. Please correct the list and try again");
337 return "The accession list did not pass validation. Please correct the list and try again";
340 var list_data = lo.getListData(accession_list_id);
341 var accessions = list_data.elements;
343 for (i = 0; i < accessions.length; i++) {
344 names.push(accessions[i][1]);