2010-03-22 01:58:37 +01:00
|
|
|
class Admin::OrdergroupsController < Admin::BaseController
|
2011-06-10 01:36:04 +02:00
|
|
|
inherit_resources
|
2018-12-21 01:12:43 +01:00
|
|
|
|
2009-01-14 12:46:01 +01:00
|
|
|
def index
|
2023-05-12 13:01:12 +02:00
|
|
|
@ordergroups = Ordergroup.undeleted.sort_by_param(params['sort'])
|
2011-06-10 01:36:04 +02:00
|
|
|
|
2018-12-21 01:12:43 +01:00
|
|
|
if request.format.csv?
|
2023-05-12 13:01:12 +02:00
|
|
|
send_data OrdergroupsCsv.new(@ordergroups).to_csv, filename: 'ordergroups.csv',
|
|
|
|
type: 'text/csv'
|
2018-12-21 01:12:43 +01:00
|
|
|
end
|
|
|
|
|
2011-06-10 01:36:04 +02:00
|
|
|
# if somebody uses the search field:
|
2023-05-12 13:01:12 +02:00
|
|
|
@ordergroups = @ordergroups.where('name LIKE ?', "%#{params[:query]}%") if params[:query].present?
|
2011-06-10 01:36:04 +02:00
|
|
|
|
2012-10-15 21:19:17 +02:00
|
|
|
@ordergroups = @ordergroups.page(params[:page]).per(@per_page)
|
2009-01-14 12:46:01 +01:00
|
|
|
end
|
2011-06-10 13:33:10 +02:00
|
|
|
|
2023-11-03 16:37:43 +01:00
|
|
|
def update
|
|
|
|
sepa_account_holder_params = params[:ordergroup][:sepa_account_holder_attributes]
|
|
|
|
if sepa_account_holder_params&.[](:user_id).blank? || sepa_account_holder_params&.[](:group_id).blank?
|
|
|
|
if sepa_account_holder_params&.[](:id).present?
|
|
|
|
SepaAccountHolder.find(sepa_account_holder_params[:id]).destroy
|
|
|
|
end
|
|
|
|
params[:ordergroup].delete(:sepa_account_holder_attributes)
|
|
|
|
end
|
|
|
|
@ordergroup = Ordergroup.find(params[:id])
|
|
|
|
if @ordergroup.update(params[:ordergroup])
|
|
|
|
redirect_to admin_ordergroup_path(@ordergroup), notice: t('.notice')
|
|
|
|
else
|
|
|
|
redirect_to edit_admin_ordergroup_path(@ordergroup), alert: @ordergroup.errors.full_messages.join(', ')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-10 13:33:10 +02:00
|
|
|
def destroy
|
|
|
|
@ordergroup = Ordergroup.find(params[:id])
|
2013-03-16 17:53:24 +01:00
|
|
|
@ordergroup.mark_as_deleted
|
2023-05-12 13:01:12 +02:00
|
|
|
redirect_to admin_ordergroups_url, notice: t('.notice')
|
|
|
|
rescue StandardError => e
|
|
|
|
redirect_to admin_ordergroups_url, alert: t('.error')
|
2011-06-10 13:33:10 +02:00
|
|
|
end
|
2009-01-14 12:46:01 +01:00
|
|
|
end
|