Sha256: 33743a7148ab82166ee47e705c75888688a9714f60e19561f61adeab447e82b3

Contents?: true

Size: 1.1 KB

Versions: 20

Compression:

Stored size: 1.1 KB

Contents

module Spina
  module Admin
    module PagesHelper
      def link_to_add_fields(f, association, &block)
        new_object = f.object.send(association).klass.new
        id = new_object.object_id
        fields = f.fields_for(association, new_object, child_index: id) do |builder|
          build_structure_parts(f.object.page_part.name, new_object) if structure_item?(new_object)
          render(association.to_s.singularize + "_fields", f: builder)
        end
        link_to '#', class: "#{add_fields_class(new_object)} button button-link", data: {id: id, fields: fields.gsub("\n", "")} do
          block.yield
        end
      end

      def add_fields_class(object)
        structure_item?(object) ? 'add_structure' : 'add_fields'
      end

      def structure_item?(object)
        object.class.name.demodulize == "StructureItem"
      end

      def build_structure_parts(name, item)
        current_theme.config.structures[name].each do |part|
          part = item.structure_parts.build(part)
          part.structure_partable = part.structure_partable_type.constantize.new
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
spina-0.8.3 app/helpers/spina/admin/pages_helper.rb
spina-0.8.2 app/helpers/spina/admin/pages_helper.rb
spina-0.8.1 app/helpers/spina/admin/pages_helper.rb
spina-0.8.0 app/helpers/spina/admin/pages_helper.rb
spina-0.7.3 app/helpers/spina/admin/pages_helper.rb
spina-0.7.2 app/helpers/spina/admin/pages_helper.rb
spina-0.7.0 app/helpers/spina/admin/pages_helper.rb
spina-0.6.29 app/helpers/spina/admin/pages_helper.rb
spina-0.6.28 app/helpers/spina/admin/pages_helper.rb
spina-0.6.27 app/helpers/spina/admin/pages_helper.rb
spina-0.6.26 app/helpers/spina/admin/pages_helper.rb
spina-0.6.25 app/helpers/spina/admin/pages_helper.rb
spina-0.6.24 app/helpers/spina/admin/pages_helper.rb
spina-0.6.23 app/helpers/spina/admin/pages_helper.rb
spina-0.6.22 app/helpers/spina/admin/pages_helper.rb
spina-0.6.21 app/helpers/spina/admin/pages_helper.rb
spina-0.6.20 app/helpers/spina/admin/pages_helper.rb
spina-0.6.19 app/helpers/spina/admin/pages_helper.rb
spina-0.6.18 app/helpers/spina/admin/pages_helper.rb
spina-0.6.17 app/helpers/spina/admin/pages_helper.rb