%# This is ancient code, needs a lot of refactoring when I or someone can get around to it. In the meantime, it works. %>
<% totals ||= nil %>
<% container ||= '' %>
<% container_class = container.gsub(/\[\d+\]/, '').gsub(/\[|\]/, '-') %>
<% form_id ||= '' %>
<% stimulus_controller_name = name.pluralize.dasherize %>
<% attributes = lookup_attributes(attributes_key) if attributes_key %>
<%
begin
hidden_fields = "#{name.classify}::HIDDEN_FIELDS".constantize
rescue NameError, LoadError
hidden_fields = []
end
%>
" data-child-objects-target="child-objects.row">
<% attributes.each do |attribute| %>
<% attribute_value = child.send(attribute) %>
<% if hidden_fields.include? attribute.to_sym %>
<%= hidden_field_tag "#{name.pluralize}#{container}[#{child_counter}][#{attribute}]", attribute_value, class: "#{name.pluralize}#{container_class}_#{attribute}" %>
<% else %>
<% if eval %Q|!child.respond_to?("#{attribute}=")| %>
<% if eval "#{name.classify}::WRITE_ONCE_ATTRIBUTES.detect {|woa| woa == :#{attribute}}" %>
<% if child.respond_to?(:format_for_value) -%>
<%= hidden_field_tag "#{name.pluralize}#{container}[#{child_counter}][#{attribute}]", child.format_for_value(attribute, attribute_value), class: "#{name.pluralize}#{container_class}_#{attribute}" %>
<% else -%>
<%= hidden_field_tag "#{name.pluralize}#{container}[#{child_counter}][#{attribute}]", (attribute_value.respond_to?(:to_html) ? attribute_value.to_html : attribute_value), class: "#{name.pluralize}#{container_class}_#{attribute}" %>
<% end -%>
<% end %>
<% if child.respond_to?(:format_for_display) -%>
<%= h child.format_for_display(attribute, attribute_value) %>
<% else -%>
<%= h(attribute_value.respond_to?(:to_html) ? attribute_value.to_html : attribute_value) %>
<% end -%>
<% else %>
<% if attribute[-4..-1] == 'time' %>
<%= select_time(attribute_value, prefix: "#{name.pluralize}#{container}[#{child_counter}][#{attribute}]", minute_step: 5, ampm: true, include_blank: true, class: 'select is-small') %>
<% elsif attribute[-3..-1] == '_id' %>
<%= select_tag "#{name.pluralize}#{container}[#{child_counter}][#{attribute}]", options_for_select(id_select_options(attribute).unshift(["Select One", ""]), attribute_value.to_i), class: 'select is-small' %>
<% else %>
<%= text_field_tag "#{name.pluralize}#{container}[#{child_counter}][#{attribute}]", (attribute_value.respond_to?(:to_html) ? attribute_value.to_html : attribute_value), size: (attribute == "covers" ? 2 : 10), class: "#{name.pluralize}#{container_class}_#{attribute} input is-small", data: {"#{stimulus_controller_name}-container": container, "#{stimulus_controller_name}-container-class": container_class, "#{stimulus_controller_name}-form-id": form_id, action: "change->#{stimulus_controller_name}#updateTotals"} %>
<% end %>
<% end %>
<% end %>
<% field_index = attributes.index(attribute) %>
<% totals[field_index] += attribute_value.to_f if (totals && field_index && totals[field_index] && attribute_value.respond_to?(:to_f)) %>
|
<% end %>
<% unless system_controlled %>
<%= button_tag "delete", type: :button, class: 'button is-small is-danger', data: {action: 'click->child-objects#deleteRow'} %>
|
<% end %>
<% if last && !system_controlled %>
<%= button_tag "add another", type: :button, class: 'button is-small is-primary', data: {action: 'click->child-objects#addRow'} %>
|
<% end %>