3 * general solGS app wide and misc functions
4 * @author Isaak Y Tecle <iyt2@cornell.edu>
9 JSAN.use('jquery.blockUI');
10 JSAN.use('jquery.form');
13 var solGS = solGS || function solGS () {};
15 solGS.waitPage = function (page, args) {
17 var matchItems = 'solgs/population/'
18 + '|solgs/populations/combined/'
20 + '|solgs/model/combined/trials/'
21 + '|solgs/search/trials/trait/'
22 + '|solgs/model/\\d+/prediction/'
23 + '|solgs/analyze/traits/';
25 if (page.match(matchItems)) {
33 function askUser(page, args) {
35 var t = '<p>This analysis may take longer than 20 min. '
36 + 'Would you like to be emailed when it is done?</p>';
44 title : "Analysis job submission",
48 class: 'btn btn-success',
50 jQuery(this).dialog("close");
52 checkUserLogin(page, args);
57 text: 'No, I will wait...',
58 class: 'btn btn-primary',
60 jQuery(this).dialog("close");
62 displayAnalysisNow(page, args);
68 class: 'btn btn-info',
70 jQuery(this).dialog("close");
79 function checkUserLogin (page, args) {
81 if (args === undefined) {
88 url : '/solgs/check/user/login/',
89 success : function(response) {
90 if (response.loggedin) {
91 var contact = response.contact;
93 args['user_name'] = contact.name;
94 args['user_email'] = contact.email;
96 getProfileDialog(page, args);
107 function loginAlert () {
110 .html('To use this feature, you need to log in and start over the process.')
119 jQuery(this).dialog('close');
122 class: 'btn btn-success',
128 jQuery(this).dialog('close');
130 class: 'btn btn-primary',
139 function loginUser () {
141 window.location = '/solpeople/login.pl?goto_url=' + window.location.pathname;
146 function displayAnalysisNow (page, args) {
148 blockPage(page, args);
153 function blockPage (page, args) {
155 goToPage(page, args);
157 jQuery.blockUI.defaults.applyPlatformOpacityRules = false;
158 jQuery.blockUI({message: 'Please wait..'});
160 jQuery(window).unload(function() {
167 function goToPage (page, args) {
169 var matchItems = 'solgs/population/'
170 + '|solgs/confirm/request'
172 + '|solgs/model/combined/trials/'
173 + '|solgs/model/\\d+/prediction/';
175 var multiTraitsUrls = 'solgs/analyze/traits/population/'
176 + '|solgs/models/combined/trials/';
178 if (page.match(matchItems)) {
180 window.location = page;
182 } else if (page.match(multiTraitsUrls)) {
184 submitTraitSelections(page, args);
186 } else if (page.match(/solgs\/populations\/combined\//)) {
188 //window.location = page;
191 window.location = window.location.href;
197 function submitTraitSelections (page, args) {
201 if (args == 'undefined') {
202 document.getElementById('traits_selection_form').submit();
203 document.getElementById('traits_selection_form').reset();
205 jQuery('#traits_selection_form').ajaxSubmit();
206 jQuery('#traits_selection_form').resetForm();
211 function wrapTraitsForm () {
213 var popId = jQuery('#population_id').val();
214 var formId = ' id="traits_selection_form"';
217 var referer = window.location.href;
219 if ( referer.match(/solgs\/populations\/combined\//) ) {
220 action = ' action="/solgs/models/combined/trials/' + popId + '"';
223 if ( referer.match(/solgs\/population\//) ) {
224 action = ' action="/solgs/analyze/traits/population/' + popId + '"';
227 var method = ' method="POST"';
229 var traitsForm = '<form'
236 jQuery('#population_traits_list').wrap(traitsForm);
241 function getProfileDialog (page, args) {
243 var matchItems = '/solgs/population/'
245 + '|solgs/model/combined/trials/'
246 + '|solgs/model/\\d+/prediction/';
248 if (page.match(matchItems) ) {
250 args = getArgsFromUrl(page, args);
253 var form = getProfileForm(args);
255 jQuery('<div />', {id: 'email-form'})
261 title : 'Info about your analysis.',
266 var userName = jQuery("#user_name").val();
267 var userEmail = jQuery("#user_email").val();
269 var analysisName = jQuery('#analysis_name').val();
270 var analysisType = args.analysis_type;
272 var dataSetType = args.data_set_type;
274 args['user_email'] = userEmail;
275 args = JSON.stringify(args);
277 var analysisProfile = {
278 'user_name' : userName,
279 'user_email' : userEmail,
280 'analysis_name': analysisName,
281 'analysis_page': page,
282 'analysis_type': analysisType,
283 'data_set_type': dataSetType,
287 jQuery(this).dialog('close');
289 saveAnalysisProfile(analysisProfile);
291 class: 'btn btn-success',
297 jQuery(this).dialog('close');
299 class: 'btn btn-primary',
308 function getArgsFromUrl (url, args) {
310 if (window.Prototype) {
311 delete Array.prototype.toJSON;
314 if (url.match(/solgs\/trait\//)) {
316 var urlStr = url.split(/\/+/);
318 if (args === undefined) {
320 args = {'trait_id' : [ urlStr[4] ],
321 'population_id' : [ urlStr[6] ],
322 'analysis_type' : 'single model',
323 'data_set_type' : 'single population',
328 args['trait_id'] = [ urlStr[4] ];
329 args['population_id'] = [ urlStr[6] ];
330 args['analysis_type'] = 'single model';
331 args['data_set_type'] = 'single population';
334 } else if (url.match(/solgs\/model\/combined\/trials\//)) {
336 var urlStr = url.split(/\/+/);
339 var populationId = [];
340 var comboPopsId = [];
342 var referer = window.location.href;
344 if (referer.match(/solgs\/search\/trials\/trait\//)) {
346 populationId.push(urlStr[5]);
347 comboPopsId.push(urlStr[5]);
348 traitId.push(urlStr[7]);
350 else if (referer.match(/solgs\/populations\/combined\//)) {
352 populationId.push(urlStr[6]);
353 comboPopsId.push(urlStr[6]);
354 traitId.push(urlStr[8]);
357 if (args === undefined) {
359 args = {'trait_id' : traitId,
360 'population_id' : populationId,
361 'combo_pops_id' : comboPopsId,
362 'analysis_type' : 'single model',
363 'data_set_type' : 'combined populations'};
366 args['trait_id'] = traitId;
367 args['population_id'] = populationId;
368 args['combo_pops_id'] = comboPopsId;
369 args['analysis_type'] = 'single model';
370 args['data_set_type'] = 'combined populations';
372 } else if (url.match(/solgs\/population\//)) {
374 var urlStr = url.split(/\/+/);
376 if (args === undefined) {
378 'population_id' : [ urlStr[4] ],
379 'analysis_type' : 'population download',
380 'data_set_type' : 'single population'
383 args['population_id'] = [ urlStr[4] ];
384 args['analysis_type'] = 'population download';
385 args['data_set_type'] = 'single population';
387 } else if (url.match(/solgs\/model\/\d+\/prediction\//)) {
389 var traitId = jQuery('#trait_id').val();
390 var modelId = jQuery('#model_id').val();
391 var urlStr = url.split(/\/+/);
395 if (window.location.href.match(/solgs\/model\/combined\/populations\//)) {
396 dataSetType = 'combined populations';
397 } else if (window.location.href.match(/solgs\/trait\/|solgs\/traits\/all\/population\//)) {
398 dataSetType = 'single population';
401 if (args === undefined) {
404 'trait_id' : [ traitId ],
405 'training_pop_id' : [ urlStr[4] ],
406 'selection_pop_id' : [ urlStr[6] ],
407 'analysis_type' : 'selection prediction',
408 'data_set_type' : dataSetType,
412 args['trait_id'] = [ traitId ];
413 args['training_pop_id'] = [ urlStr[4] ];
414 args['selection_pop_id'] = [ urlStr[6] ];
415 args['analysis_type'] = 'selection prediction';
416 args['data_set_type'] = dataSetType;
425 function getProfileForm (args) {
428 if (args.user_email) {
429 email = args.user_email;
433 if (args.user_name) {
434 userName = args.user_name;
437 var emailForm = '<p>Please fill in your:</p>'
438 + '<div class="form-group">'
439 + '<table class="table">'
442 + '<td><input type="text" class="form-control" name="user_name" id="user_name" value=\"' + userName + '\"/></td>'
445 + '<td>Analysis name:</td>'
446 + '<td><input type="text" class="form-control" name="analysis_name" id="analysis_name"></td>'
450 + '<td><input type="text" class="form-control" name="user_email" id="user_email" value=\"' + email + '\"/></td>'
460 function saveAnalysisProfile (profile) {
466 url : '/solgs/save/analysis/profile/',
467 success : function(response) {
468 if (response.result) {
469 runAnalysis(profile);
473 jQuery('<div />', {id: 'error-message'})
474 .html('Failed saving your analysis profile.')
479 title : 'Error message',
482 jQuery(this).dialog('close');
483 window.location = window.location.href;
491 .html('Error occured calling the function to save your analysis profile.')
496 title : 'Error message',
499 jQuery(this).dialog('close');
500 window.location = window.location.href;
510 function runAnalysis (profile) {
516 url : '/solgs/run/saved/analysis/',
522 function confirmRequest () {
524 blockPage('/solgs/confirm/request');
531 jQuery(document).ready(function (){
533 jQuery('#runGS').on('click', function() {
539 var hostName = window.location.protocol
541 + window.location.host;
543 var referer = window.location.href;
545 if ( referer.match(/solgs\/populations\/combined\//) ) {
547 dataSetType = 'combined populations';
550 if ( referer.match(/solgs\/population\//) ) {
552 dataSetType = 'single population';
555 var traitIds = jQuery("#traits_selection_div :checkbox").fieldValue();
556 var popId = jQuery('#population_id').val();
558 if (traitIds.length == 1 ) {
560 analysisType = 'single model';
562 if ( referer.match(/solgs\/populations\/combined\//) ) {
565 + '/solgs/model/combined/trials/'
570 } else if ( referer.match(/solgs\/population\//)) {
581 analysisType = 'multiple models';
583 if ( referer.match(/solgs\/populations\/combined\//) ) {
585 + '/solgs/models/combined/trials/'
591 + '/solgs/analyze/traits/population/'
596 var args = {'trait_id' : traitIds,
597 'population_id' : [ popId ],
598 'analysis_type' : analysisType,
599 'data_set_type' : dataSetType,
602 solGS.waitPage(page, args);
609 solGS.getTraitDetails = function (traitId) {
612 traitId = jQuery("#trait_id").val();
619 data : {'trait_id': traitId},
620 url : '/solgs/details/trait/' + traitId,
621 success: function (trait) {
622 jQuery(document.body)
623 .append('<input type="hidden" id="trait_name" value="'
624 + trait.name + '"></input>');
625 jQuery(document.body)
626 .append('<input type="hidden" id="trait_abbr" value="'
627 + trait.abbr + '"></input>');
635 solGS.getPopulationDetails = function () {
637 var populationId = jQuery("#population_id").val();
638 var populationName = jQuery("#population_name").val();
640 var selectionPopId = jQuery("#selection_pop_id").val();
641 var selectionPopName = jQuery("#selection_pop_name").val();
643 if (populationId == 'undefined') {
644 populationId = jQuery("#model_id").val();
645 populationName = jQuery("#model_name").val();
649 populationId = jQuery("#combo_pops_id").val();
652 return {'population_id' : populationId,
653 'training_pop_id' : populationId,
654 'population_name' : populationName,
655 'training_pop_name' : populationName,
656 'selection_pop_id' : selectionPopId,
657 'selection_pop_name': selectionPopName,
661 //executes two functions alternately
662 jQuery.fn.alternateFunctions = function(a, b) {
663 return this.each(function() {
665 jQuery(this).bind("click", function() {
668 return b.apply(this, arguments);
672 return a.apply(this, arguments);