Browse Source

wip more

CLDC-1324
Kat 2 years ago
parent
commit
02ae69dd16
  1. 35
      app/controllers/form_controller.rb
  2. 4
      config/routes.rb

35
app/controllers/form_controller.rb

@ -1,8 +1,7 @@
class FormController < ApplicationController class FormController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :find_resource, only: %i[submit_form review] before_action :find_resource, only: %i[submit_form review]
before_action :find_resource_by_named_id, except: %i[submit_form review show_new_page] before_action :find_resource_by_named_id, except: %i[submit_form review]
before_action :create_new_resource, only: %i[show_new_page]
def submit_form def submit_form
if @log if @log
@ -61,33 +60,9 @@ class FormController < ApplicationController
end end
end end
def show_new_page
page_id = request.path.split("/")[-1].underscore
if @log
restore_error_field_values
page_id = request.path.split("/")[-1].underscore
@page = @log.form.get_page(page_id)
@subsection = @log.form.subsection_for_page(@page)
if @page.routed_to?(@log, current_user)
render "form/page"
else
redirect_to lettings_log_path(@log)
end
else
render_not_found
end
end
private private
def save_new_log(page_id)
if current_user.support?
@log.save! unless page_id.eql?("organisation") && @log.id.nil?
else
@log.save! unless page_id.eql?("needs_type") && @log.id.nil?
end
end
def restore_error_field_values def restore_error_field_values
if session["errors"] if session["errors"]
JSON(session["errors"]).each do |field, messages| JSON(session["errors"]).each do |field, messages|
@ -149,18 +124,14 @@ private
@log = if params[:sales_log_id].present? @log = if params[:sales_log_id].present?
current_user.sales_logs.find_by(id: params[:sales_log_id]) current_user.sales_logs.find_by(id: params[:sales_log_id])
elsif new_log_request? elsif new_log_request?
if request.path.include?("sales-logs") create_new_resource
SalesLog.new
else
LettingsLog.new
end
else else
current_user.lettings_logs.find_by(id: params[:lettings_log_id]) current_user.lettings_logs.find_by(id: params[:lettings_log_id])
end end
end end
def create_new_resource def create_new_resource
@log = if request.path.include?("sales-logs") if request.path.include?("sales-logs")
SalesLog.new SalesLog.new
else else
LettingsLog.new LettingsLog.new

4
config/routes.rb

@ -31,8 +31,8 @@ Rails.application.routes.draw do
FormHandler.instance.forms.each do |_key, form| FormHandler.instance.forms.each do |_key, form|
form.pages.map do |page| form.pages.map do |page|
get "/lettings-logs/new/#{page.id.to_s.dasherize}", to: "form#show_new_page" get "/lettings-logs/new/#{page.id.to_s.dasherize}", to: "form#show_page"
get "/sales-logs/new/#{page.id.to_s.dasherize}", to: "form#show_new_page" get "/sales-logs/new/#{page.id.to_s.dasherize}", to: "form#show_page"
end end
end end

Loading…
Cancel
Save