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

form for setting all group assignments to end date optimized

parent 02f69065
......@@ -40,3 +40,8 @@ fieldset {
flex: 0 0 20%;
}
}
.field-wrapper-inline {
display: inline-block;
margin: 5px;
}
......@@ -89,6 +89,16 @@ class GroupOffersController < ApplicationController
end
end
def end_all_assignments
@group_offer.group_assignments.running.each do |group_assignment|
group_assignment.update(
period_end: group_offer_params['group_assignments_attributes']['0']['period_end'],
period_end_set_by: current_user
)
end
redirect_to initiate_termination_group_offer_path(@group_offer), notice: 'Gruppeneinsätze wurden beendet.'
end
private
def set_group_offer
......@@ -128,7 +138,7 @@ class GroupOffersController < ApplicationController
params.require(:group_offer).permit(:title, :offer_type, :offer_state, :volunteer_state,
:necessary_volunteers, :description, :women, :men, :children, :teenagers, :unaccompanied,
:all, :long_term, :regular, :short_term, :workday, :weekend, :morning, :afternoon, :evening,
:flexible, :schedule_details, :department_id, :creator_id, :organization, :location,
:group_offer_category_id, :period_end, group_assignments_attributes)
:flexible, :schedule_details, :department_id, :creator_id, :organization, :location, :period_end,
:group_offer_category_id, group_assignments_attributes)
end
end
class DatePickerInput < SimpleForm::Inputs::Base
def input
template.content_tag(:div, class: 'input-group date form_datetime input-date-picker') do
template.concat @builder.text_field(attribute_name, input_html_options)
end
def input(wrapper_options)
@builder.text_field(attribute_name, input_html_options)
end
def input_html_options
......
......@@ -28,7 +28,8 @@ class GroupOfferPolicy < ApplicationPolicy
alias_method :change_active_state?, :superadmin_or_department_manager_offer?
alias_method :initiate_termination?, :superadmin_or_department_manager_offer?
alias_method :submit_initiate_termination?, :superadmin_or_department_manager_offer?
alias_method :end_all_assignments?, :superadmin_or_department_manager_offer?
alias_method :destroy?, :superadmin?
# supplemental policies
......
h1 Gruppenangebot Beenden
= simple_form_for(@group_offer, method: :put, url: submit_initiate_termination_group_offer_path(@group_offer)) do |f|
- if @group_offer.group_assignments.running.any?
h2 Noch nicht beendete Gruppeneinsätze
= render 'group_assignments_index', group_assignments: @group_offer.group_assignments.running,
redirect_to_action: :initiate_termination
- if @group_offer.group_assignments.running.any?
h2 Noch nicht beendete Gruppeneinsätze
= render 'group_assignments_index', group_assignments: @group_offer.group_assignments.running,
redirect_to_action: :initiate_termination
- if @group_offer.group_assignments.running.size > 1
= simple_form_for(@group_offer, url: end_all_assignments_group_offer_path(@group_offer)) do |f|
h3 Alle Gruppeneinsätze beenden
= f.simple_fields_for :group_assignments do |ga|
- next if ga.index > 0
= ga.input :period_end, as: :string, wrapper: :date_picker_inline,
input_html: { value: Time.zone.today.to_s }, label: false
input.btn.btn-default.btn-sm type='submit' name='commit' value='Jetzt alle Einsätze auf Enddatum beenden' data-disable-with='Begleitung aktualisieren'
hr
h2 class=('disabled-title' if @group_offer.group_assignments.running.any?) Enddatum für das Gruppenangebot setzen
- if @group_offer.group_assignments.running.any?
p.text-danger.text-bigger-1 Um das Gruppenangebot zu beenden, müssen erst alle zugehörigen Gruppeneinsätze beendet sein.
h2 class=('disabled-title' if @group_offer.group_assignments.running.any?) Enddatum für das Gruppenangebot setzen
- if @group_offer.group_assignments.running.any?
p.text-danger.text-bigger-1 Um das Gruppenangebot zu beenden, müssen erst alle zugehörigen Gruppeneinsätze beendet sein.
= simple_form_for(@group_offer, method: :put, url: submit_initiate_termination_group_offer_path(@group_offer)) do |f|
= f.input :period_end, as: :date_picker, disabled: @group_offer.group_assignments.running.any?
p.text-info.m-b-10.text-bigger-1
em Die Voreinstellung für das Enddatum kann auf ein beliebiges Datum angepasst werden
hr
= f.button :submit, disabled: @group_offer.group_assignments.running.any?
......@@ -112,6 +112,29 @@ SimpleForm.setup do |config|
end
end
config.wrappers :date_picker, tag: 'div', class: 'form-group date form_datetime input-date-picker', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'control-label'
b.use :input, class: 'input-sm form-control', data: { provide: 'datepicker' }
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
config.wrappers :date_picker_inline, tag: 'div', class: 'date form_datetime input-date-picker field-wrapper-inline', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'sr-only'
b.use :input, class: 'input-sm form-control', data: { provide: 'datepicker' }
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
config.wrappers :submit_inline, tag: 'div', class: 'field-wrapper-inline' do |b|
b.use :html5
b.use :input, class: 'btn btn-default'
end
config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
......
......@@ -70,6 +70,7 @@ Rails.application.routes.draw do
put :change_active_state, on: :member
get :initiate_termination, on: :member
put :submit_initiate_termination, on: :member
patch :end_all_assignments, on: :member
end
get 'list_responses/hours', to: 'list_responses#hours'
......
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