Sha256: 9ad06b0d2e043e1631115feb14018dd196c489b6f4a00eb0565c38c3a2998264

Contents?: true

Size: 1.92 KB

Versions: 11

Compression:

Stored size: 1.92 KB

Contents

require 'cms/form_builder/deprecated_inputs'

module Cms
  module FormBuilder
    # Adds additional methods to the forms for creating content blocks.
    class ContentBlockFormBuilder < SimpleForm::FormBuilder
      include DeprecatedInputs

      # Allows editors to add multiple files uploader for attachments.
      # Usage:
      #   <%= f.attachment_manager %>
      #
      # Generator: The following will generate an attachments field with an associated attachment manager input.
      #   rails generate cms:content_block Widget photos:attachments
      def cms_attachment_manager
        input :attachments, as: :attachments
      end

      # Allows editors add a space separated list of tags. Each tag entered will be created if needed as an instance of a Cms::Tag.
      #
      # Usage:
      #   <%= f.cms_tag_list %>
      #
      # There is no generator for this field type.
      #
      def cms_tag_list(options={})
        input :tag_list, as: :tag_list, label: "Tags", input_html: {autocomplete: 'off'}, hint: "A space separated list of tags."
      end

      # Displays a concise list of error messages. This is may be unnecessary given that simple form will display error inline.
      # Handles 'global' messages that aren't specific to a field.
      def cms_error_messages
        return unless object.respond_to?(:errors) && object.errors.any?

        errors_list = ""
        errors_list << @template.content_tag(:h2, "#{object.errors.size} error prohibited this #{object_name.humanize} from being saved.".html_safe)
        errors_list << @template.content_tag(:p, "There were problems with the following fields:")
        errors_list << @template.content_tag(:ul, object.errors.full_messages.map { |message| @template.content_tag(:li, message).html_safe }.join("\n").html_safe).html_safe

        @template.content_tag(:div, errors_list.html_safe, :class => "errorExplanation", :id => "errorExplanation")
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
browsercms-artirix-4.0.4 lib/cms/form_builder/content_block_form_builder.rb
browsercms-artirix-4.0.3.3 lib/cms/form_builder/content_block_form_builder.rb
browsercms-artirix-4.0.3.2 lib/cms/form_builder/content_block_form_builder.rb
browsercms-artirix-4.0.3.1 lib/cms/form_builder/content_block_form_builder.rb
browsercms-artirix-4.0.3 lib/cms/form_builder/content_block_form_builder.rb
browsercms-artirix-4.0.2 lib/cms/form_builder/content_block_form_builder.rb
browsercms-artirix-4.0.1.1 lib/cms/form_builder/content_block_form_builder.rb
browsercms-artirix-4.0.0.rc1.art4 lib/cms/form_builder/content_block_form_builder.rb
browsercms-4.0.0.rc1 lib/cms/form_builder/content_block_form_builder.rb
browsercms-4.0.0.beta lib/cms/form_builder/content_block_form_builder.rb
browsercms-4.0.0.alpha lib/cms/form_builder/content_block_form_builder.rb