|
|
@ -1,7 +1,8 @@ |
|
|
|
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] |
|
|
|
before_action :find_resource_by_named_id, except: %i[submit_form review show_new_page] |
|
|
|
|
|
|
|
before_action :create_new_resource, only: %i[show_new_page] |
|
|
|
|
|
|
|
|
|
|
|
def submit_form |
|
|
|
def submit_form |
|
|
|
if @log |
|
|
|
if @log |
|
|
@ -13,7 +14,7 @@ class FormController < ApplicationController |
|
|
|
session[:errors] = session[:fields] = nil |
|
|
|
session[:errors] = session[:fields] = nil |
|
|
|
redirect_to(successful_redirect_path) |
|
|
|
redirect_to(successful_redirect_path) |
|
|
|
else |
|
|
|
else |
|
|
|
redirect_path = "#{@log.model_name.param_key}_#{@page.id}_path" |
|
|
|
redirect_path = @log.status == "not_started" ? "#{@log.model_name.param_key}s_new_#{@page.id}_path" : "#{@log.model_name.param_key}_#{@page.id}_path" |
|
|
|
mandatory_questions_with_no_response.map do |question| |
|
|
|
mandatory_questions_with_no_response.map do |question| |
|
|
|
@log.errors.add question.id.to_sym, question.unanswered_error_message |
|
|
|
@log.errors.add question.id.to_sym, question.unanswered_error_message |
|
|
|
end |
|
|
|
end |
|
|
@ -62,7 +63,6 @@ class FormController < ApplicationController |
|
|
|
|
|
|
|
|
|
|
|
def show_new_page |
|
|
|
def show_new_page |
|
|
|
page_id = request.path.split("/")[-1].underscore |
|
|
|
page_id = request.path.split("/")[-1].underscore |
|
|
|
save_new_log page_id |
|
|
|
|
|
|
|
if @log |
|
|
|
if @log |
|
|
|
restore_error_field_values |
|
|
|
restore_error_field_values |
|
|
|
page_id = request.path.split("/")[-1].underscore |
|
|
|
page_id = request.path.split("/")[-1].underscore |
|
|
@ -159,6 +159,14 @@ private |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_new_resource |
|
|
|
|
|
|
|
@log = if request.path.include?("sales-logs") |
|
|
|
|
|
|
|
SalesLog.new |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LettingsLog.new |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def new_log_request? |
|
|
|
def new_log_request? |
|
|
|
request.path.split("/").include?("new") |
|
|
|
request.path.split("/").include?("new") |
|
|
|
end |
|
|
|
end |
|
|
|