diff --git a/app/controllers/casa_orgs_controller.rb b/app/controllers/casa_orgs_controller.rb index 7c05102478..238436135d 100644 --- a/app/controllers/casa_orgs_controller.rb +++ b/app/controllers/casa_orgs_controller.rb @@ -1,6 +1,8 @@ class CasaOrgsController < ApplicationController + before_action :authenticate_user!, :must_be_admin before_action :set_casa_org, only: %i[edit update] before_action :set_contact_type_data, only: %i[edit update] + before_action :set_hearing_types, only: %i[edit update] before_action :must_be_admin before_action :require_organization! @@ -35,4 +37,8 @@ def set_contact_type_data @contact_type_groups = @casa_org.contact_type_groups @contact_types = ContactType.for_organization(@casa_org) end + + def set_hearing_types + @hearing_types = HearingType.for_organization(@casa_org) + end end diff --git a/app/controllers/hearing_types_controller.rb b/app/controllers/hearing_types_controller.rb new file mode 100644 index 0000000000..24ed4cc03c --- /dev/null +++ b/app/controllers/hearing_types_controller.rb @@ -0,0 +1,43 @@ +class HearingTypesController < ApplicationController + before_action :authenticate_user!, :must_be_admin + before_action :set_hearing_type, except: [:new, :create] + + def new + @hearing_type = HearingType.new + end + + def create + @hearing_type = HearingType.new(hearing_type_params) + + respond_to do |format| + if @hearing_type.save + format.html { redirect_to edit_casa_org_path(current_organization), notice: "Hearing Type was successfully created." } + else + format.html { render :new } + end + end + end + + def edit + end + + def update + if @hearing_type.update(hearing_type_params) + redirect_to edit_casa_org_path(current_organization), notice: "Hearing Type was successfully updated." + else + render :edit + end + end + + private + + def set_hearing_type + @hearing_type = HearingType.find(params[:id]) + end + + def hearing_type_params + params.require(:hearing_type).permit(:name, :active).merge( + casa_org: current_organization + ) + end +end diff --git a/app/models/hearing_type.rb b/app/models/hearing_type.rb new file mode 100644 index 0000000000..dc8be2c600 --- /dev/null +++ b/app/models/hearing_type.rb @@ -0,0 +1,24 @@ +class HearingType < ApplicationRecord + has_paper_trail + + belongs_to :casa_org + + validates :name, presence: true, uniqueness: { scope: %i[casa_org] } + validates :active, presence: true + + scope :for_organization, ->(org) { where(casa_org: org) } +end + +# == Schema Information +# +# Table name: hearing_types +# +# id :bigint not null, primary key +# active :boolean default(TRUE), not null +# name :string not null +# casa_org_id :bigint not null +# +# Indexes +# +# index_hearing_types_on_casa_org_id (casa_org_id) +# diff --git a/app/views/casa_orgs/_contact_types.html.erb b/app/views/casa_orgs/_contact_types.html.erb index af98d2baf9..77a13beb77 100644 --- a/app/views/casa_orgs/_contact_types.html.erb +++ b/app/views/casa_orgs/_contact_types.html.erb @@ -26,6 +26,7 @@
| Name | +Active | +Actions | +
|---|---|---|
| + <%= hearing_type.name %> + | ++ <%= hearing_type.active %> + | ++ <%= link_to "Edit", edit_hearing_type_path(hearing_type) %> + | +