Verified Commit e2ff194e authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

feat(semester-process): add form select that triggers reload in case semester is changed

- in order to have elegible volunteers to be rebuilt for the changed semester daterange
parent 8f4a52f2
$(() => {
// Only run this on new_semester_process_path
if (Routes.new_semester_process_path() !== window.location.pathname) { return }
$('select.semester-selector').change(({ target }) => {
window.location.href = `${window.location.origin}${Routes.new_semester_process_path({ semester: $(target).val() })}`
})
})
class SemesterProcessesController < ApplicationController
before_action :set_semester_process, only: [:show, :edit, :update, :destroy]
before_action :set_semester, only: [:new, :create]
def index
authorize SemesterProcess
......@@ -16,7 +17,7 @@ class SemesterProcessesController < ApplicationController
def edit; end
def create
@semester_process = SemesterProcess.new(semester_process_params)
@semester_process = SemesterProcess.new(semester_process_params.slice(:semester))
@semester_process.creator = current_user
authorize @semester_process
if @semester_process.save
......@@ -49,7 +50,19 @@ class SemesterProcessesController < ApplicationController
authorize @semester_process
end
def set_semester
@semester = Semester.new
params[:semester] = @semester.year_number unless params[:semester]
@selected_semester = Semester.new(*params[:semester].split(',').map(&:to_i)).current
@volunteers = Volunteer.semester_process_eligible(@selected_semester)
end
def semester_process_params
params.require(:semester_process).permit(:period_start, :period_end)
params.require(:semester_process).permit(
:semester,
semester_process_volunteers_attributes: [
:volunteer_id, :selected
]
)
end
end
= simple_form_for(@semester_process) do |f|
= simple_form_for(@semester_process, html: { class: 'form-ignore-changes' }) do |f|
= simple_error_notice f
.row
.col-xs-12
= f.input :period, as: :date_range_picker, label: false
.row:.col-xs-12.col-md-4
= f.input :semester, collection: @semester.collection, selected: params[:semester], input_html: { class: 'semester-selector' }
.row
.col-xs-12
.row:.col-xs-12
= f.button :submit
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment