Use separate actions to enable/disable budget phases
This is consistent with the way we use separate actions to hide and restore records, which is similar to enabling and disabling a record. We might do something similar with the `toggle_selection` actions in the future. For now, we're only doing it with budget phases because we're going to add a similar switch control to hide and restore tenants. We're also making these actions idempotent, so sending many requests to the same action will get the same result, which wasn't the case with the `toggle` action. Although it's a low probability case, the `toggle` action could result in disabling a phase when trying to enable it if someone else has enabled it between the time the page loaded and the time the admin clicked on the "enable" button.
This commit is contained in:
@@ -6,7 +6,7 @@ module Admin::BudgetPhasesActions
|
||||
include ImageAttributes
|
||||
|
||||
before_action :load_budget
|
||||
before_action :load_phase, only: [:edit, :update, :toggle_enabled]
|
||||
before_action :load_phase, only: [:edit, :update, :enable, :disable]
|
||||
end
|
||||
|
||||
def edit
|
||||
@@ -20,12 +20,21 @@ module Admin::BudgetPhasesActions
|
||||
end
|
||||
end
|
||||
|
||||
def toggle_enabled
|
||||
@phase.update!(enabled: !@phase.enabled)
|
||||
def enable
|
||||
@phase.update!(enabled: true)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to phases_index, notice: t("flash.actions.save_changes.notice") }
|
||||
format.js
|
||||
format.js { render template: "admin/budgets_wizard/phases/toggle_enabled" }
|
||||
end
|
||||
end
|
||||
|
||||
def disable
|
||||
@phase.update!(enabled: false)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to phases_index, notice: t("flash.actions.save_changes.notice") }
|
||||
format.js { render template: "admin/budgets_wizard/phases/toggle_enabled" }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user