Extract form partial in admin/account_actions

This commit is contained in:
Matt Jankowski 2024-09-25 12:20:17 -04:00
parent f5f65abe1f
commit e4417191ee
5 changed files with 46 additions and 47 deletions

View File

@ -7,8 +7,7 @@ module Admin
def new def new
authorize @account, :show? authorize @account, :show?
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true, include_statuses: true) @account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true, include_statuses: true, target_account: @account)
@warning_presets = AccountWarningPreset.all
end end
def create def create

View File

@ -9,4 +9,8 @@ module Admin::AccountActionsHelper
] ]
) )
end end
def warning_presets
AccountWarningPreset.alphabetic
end
end end

View File

@ -25,6 +25,8 @@ class Admin::AccountAction
alias send_email_notification? send_email_notification alias send_email_notification? send_email_notification
alias include_statuses? include_statuses alias include_statuses? include_statuses
delegate :local?, :pretty_acct, to: :target_account, prefix: true
validates :type, :target_account, :current_account, presence: true validates :type, :target_account, :current_account, presence: true
validates :type, inclusion: { in: TYPES } validates :type, inclusion: { in: TYPES }

View File

@ -0,0 +1,34 @@
= form.input :report_id,
as: :hidden
.fields-group
= form.input :type,
as: :radio_buttons,
collection: Admin::AccountAction.types_for_account(form.object.target_account),
disabled: Admin::AccountAction.disabled_types_for_account(form.object.target_account),
hint: t('simple_form.hints.admin_account_action.type_html', acct: form.object.target_account_pretty_acct),
include_blank: false,
label_method: ->(type) { account_action_type_label(type) },
wrapper: :with_block_label
- if form.object.target_account_local?
%hr.spacer/
.fields-group
= form.input :send_email_notification,
as: :boolean,
wrapper: :with_label
- if params[:report_id].present?
.fields-group
= form.input :include_statuses,
as: :boolean,
wrapper: :with_label
%hr.spacer/
- unless warning_presets.empty?
.fields-group
= form.input :warning_preset_id,
collection: warning_presets,
label_method: ->(warning_preset) { [warning_preset.title.presence, truncate(warning_preset.text)].compact.join(' - ') },
wrapper: :with_block_label
.fields-group
= form.input :text,
as: :text,
hint: t('simple_form.hints.admin_account_action.text_html', path: admin_warning_presets_path),
wrapper: :with_block_label

View File

@ -8,50 +8,10 @@
.flash-message.warn .flash-message.warn
= t('admin.account_actions.already_silenced') = t('admin.account_actions.already_silenced')
= simple_form_for @account_action, url: admin_account_action_path(@account.id) do |f| = simple_form_for @account_action, url: admin_account_action_path(@account.id) do |form|
= f.input :report_id, = render form
as: :hidden
.fields-group
= f.input :type,
as: :radio_buttons,
collection: Admin::AccountAction.types_for_account(@account),
disabled: Admin::AccountAction.disabled_types_for_account(@account),
hint: t('simple_form.hints.admin_account_action.type_html', acct: @account.pretty_acct),
include_blank: false,
label_method: ->(type) { account_action_type_label(type) },
wrapper: :with_block_label
- if @account.local?
%hr.spacer/
.fields-group
= f.input :send_email_notification,
as: :boolean,
wrapper: :with_label
- if params[:report_id].present?
.fields-group
= f.input :include_statuses,
as: :boolean,
wrapper: :with_label
%hr.spacer/
- unless @warning_presets.empty?
.fields-group
= f.input :warning_preset_id,
collection: @warning_presets,
label_method: ->(warning_preset) { [warning_preset.title.presence, truncate(warning_preset.text)].compact.join(' - ') },
wrapper: :with_block_label
.fields-group
= f.input :text,
as: :text,
hint: t('simple_form.hints.admin_account_action.text_html', path: admin_warning_presets_path),
wrapper: :with_block_label
.actions .actions
= f.button :button, = form.button :button,
t('admin.account_actions.action'), t('admin.account_actions.action'),
type: :submit type: :submit