mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +00:00
These all seem to require html_safe/raw, so we'll permit it. Some of the spree code is a bit strange and could probably be improved, but I think it's ok for now.
39 lines
1.3 KiB
Ruby
39 lines
1.3 KiB
Ruby
# frozen_string_literal: false
|
|
|
|
module Spree
|
|
module Admin
|
|
module ZonesHelper
|
|
# This method creates a link which uses javascript to add a new
|
|
# form partial to the DOM.
|
|
#
|
|
# <%= form_for @project do |project_form| %>
|
|
# <div id="tasks">
|
|
# <%= project_form.fields_for :tasks do |task_form| %>
|
|
# <%= render partial: 'task', locals: { f: task_form } %>
|
|
# <% end %>
|
|
# </div>
|
|
# <% end %>
|
|
def generate_html(form_builder, method, options = {})
|
|
options[:object] ||= form_builder.object.class.reflect_on_association(method).klass.new
|
|
options[:partial] ||= method.to_s.singularize
|
|
options[:form_builder_local] ||= :f
|
|
|
|
form_builder.fields_for(method, options[:object], child_index: 'NEW_RECORD') do |f|
|
|
render(partial: options[:partial], locals: { options[:form_builder_local] => f })
|
|
end
|
|
end
|
|
|
|
def generate_template(form_builder, method, options = {})
|
|
escape_javascript generate_html(form_builder, method, options)
|
|
end
|
|
|
|
def remove_nested(fields)
|
|
out = ''
|
|
out << fields.hidden_field(:_destroy) unless fields.object.new_record?
|
|
out << (link_to icon('icon-remove'), "#", class: 'remove')
|
|
out.html_safe # rubocop:disable Rails/OutputSafety
|
|
end
|
|
end
|
|
end
|
|
end
|