mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
simplify available units params (and remove regex!)
This commit is contained in:
@@ -10,7 +10,7 @@ module Spree
|
||||
end
|
||||
|
||||
def update
|
||||
combine_available_units_params
|
||||
merge_available_units_params
|
||||
params.each do |name, value|
|
||||
next unless Spree::Config.has_preference? name
|
||||
|
||||
@@ -23,14 +23,9 @@ module Spree
|
||||
|
||||
private
|
||||
|
||||
def combine_available_units_params
|
||||
available_units = []
|
||||
params.each do |name, value|
|
||||
if value == "1" && unit = name.match(/available_units_(.*)/)&.captures&.first
|
||||
available_units << unit
|
||||
end
|
||||
end
|
||||
params[:available_units] = available_units.join(",")
|
||||
def merge_available_units_params
|
||||
params[:available_units] =
|
||||
params[:available_units].select { |unit, checked| checked == "1" }.keys.join(",")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,10 +90,10 @@
|
||||
%fieldset.available_units.no-border-bottom
|
||||
%legend{:align => "center"}= t('admin.available_units')
|
||||
.field
|
||||
- selected_units = Spree::Config[:available_units].split(",")
|
||||
- available_units = Spree::Config[:available_units].split(",")
|
||||
- all_units.each do |unit|
|
||||
- selected = selected_units.include?(unit)
|
||||
= preference_field_tag("available_units_#{unit}", selected, { type: :boolean, selected: selected })
|
||||
- selected = available_units.include?(unit)
|
||||
= preference_field_tag("available_units[#{unit}]", selected, { type: :boolean, selected: selected })
|
||||
= label_tag(unit, unit.downcase) + tag(:br)
|
||||
|
||||
.form-buttons.filter-actions.actions{"data-hook" => "buttons"}
|
||||
|
||||
Reference in New Issue
Block a user