var apply_default, check_search_term, dataset_info, group_info, make_default, open_window, populate_dataset, populate_group, populate_species, populate_type, process_json, redo_dropdown; process_json = function(data) { window.jdata = data; populate_species(); if ($('#type').length > 0) { //This is to determine if it's the index page or the submit_trait page (which only has species and group selection and no make default option) return apply_default(); } }; range = function(size, startAt=0) { return [...Array(size).keys()].map(idx => idx + startAt); }; indicate_error = function (jqXHR, textStatus, errorThrown) { errorElement = document.createElement("span"); errorElement.setAttribute("class", "alert-danger"); fallbackLink = document.createElement('a'); fallbackLink.href = "https://fallback.genenetwork.org"; fallbackLink.title = "GN2 Fallback"; fallbackLink.appendChild(document.createTextNode("GN2 Fallback Server.")); errorText = document.createTextNode( "There was an error retrieving and setting the menu. Try visiting the "); errorElement.appendChild(errorText); errorElement.appendChild(fallbackLink); if (document.getElementById("search")){ form = document.getElementById("search").getElementsByTagName("form")[0]; form.prepend(errorElement); disable_element = function(select) { select.setAttribute("disabled", "disabled"); }; Array.from(form.getElementsByTagName("select")).forEach(disable_element); Array.from(form.getElementsByTagName("textarea")).forEach(disable_element); } }; defaultStatusCodeFunctions = range(200, 400).reduce( function(acc, scode) { acc[scode] = indicate_error; return acc; }, {}); if (typeof gn_server_url === 'undefined'){ gn_server_url = $("#search form").attr("data-gn_server_url") } $.ajax(gn_server_url +'/menu/generate/json', { dataType: 'json', success: process_json, statusCode: { ...defaultStatusCodeFunctions, } }); populate_species = function() { var species_list; species_list = this.jdata.species; redo_dropdown($('#species'), species_list); return populate_group(); }; window.populate_species = populate_species; populate_group = function() { var group_list, species; species = $('#species').val(); group_list = this.jdata.groups[species]; for (_i = 0, _len = group_list.length; _i < (_len - 1); _i++) { if (group_list[_i][0] == "BXD300"){ group_list.splice(_i, 1) } } redo_dropdown($('#group'), group_list); if ($('#type').length > 0) { //This is to determine if it's the index page or the submit_trait page (which only has species and group selection and no make default option) return populate_type(); } }; window.populate_group = populate_group; populate_type = function() { var group, species, type_list; species = $('#species').val(); group = $('#group').val(); type_list = this.jdata.types[species][group]; redo_dropdown($('#type'), type_list); return populate_dataset(); }; window.populate_type = populate_type; populate_dataset = function() { var dataset_list, group, species, type; species = $('#species').val(); group = $('#group').val(); type = $('#type').val(); dataset_list = this.jdata.datasets[species][group][type]; return redo_dropdown($('#dataset'), dataset_list); }; window.populate_dataset = populate_dataset; redo_dropdown = function(dropdown, items) { var item, _i, _len, _results; dropdown.empty(); _results = []; if (dropdown.attr('id') == "species"){ species_family_list = []; for (_i = 0, _len = items.length; _i < _len; _i++) { item = items[_i]; species_family = item[2].toString() species_family_list.push([item[0], item[1], species_family]) } current_family = "" this_opt_group = null for (_i = 0, _len = species_family_list.length; _i < _len; _i++) { item = species_family_list[_i]; if (item[2] != "None" && current_family == ""){ current_family = item[2] this_opt_group = $("") this_opt_group.append($("") this_opt_group.append($("") this_opt_group.append($("") this_opt_group.append($("") this_opt_group.append($("") this_opt_group.append($("