Sha256: 2f062819f8487a42429890ffad26ceb8f8ffcb513fc62b4a71d4095cdab4dec4

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8

module PagesCore
  module Admin
    module TagEditorHelper
      def tag_editor_for(
        form_helper, item, field_name = :serialized_tags, options = {}
      )
        tags = options[:tags] || Tag.tags_and_suggestions_for(item, limit: 20)
        tagged = options[:tagged] || item.tags
        options[:placeholder] ||= "Add tag..."
        content_tag(:div, class: "tag-editor clearfix") do
          form_helper.hidden_field(field_name, class: "serialized_tags") +
            tag_check_boxes(tags, tagged) +
            add_tag_button(options)
        end
      end

      private

      def tag_check_box(tag, tagged)
        content_tag(:span, class: :tag) do
          check_box_tag(
            "tag-#{tag.id}",
            1,
            tagged.include?(tag)
          ) + content_tag(:span, tag.name, class: :name)
        end
      end

      def tag_check_boxes(tags, tagged)
        content_tag(:div, class: :tags) do
          safe_join(tags.map { |t| tag_check_box(t, tagged) }, "")
        end
      end

      def add_tag_button(options = {})
        content_tag(:div, class: "add-tag-form") do
          text_field_tag(
            "add_tag",
            options[:placeholder],
            class: "add-tag"
          ) + content_tag(:button, "Add", class: "add-tag-button")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pages_core-3.5.1 app/helpers/pages_core/admin/tag_editor_helper.rb