Sha256: 0d5d46258ea0df99629f2c19fb0fcfe2e0b74a6466defcc4c2d5509939dabb93

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

module Flexite
  module EntriesHelper
    ENTRY_TYPE_OPTIONS = [
      ['String', 'Flexite::StrEntry'],
      ['Symbol', 'Flexite::SymEntry'],
      ['Boolean', 'Flexite::BoolEntry'],
      ['Array', 'Flexite::ArrEntry'],
      ['Integer', 'Flexite::IntEntry']
    ].freeze

    def render_entries(entries, form)
      content_tag :div, id: "#{form.object_name}-array-entries-#{form.options[:index]}" do
        entries.each_with_index do |entry, index|
          concat render_entry(entry, form, index)
        end
      end
    end

    def entry_type_select(f = nil)
      if f.present?
        f.select :type, options_for_select(ENTRY_TYPE_OPTIONS), {}, class: 'form-control'
      else
        select_tag :new_entry_type, options_for_select(ENTRY_TYPE_OPTIONS), class: 'form-control'
      end
    end

    private

    def render_entry(entry, form, index)
      cache entry do
        entry_form = entry.class.form(entry.form_attributes)

        concat(form.simple_fields_for(:entries, entry_form, index: index) do |fields|
          delete_link = link_to 'Delete', destroy_array_entries_path(id: entry.id, selector: "#{fields.object_name}-#{index}-#{entry.id}"),
                                remote: true, method: :delete, class: 'btn btn-danger'
          history_link = link_to 'History', entity_history_path(entry_form.id, entry_form.history_type), remote: true, class: 'btn btn-default'

          concat(content_tag(:div, id: "#{fields.object_name}-#{index}-#{entry.id}") do
            concat fields.input :id, as: :hidden
            concat fields.input :type, as: :hidden
            concat render "flexite/entries/types/#{entry_form.view_type}", f: fields, delete_link: delete_link, history_link: history_link
          end)
        end)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flexite-0.0.7 app/helpers/flexite/entries_helper.rb
flexite-0.0.6 app/helpers/flexite/entries_helper.rb
flexite-0.0.5 app/helpers/flexite/entries_helper.rb