Files
baclight/app/controllers/id_card/setup_controller.rb
T

108 lines
3.5 KiB
Ruby
Raw Normal View History

module IdCard
2026-03-20 10:46:53 -04:00
class SetupController < ApplicationController
2026-03-13 08:47:13 -04:00
before_action :set_employer_and_setup
# View Methods
2026-03-20 10:46:53 -04:00
def index
2026-05-06 13:28:16 -04:00
if @setup.provider_section.present? && !@setup.provider_section.default
employer_custom_options = @setup.provider_section
else
employer_custom_options = IdCard::ProviderSection.new(title: "#{@employer.name} Custom")
2026-03-13 08:47:13 -04:00
end
2026-05-06 13:28:16 -04:00
@provider_options = (IdCard::ProviderSection.where(default: true) + [employer_custom_options])
.compact.uniq.map { |option| [option.display_title, option.id || "99"] }
@rx_options = IdCard::RxSection.where.not(title: nil)
@rx_default = IdCard::RxSection.find_by(title: "FairosRx")
2026-03-20 10:46:53 -04:00
render :index
end
2026-03-20 10:46:53 -04:00
def update
if params[:id_card_setup]["provider_section_id"].include?("new|")
2026-03-13 08:47:13 -04:00
new_provider_section_params = IdCard::ProviderSection.permitted_params(params)
new_provider_section = IdCard::ProviderSection.create(new_provider_section_params)
2026-03-20 10:46:53 -04:00
params[:id_card_setup]["provider_section_id"] = new_provider_section.id
2026-03-13 08:47:13 -04:00
end
2026-03-20 10:46:53 -04:00
setup_params = IdCard::Setup.permitted_params(params)
if @setup.update(setup_params)
2026-03-13 08:47:13 -04:00
puts "sucess"
2026-03-20 10:46:53 -04:00
redirect_to employer_path(@employer.slug), notice: 'ID Card Setup was successfully updated.'
2026-03-13 08:47:13 -04:00
else
puts "fail"
2026-05-06 13:28:16 -04:00
if @setup.provider_section.present? && !@setup.provider_section.default
employer_custom_options = @setup.provider_section
else
employer_custom_options = IdCard::ProviderSection.new(title: "#{@employer.name} Custom")
end
@provider_options = (IdCard::ProviderSection.where(default: true) + [employer_custom_options])
.compact.uniq.map { |option| [option.display_title, option.id || "99"] }
@rx_options = IdCard::RxSection.all
@rx_default = IdCard::RxSection.find_by(title: "FairosRx")
2026-03-20 10:46:53 -04:00
render :index, status: :unprocessable_entity
2026-03-13 08:47:13 -04:00
end
end
2026-03-13 08:47:13 -04:00
def plans
@plan_templates = IdCard::Plan.templates
render :plans
end
def update_plans
plans_params = IdCard::Plan.permitted_params(params)
2026-03-20 10:46:53 -04:00
if @setup.update(plans_params)
puts "sucess"
2026-03-20 10:46:53 -04:00
redirect_to employer_path(@setup.employer.slug), notice: 'ID Card Plans successfully updated.'
else
puts "fail"
2026-05-06 13:28:16 -04:00
@plan_templates = IdCard::Plan.templates
2026-03-13 08:47:13 -04:00
render :plans, status: :unprocessable_entity
end
end
def field_exceptions
render :field_exceptions
end
def update_field_exceptions
field_exceptions_params = IdCard::FieldException.permitted_params(params)
2026-03-20 10:46:53 -04:00
if @setup.update(field_exceptions_params)
2026-03-13 08:47:13 -04:00
puts "sucess"
2026-03-20 10:46:53 -04:00
redirect_to employer_path(@setup.employer.slug), notice: 'ID Card Exceptions successfully updated.'
2026-03-13 08:47:13 -04:00
else
puts "fail"
render :field_exceptions, status: :unprocessable_entity
end
end
2026-04-17 15:35:10 -04:00
def update_active_status
@setup.active = !@setup.active
if @setup.save
puts "sucess"
redirect_to employer_path(@setup.employer.slug), notice: 'ID Card Active Status successfully updated.'
else
puts "fail"
render :show, status: :unprocessable_entity
end
end
def destroy
end
# API Methods
private
2026-03-13 08:47:13 -04:00
def set_employer_and_setup
@employer = Employer.find_by(slug: params[:employer_id])
2026-03-20 10:46:53 -04:00
if @employer.id_card_setup.present?
@setup = @employer.id_card_setup
2026-03-13 08:47:13 -04:00
else
2026-03-20 10:46:53 -04:00
@setup = @employer.create_id_card_setup
2026-03-13 08:47:13 -04:00
end
end
end
end