Module: ContentBlockHelper

Defined in:
app/helpers/content_block_helper.rb

Instance Method Summary collapse

Instance Method Details

#edit_button(content_block) ⇒ Object



15
16
17
# File 'app/helpers/content_block_helper.rb', line 15

def edit_button(content_block)
  button_tag "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



23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/content_block_helper.rb', line 23

def edit_form(content_block, editing_field_id = nil)
  editing_field_id ||= "text_area_#{content_block.name}"
  form_for([sufia, 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 (:div) { f.submit 'Save', class: "btn btn-primary" }
  end
end

#editable_content_block(content_block, show_new = false) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/content_block_helper.rb', line 2

def editable_content_block(content_block, show_new = false)
  return raw(content_block.value) unless can? :update, content_block
  capture do
    concat (: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

#key_field_class(content_block_type) ⇒ Object



34
35
36
# File 'app/helpers/content_block_helper.rb', line 34

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

#new_button(_content_block) ⇒ Object



19
20
21
# File 'app/helpers/content_block_helper.rb', line 19

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

#new_form(name) ⇒ Object



38
39
40
41
# File 'app/helpers/content_block_helper.rb', line 38

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

#tiny_mce_stuffObject



43
44
45
46
47
48
# File 'app/helpers/content_block_helper.rb', line 43

def tiny_mce_stuff
  capture do
    concat tinymce_assets
    concat tinymce
  end
end