diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 68c3667..3fd4b4e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -195,3 +195,25 @@ return false; } } + +/* --------------------------------------------------------------------------- */ +function selectItemsFromJsonArray(array, selector, array_of_values, callback){ + var out = []; + + if(!Array.isArray(array_of_values)){ + array_of_values = [array_of_values]; + } + + for(var i = 0; i < array.length; i++){ + if(array_of_values.indexOf('' + array[i][selector]) >= 0){ + out.push(array[i]); + } + } + + var selectionInterval = setInterval(function(){ + if(i >= array.length){ + clearInterval(selectionInterval); + callback(out); + } + }, 50); +} diff --git a/app/assets/javascripts/projects.js b/app/assets/javascripts/projects.js index c103f84..33c411c 100644 --- a/app/assets/javascripts/projects.js +++ b/app/assets/javascripts/projects.js @@ -1,169 +1,185 @@ $( document ).ready(function() { -/* - $("#project_funder_id").select2({ - placeholder: "Select a funder" - }); + $(".select2-container").select2(); + +/* + $("#project_funder_id").select2({ + placeholder: "Select a funder" + }); */ - $("#project_funder_id").change(function () { - update_template_options(); - update_guidance_options(); - if ($(this).val().length > 0) { - $("#other-funder-name").hide(); - $("#project_funder_name").val(""); - } - else { - $("#other-funder-name").show(); - } - $("#institution-control-group").show(); - $("#create-plan-button").show(); - $("#confirm-funder").text($("#project_funder_id").select2('data').text); - }); - - $("#no-funder").click(function(e) { - e.preventDefault(); - $("#project_funder_id").select2("val", ""); - update_template_options(); - update_guidance_options(); - $("#institution-control-group").show(); - $("#create-plan-button").show(); - $("#other-funder-name").show(); - $("#confirm-funder").text(I18n.t("helpers.none")); - }); - - $("#project_funder_name").change(function(){ - $("#confirm-funder").text($(this).val()); - }); - - $("#project_institution_id").change(function () { - update_template_options(); - update_guidance_options(); - $("#confirm-institution").text($("#project_institution_id").select2('data').text); - }); - - $("#no-institution").click(function() { - $("#project_institution_id").select2("val", ""); - update_template_options(); - update_guidance_options(); - $("#confirm-institution").text(I18n.t("helpers.none")); - }); - - $("#project_dmptemplate_id").change(function (f) { - update_guidance_options(); - $("#confirm-template").text($("#project_dmptemplate_id :selected").text()); - }); - - $("#project-confirmation-dialog").on("show", function(){ - if ($("#confirm-institution").text() == "") { - $("#confirm-institution").text(I18n.t("helpers.none")); - } - if ($("#confirm-funder").text() == "") { - $("#confirm-funder").text(I18n.t("helpers.none")); - } - if ($("#confirm-template").text() == "") { - $("#confirm-template").closest("div").hide(); - } - else { - $("#confirm-template").closest("div").show(); - } - $("#confirm-guidance").empty(); - $("input:checked").each(function(){ - $("#confirm-guidance").append("