diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 905ca3c..85396a9 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -36,34 +36,39 @@ def create if user_signed_in? then @plan = Plan.new - authorize @plan @plan.save + authorize @plan - funder_id = params[:plan][:funder_id] - if !funder_id.blank? - # get all funder @templates - funder = Org.find(params[:plan][:funder_id]) - @templates = get_most_recent( funder.templates.where("published = ?", true).all ) - - orgtemplates = current_user.org.templates.all - replacements = [] - - # replace any that are customised by the org - orgtemplates.each do |orgt| - base_template = orgt.customization_of - @templates.delete(base_template) - replacements << orgt - end - @templates + replacements - + if params[:template_id] + @templates = [ Template.find(params[:template_id] ) ] else - # get all org @templates which are not customisations - @templates = current_user.org.templates.where(customization_of: nil) - # if none of these get the basic dcc template - if @templates.blank? - @templates = Template.find_by_is_default(true) - end + funder_id = params[:plan][:funder_id] + if !funder_id.blank? + # get all funder @templates + funder = Org.find(params[:plan][:funder_id]) + @templates = get_most_recent( funder.templates.where("published = ?", true).all ) + + orgtemplates = current_user.org.templates.all + replacements = [] + + # replace any that are customised by the org + orgtemplates.each do |orgt| + base_template = orgt.customization_of + @templates.delete(base_template) + replacements << orgt + end + @templates + replacements + + else + # get all org @templates which are not customisations + @templates = current_user.org.templates.where(customization_of: nil) + + # if none of these get the basic dcc template + if @templates.blank? + @templates = Template.find_by_is_default(true) + end + end end # if we have more than one template then back to the user @@ -89,7 +94,6 @@ respond_to do |format| if @plan.save - #format.html { redirect_to({:action => "show", :id => @plan.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } format.html { redirect_to({:action => "show", :id => @plan.id, :editing => true }, {:notice => _('Plan was successfully created.')}) } else @error = "Something went wrong" diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb index 9eec2dc..98e6fd5 100644 --- a/app/views/plans/_plan_details.html.erb +++ b/app/views/plans/_plan_details.html.erb @@ -16,7 +16,7 @@

- <%= _('helpers.links.cancel') %> + <%= _('Cancel') %>
@@ -76,7 +76,7 @@ <%= f.actions do %>
<%= f.submit _('Save'), :class => 'btn btn-primary' %> - <%= _('helpers.links.cancel') %> + <%= _('Cancel') %>
<%end%> <%end%> diff --git a/app/views/plans/create.html.erb b/app/views/plans/create.html.erb index b1ef328..3482890 100644 --- a/app/views/plans/create.html.erb +++ b/app/views/plans/create.html.erb @@ -1,14 +1,21 @@
-

Choose one of these templates

+

Choose one of these templates:

-<%= debug @templates %> -<% @templates.each do |t| %> -

<%= t %> +<%= form_tag(controller: "plans", action: "create", method: "post", class: "choose_template_form") do %> +

+ <%= submit_tag("Create Plan") %> <% end %> +
- - diff --git a/config/environments/production.rb b/config/environments/production.rb index 1128592..76a2c35 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -64,6 +64,9 @@ # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false + # Set default host for mailer URLs + # config.action_mailer.default_url_options = {host: "example.com"} + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true diff --git a/lib/assets/javascripts/projects.js b/lib/assets/javascripts/projects.js index 9e1c870..c32016c 100644 --- a/lib/assets/javascripts/projects.js +++ b/lib/assets/javascripts/projects.js @@ -1,116 +1,5 @@ $( document ).ready(function() { $(".select2-container").select2(); - - // ---------------------------------------------------------- - $("#plan_funder_id").change(function(){ - -// if($(this).select2().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 option:selected").text()); - getTemplateList(); - }); - - // ---------------------------------------------------------- - $("#project_institution_idX").change(function(){ - reloadTemplateData(); - - $("#confirm-institution").text($("#project_institution_id option:selected").text()); - }); - - // ---------------------------------------------------------- - $("#project_dmptemplate_idX").change(function(){ - reloadGuidanceOptions(); - }); - - // ---------------------------------------------------------- - $("#no-funderX").click(function(e) { - e.preventDefault(); - // For some reason we need to access the select2 box's value again to get the - // UI to update correctly - $("#project_funder_id").select2().val(""); - $("#project_funder_id").select2().val(); - - $("#institution-control-group").show(); - $("#create-plan-button").show(); - $("#other-funder-name").show(); - $("#confirm-funder").text(I18n.t("helpers.none")); - reloadTemplateData(); - }); - - // ---------------------------------------------------------- - $("#project_funder_nameX").change(function(){ - $("#confirm-funder").text($("#project_funder_id :selected").text()); - reloadTemplateData(); - }); - - // ---------------------------------------------------------- - $("#no-institutionX").click(function() { - // For some reason we need to access the select2 box's value again to get the - // UI to update correctly - $("#project_institution_id").select2().val(""); - $("#project_institution_id").select2().val(); - - $("#confirm-institution").text(I18n.t("helpers.none")); - }); - - // ---------------------------------------------------------- - $("#project-confirmation-dialogX").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("
  • "+$(this).parent().text()+"
  • "); - }); - $('.select2-choice').hide(); - }); - - // ---------------------------------------------------------- - $("#new-project-cancelledX").click(function (){ - $("#project-confirmation-dialog").modal("hide"); - $('.select2-choice').show(); - }); - - // ---------------------------------------------------------- - $("#new-project-confirmedX").click(function (){ - $("#new_project").submit(); - }); - - // ---------------------------------------------------------- - //for the default template alert - $("#default-template-confirmation-dialogX").on("show", function(){ - $('.select2-choice').hide(); - }); - - // ---------------------------------------------------------- - $("#default-template-cancelledX").click(function (){ - $("#default-template-confirmation-dialog").modal("hide"); - $('.select2-choice').show(); - }); - - // ---------------------------------------------------------- - $("#default-template-confirmedX").click(function (){ - $("#default_tag").val('true'); - $("#new_project").submit(); - }); - // The following function references a JSON array that is // constructed in app/view/projects/_dropdown_new_project.html.erb diff --git a/lib/assets/stylesheets/bootstrap_and_overrides.css.less b/lib/assets/stylesheets/bootstrap_and_overrides.css.less index fee94ab..c8a9992 100644 --- a/lib/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/lib/assets/stylesheets/bootstrap_and_overrides.css.less @@ -759,6 +759,10 @@ margin-left: 10px; } +#choose-template label { + display: inline +} + .sign_up_org_label{ margin: 0 0 6px 0;