Module: Hyrax::ContentBlockHelperBehavior
- Included in:
- ContentBlockHelper
- Defined in:
- app/helpers/hyrax/content_block_helper_behavior.rb
Instance Method Summary collapse
- #display_editable_content_block?(content_block) ⇒ Boolean
- #edit_button(content_block) ⇒ Object
- #edit_form(content_block, editing_field_id = nil) ⇒ Object
- #editable_content_block(content_block, show_new = false) ⇒ Object
- #key_field_class(content_block_type) ⇒ Object
- #new_button(_content_block) ⇒ Object
- #new_form(name) ⇒ Object
Instance Method Details
#display_editable_content_block?(content_block) ⇒ Boolean
16 17 18 |
# File 'app/helpers/hyrax/content_block_helper_behavior.rb', line 16 def display_editable_content_block?(content_block) content_block.value.present? || can?(:update, content_block) end |
#edit_button(content_block) ⇒ Object
20 21 22 |
# File 'app/helpers/hyrax/content_block_helper_behavior.rb', line 20 def (content_block) "Edit", class: 'btn btn-primary', data: { behavior: 'reveal-editor', target: '#' + dom_id(content_block, 'edit') } end |
#edit_form(content_block, editing_field_id = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/hyrax/content_block_helper_behavior.rb', line 28 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 |
#editable_content_block(content_block, show_new = false) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/hyrax/content_block_helper_behavior.rb', line 3 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 (content_block) concat (content_block) if show_new } concat edit_form(content_block) concat new_form(content_block.name) if show_new end end |
#key_field_class(content_block_type) ⇒ Object
39 40 41 |
# File 'app/helpers/hyrax/content_block_helper_behavior.rb', line 39 def key_field_class(content_block_type) content_block_type == ContentBlock::RESEARCHER ? 'select2-user' : '' end |
#new_button(_content_block) ⇒ Object
24 25 26 |
# File 'app/helpers/hyrax/content_block_helper_behavior.rb', line 24 def (_content_block) "New", class: 'btn btn-primary', data: { behavior: 'reveal-editor', target: '#' + 'new_content_block' } end |
#new_form(name) ⇒ Object
43 44 45 46 |
# File 'app/helpers/hyrax/content_block_helper_behavior.rb', line 43 def new_form(name) content_block = ContentBlock.new(name: name) edit_form(content_block, "new_#{name}_text_area") end |