1 /*jslint browser: true, devel: true */
7 Display for managing genotyping trials
12 Jeremy D. Edwards <jde22@cornell.edu>
19 var $j = jQuery.noConflict();
21 jQuery(document).ready(function ($) {
23 // defined in CXGN.BreedersToolbox.HTMLSelect
24 get_select_box("locations", "location_select_div");
25 get_select_box("breeding_programs", "breeding_program_select_div");
26 get_select_box("years", "year_select_div");
28 get_select_box("locations", "igd_location_select_div");
29 get_select_box("breeding_programs", "igd_breeding_program_select_div");
30 get_select_box("years", "igd_year_select_div");
33 $( "#genotyping_trials_accordion" )
38 heightStyle: "content"
43 stop: function( event, ui ) {
44 // IE doesn't register the blur when sorting
45 // so trigger focusout handlers to remove .ui-state-focus
46 ui.item.children( "h3" ).triggerHandler( "focusout" );
51 $('#genotyping_trial_dialog').dialog( {
55 position: ['top', 150],
56 title: 'Create a genotyping trial',
60 id: 'genotype_trial_submit_button',
62 submit_genotype_trial();
67 id: 'genotype_trial_cancel_button',
69 $('#genotyping_trial_dialog').dialog("close");
75 function submit_genotype_trial() {
76 var breeding_program = $('#breeding_program_select').val();
77 var year = $('#year_select').val();
78 var location = $('#location_select').val();
79 var description = $('#genotyping_trial_description').val();
80 var name = $('#genotyping_trial_name').val();
81 var list_id = $('#accession_select_box_list_select').val();
84 alert("A name is required and it should be unique in the database. Please try again.");
89 var l = new CXGN.List();
90 if (! l.validate(list_id, 'accessions', true)) {
91 alert('The list contains elements that are not accessions.');
96 var elements = l.getList(list_id);
97 if (typeof elements == 'undefined' ) {
98 alert("There are no elements in the list provided.");
103 if (elements.length > 95) {
104 $('#working').dialog("close");
105 alert("The list needs to have less than 96 elements (one well is reserved for the BLANK). Please use another list.");
110 $('#working').dialog("open");
113 url: '/ajax/breeders/genotypetrial',
114 data: { 'location': location, 'breeding_program': breeding_program, 'year': year, 'description': description, 'name': name, 'list_id':list_id },
115 success : function(response) {
116 if (response.error) {
117 alert(response.error);
118 $('#working').dialog("close");
121 alert(response.message);
122 $('#genotyping_trial_dialog').dialog("close");
123 $('#working').dialog("close");
124 window.location.href = "/breeders/trial/"+response.trial_id;
127 error: function(response) {
128 alert('An error occurred trying the create the layout.');
129 $('#working').dialog("close");
134 jQuery('#genotyping_trial_dialog').bind("dialogopen", function displayMenu() {
135 var l = new CXGN.List();
136 var html = l.listSelect('accession_select_box', [ 'accessions', 'plots' ]);
137 $('#accession_select_box_span').html(html);
140 function open_genotyping_trial_dialog () {
141 $('#genotyping_trial_dialog').dialog("open");
144 $('#create_genotyping_trial_link').click(function () {
145 open_genotyping_trial_dialog();
148 ///////////////////////////////////////////////////////////////
150 // $('#igd_genotyping_trial_dialog').dialog( {
154 // position: ['top', 150],
155 // title: 'Create an IGD genotyping trial',
159 // id: 'genotype_trial_submit_button',
160 // click: function() {
161 // submit_igd_genotype_trial();
166 // id: 'genotype_trial_cancel_button',
167 // click: function() {
168 // $('#igd_genotyping_trial_dialog').dialog("close");
174 $('#add_igd_geno_trial_submit').click(function () {
175 submit_igd_genotype_trial();
178 function submit_igd_genotype_trial() {
179 var breeding_program = $('#breeding_program_select').val();
180 var year = $('#year_select').val();
181 var location = $('#location_select').val();
182 var description = $('#genotyping_trial_description').val();
183 var name = $('#genotyping_trial_name').val();
184 var list_id = $('#igd_accession_select_box_list_select').val();
187 // alert("A name is required and it should be unique in the database. Please try again.");
190 // note: taking name from file
192 var l = new CXGN.List();
193 if (! l.validate(list_id, 'accessions', true)) {
194 alert('The list contains elements that are not accessions.');
198 var elements = l.getList(list_id);
199 if (typeof elements == 'undefined' ) {
200 alert("There are no elements in the list provided.");
204 if (elements.length > 95) {
205 $('#working_modal').modal("show");
206 alert("The list needs to have less than 96 elements (one well is reserved for the BLANK). Please use another list.");
211 $('#working_modal').modal("show");
213 $('#upload_igd_genotyping_trials_form').append('<input type="hidden" name="list_id" value="'+list_id+'">');
214 $('#upload_igd_genotyping_trials_form').append('<input type="hidden" name="year" value="'+year+'">');
215 $('#upload_igd_genotyping_trials_form').append('<input type="hidden" name="breeding_program" value="'+breeding_program+'">');
216 $('#upload_igd_genotyping_trials_form').append('<input type="hidden" name="location" value="'+location+'">');
219 // url: '/ajax/breeders/igdgenotypetrial',
220 // data: { 'location': location, 'breeding_program': breeding_program, 'year': year, 'description': description, 'name': name, 'list_id':list_id },
221 // success : function(response) {
222 // if (response.error) {
223 // alert(response.error);
224 // $('#working').dialog("close");
227 // alert(response.message);
228 // $('#genotyping_trial_dialog').dialog("close");
229 // $('#working').dialog("close");
230 // window.location.href = "/breeders/trial/"+response.trial_id;
233 // error: function(response) {
234 // alert('An error occurred trying the create the layout.');
235 // $('#working').dialog("close");
239 $("#upload_igd_genotyping_trials_form").submit();
244 $('#upload_igd_genotyping_trials_form').iframePostForm({
247 var uploadedGenotypingFile = $("#igd_genotyping_trial_upload_file").val();
248 $('#working_modal').modal("show");
249 if (uploadedGenotypingFile === '') {
250 $('#working_modal').modal("hide");
251 alert("Please select a file to upload.");
255 complete: function (response) {
256 //var response_json = JSON.stringify(response);
257 //alert(response_json);
258 $('#working_modal').modal("hide");
259 if (response.error) {
260 var error = response.error;
261 $('#working_modal').modal("hide");
262 // if (response.error) {
263 // $("#upload_genotyping_error_display tbody").html('');
264 // $("#upload_genotyping_error_display tbody").append(response.error_string);
268 // $("#upload_genotyping_error_display").dialog({
272 // position: ['top', 250],
273 // title: "Errors in uploaded file",
276 // $(this).dialog("close");
283 if (response.error) {
287 if (response.success) {
288 //$('#genotyping_upload_success_dialog_message').dialog("open");
289 //alert("File uploaded successfully");
292 alert("Successfully stored the trial.");
293 window.location.href = "/breeders/trial/"+response.trial_id;
298 $('#igd_genotyping_trial_dialog').on('show.bs.modal', function (e) {
299 var l = new CXGN.List();
300 var html = l.listSelect('igd_accession_select_box', [ 'accessions', 'plots' ]);
301 $('#igd_accession_select_box_span').html(html);
304 // jQuery('#igd_genotyping_trial_dialog').bind("dialogopen", function displayMenu() {
305 // var l = new CXGN.List();
306 // var html = l.listSelect('igd_accession_select_box', [ 'accessions', 'plots' ]);
307 // $('#igd_accession_select_box_span').html(html);
311 function open_igd_genotyping_trial_dialog () {
312 $('#igd_genotyping_trial_dialog').modal("show");
315 $('#create_igd_genotyping_trial_link').click(function() {
316 open_igd_genotyping_trial_dialog();
319 $('#delete_layout_data_by_trial_id').click(function() {
320 var trial_id = get_trial_id();
321 var yes = confirm("Are you sure you want to delete this experiment with id "+trial_id+" ? This action cannot be undone.");
323 jQuery('#working_modal').modal("show");
324 var html = jQuery('#working_msg').html();
325 jQuery('#working_msg').html(html+"Deleting genotyping experiment...<br />");
328 url: '/ajax/breeders/trial/'+trial_id+'/delete/layout',
329 success: function(response) {
330 if (response.error) {
331 jQuery('#working_modal').modal("hide");
332 alert(response.error);
335 //Do nothing, as the process continues...
338 error: function(response) {
339 jQuery('#working_modal').modal("hide");
340 alert("An error occurred.");
343 html = jQuery('#working_msg').html();
344 jQuery('#working_msg').html(html+"Removing the project entry...");
347 url: '/ajax/breeders/trial/'+trial_id+'/delete/entry',
348 success: function(response) {
349 if (response.error) {
350 jQuery('#working_modal').modal("hide");
351 alert(response.error);
354 jQuery('#working_modal').modal("hide");
355 alert('The project entry has been deleted.'); // to do: give some idea how many items were deleted.
356 window.location.href="/breeders/trial/"+trial_id;
359 error: function(response) {
360 jQuery('#working_modal').modal("hide");
361 alert("An error occurred.");