Sha256: f53242c59c8d1afa775ccc463bf8504ff95b9cfd146e1faf9d8d396731d7cefc

Contents?: true

Size: 1.75 KB

Versions: 18

Compression:

Stored size: 1.75 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_histories_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

18 entries across 18 versions & 1 rubygems

Version Path
flexite-0.0.25 app/helpers/flexite/entries_helper.rb
flexite-0.0.24 app/helpers/flexite/entries_helper.rb
flexite-0.0.23 app/helpers/flexite/entries_helper.rb
flexite-0.0.22 app/helpers/flexite/entries_helper.rb
flexite-0.0.21 app/helpers/flexite/entries_helper.rb
flexite-0.0.20 app/helpers/flexite/entries_helper.rb
flexite-0.0.19 app/helpers/flexite/entries_helper.rb
flexite-0.0.18 app/helpers/flexite/entries_helper.rb
flexite-0.0.17 app/helpers/flexite/entries_helper.rb
flexite-0.0.16 app/helpers/flexite/entries_helper.rb
flexite-0.0.15 app/helpers/flexite/entries_helper.rb
flexite-0.0.14 app/helpers/flexite/entries_helper.rb
flexite-0.0.13 app/helpers/flexite/entries_helper.rb
flexite-0.0.12 app/helpers/flexite/entries_helper.rb
flexite-0.0.11 app/helpers/flexite/entries_helper.rb
flexite-0.0.10 app/helpers/flexite/entries_helper.rb
flexite-0.0.9 app/helpers/flexite/entries_helper.rb
flexite-0.0.8 app/helpers/flexite/entries_helper.rb