2 * trials search, selections to combine etc...
3 * @author Isaak Y Tecle <iyt2@cornell.edu>
8 JSAN.use('jquery.blockUI');
11 function getPopIds () {
13 var searchedPopsList = jQuery("#searched_trials_table tr").length;
17 if (searchedPopsList) {
18 tableId = 'searched_trials_table';
20 tableId = 'all_trials_table';
23 jQuery('#' +tableId + ' tr').filter(':has(:checkbox:checked)')
24 .bind('click', function() {
26 jQuery("#done_selecting").val('Done selecting');
27 var td = jQuery(this).html();
29 var selectedTrial = '<tr>' + td + '</tr>';
31 jQuery("#selected_trials_table tr:last").after(selectedTrial);
33 jQuery("#selected_trials_table tr").each( function() {
34 jQuery(this).find("input[type=checkbox]")
35 .attr('onclick', 'removeSelectedTrial()')
36 .prop('checked', true);
40 jQuery("#selected_trials").show();
41 jQuery("#combine_trials_div").show();
42 jQuery("#search_again_div").show();
47 jQuery(document).ready(function() {
48 jQuery('#done_selecting').on('click', function() {
55 function hideTrialsList() {
56 jQuery("#all_trials_div").empty();
57 jQuery("#searched_trials_div").empty();
58 jQuery("#done_selecting_div").hide();
59 jQuery("#all_trials_search_message").hide();
64 function removeSelectedTrial() {
66 jQuery("#selected_trials_table tr").on("change", function() {
68 jQuery(this).remove();
70 if (jQuery("#selected_trials_table td").length == 0) {
71 jQuery("#selected_trials").hide();
72 jQuery("#combine_trials_div").hide();
73 jQuery("#search_again_div").hide();
74 jQuery("#done_selecting").val('Select');
83 jQuery(document).ready(function() {
84 jQuery('#search_again').on('click', function() {
91 function searchAgain () {
93 var url = window.location.pathname;
95 if (url.match(/solgs\/search\/trials\/trait\//) != null) {
96 var traitId = jQuery("input[name='trait_id']").val();
97 url = '/solgs/search/result/populations/' + traitId;
99 url = '/solgs/search/trials/';
102 jQuery('#all_trials_div').empty();
103 jQuery("#searched_trials_div").empty();
104 searchAllTrials(url);
105 jQuery("#all_trials_search_message").show();
106 jQuery("#done_selecting_div").show();
107 jQuery("#done_selecting").val('Select');
112 jQuery(document).ready(function() {
113 jQuery('#combine_trait_trials').on('click', function() {
114 //combineTraitTrials();
121 function combineTraitTrials () {
122 var trId = getTraitId();
124 var trialIds = getSelectedTrials();
126 var action = "/solgs/combine/populations/trait/" + trId;
127 var selectedPops = trId + "=" + trialIds + '&' + 'combine=combine';
129 jQuery.blockUI.defaults.applyPlatformOpacityRules = false;
130 jQuery.blockUI({message: 'Please wait..'});
137 success: function(res) {
141 var comboPopsId = res.combo_pops_id;
142 var newUrl = '/solgs/model/combined/populations/' + comboPopsId + '/trait/' + trId;
145 window.location.href = newUrl;
147 } else if (res.redirect_url) {
148 goToSingleTrialPage(res.redirect_url);
154 if (res.not_matching_pops){
155 alert('populations ' + res.not_matching_pops +
156 ' were genotyped using different marker sets. ' +
157 'Please make new selections to combine.' );
158 window.location.href = '/solgs/search/result/populations/' + trId;
161 if (res.redirect_url) {
162 window.location.href = res.redirect_url;
171 jQuery(document).ready(function() {
172 jQuery('#combine_trials').on('click', function() {
179 function getCombinedPopsId() {
181 var comboPopsList = getSelectedTrials();
182 var trialsIds = comboPopsList.join(",");
183 var traitId = getTraitId();
184 var action = "/solgs/get/combined/populations/id";
190 data: {'trials': trialsIds},
191 success: function(res) {
193 var comboPopsId = res.combo_pops_id;
195 if (window.Prototype) {
196 delete Array.prototype.toJSON;
200 'combo_pops_id' : [ comboPopsId ],
201 'combo_pops_list' : comboPopsList,
202 'analysis_type' : 'combine populations',
203 'data_set_type' : 'multiple populations',
204 'trait_id' : traitId,
207 var referer = window.location.href;
210 if (referer.match(/search\/trials\/trait\//)) {
211 page = '/solgs/model/combined/trials/' + comboPopsId + '/trait/' + traitId;
214 page = '/solgs/populations/combined/' + comboPopsId;
217 solGS.waitPage(page, args);
220 error: function(res) {
221 //combinedPopsId = 0;
225 // return combinedPopsId;
230 function retrievePopsData() {
232 var trialsIds = getSelectedTrials();
233 trialsIds = trialsIds.join(",");
235 var action = "/solgs/retrieve/populations/data";
237 jQuery.blockUI.defaults.applyPlatformOpacityRules = false;
238 jQuery.blockUI({message: 'Please wait..'});
244 data: {'trials': trialsIds},
245 success: function(res) {
246 if (res.not_matching_pops == null) {
248 var combinedPopsId = res.combined_pops_id;
251 goToCombinedTrialsPage(combinedPopsId);
253 }else if (res.redirect_url) {
254 goToSingleTrialPage(res.redirect_url);
258 } else if(res.not_matching_pops ) {
261 alert('populations ' + res.not_matching_pops +
262 ' were genotyped using different marker sets. ' +
263 'Please make new selections to combine.' );
267 error: function(res) {
269 alert('An error occured retrieving phenotype' +
270 'and genotype data for trials..');
276 function getSelectedTrials () {
280 if (jQuery("#selected_trials_table").length) {
281 jQuery("#selected_trials_table tr").each(function () {
282 var trialId = jQuery(this).find("input[type=checkbox]").val();
285 trialIds.push(trialId);
290 trialIds = trialIds.sort();
297 function goToCombinedTrialsPage(combinedPopsId) {
299 var action = '/solgs/populations/combined/' + combinedPopsId;
301 if (combinedPopsId) {
302 window.location.href = action;
307 function goToSingleTrialPage(url) {
310 window.location.href = url;
315 function getTraitId() {
317 var id = jQuery("input[name='trait_id']").val();
322 Array.prototype.unique =
326 for(var i=0; i<l; i++) {
327 for(var j=i+1; j<l; j++) {
328 // If this[i] is fo3und later in the array
329 if (this[i] === this[j])