Sha256: dd3a054c3376a0f6af53ed586ba5f38e2266e35adec41c606408beae2bcc1ca5

Contents?: true

Size: 1.9 KB

Versions: 9

Compression:

Stored size: 1.9 KB

Contents

module Hyrax
  module ContentBlockHelperBehavior
    def editable_content_block(content_block, show_new = false)
      return raw(content_block.value) unless can? :update, content_block
      capture do
        concat content_tag(:div, id: dom_id(content_block, 'preview'), class: 'content_block_preview') {
          concat raw(content_block.value)
          concat edit_button(content_block)
          concat new_button(content_block) if show_new
        }
        concat edit_form(content_block)
        concat new_form(content_block.name) if show_new
      end
    end

    def display_editable_content_block?(content_block)
      content_block.value.present? || can?(:update, content_block)
    end

    def edit_button(content_block)
      button_tag "Edit", class: 'btn btn-primary', data: { behavior: 'reveal-editor', target: '#' + dom_id(content_block, 'edit') }
    end

    def new_button(_content_block)
      button_tag "New", class: 'btn btn-primary', data: { behavior: 'reveal-editor', target: '#' + 'new_content_block' }
    end

    def edit_form(content_block, editing_field_id = nil)
      editing_field_id ||= "text_area_#{content_block.name}"
      form_for([hyrax, content_block], html: { class: 'tinymce-form' }) do |f|
        concat hidden_field_tag 'content_block[name]', content_block.name
        concat f.text_area :value, id: editing_field_id, class: "tinymce", rows: 20, cols: 120
        concat f.label :external_key, content_block.external_key_name
        concat f.text_field :external_key, class: key_field_class(content_block.name)
        concat content_tag(:div) { f.submit 'Save', class: "btn btn-primary" }
      end
    end

    def key_field_class(content_block_type)
      content_block_type == ContentBlock::RESEARCHER ? 'select2-user' : ''
    end

    def new_form(name)
      content_block = ContentBlock.new(name: name)
      edit_form(content_block, "new_#{name}_text_area")
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hyrax-1.1.1 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.1.0 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.0.5 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.0.4 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.0.3 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.0.2 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.0.1 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.0.0.rc2 app/helpers/hyrax/content_block_helper_behavior.rb
hyrax-1.0.0.rc1 app/helpers/hyrax/content_block_helper_behavior.rb