Module: Maglev::Editor::SectionBlocksHelper

Defined in:
app/helpers/maglev/editor/section_blocks_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_child_section_block_button(section, section_block) ⇒ Object



63
64
65
66
67
68
69
70
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 63

def add_child_section_block_button(section, section_block)
  block_definitions = section.child_block_definitions_of(section_block.id)
  if block_definitions.one?
    add_child_section_block_no_dropdown_button(section, section_block.id, block_definitions.first.type)
  elsif block_definitions.any?
    add_child_section_block_dropdown_button(section, section_block.id, block_definitions)
  end
end

#add_child_section_block_dropdown_button(_section, parent_id, block_definitions) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 85

def add_child_section_block_dropdown_button(_section, parent_id, block_definitions)
  render Maglev::Uikit::DropdownComponent.new do |dropdown|
    dropdown.with_trigger do
      button_tag(class: maglev_icon_button_classes, **section_block_button_dropdown_attributes) do
        render Maglev::Uikit::IconComponent.new(name: 'add', size: '1.15rem')
      end
    end

    (:div, class: 'p-4 min-w-64') do
      render 'maglev/editor/section_blocks/new', blocks: block_definitions, parent_id: parent_id
    end
  end
end

#add_child_section_block_no_dropdown_button(section, parent_id, block_type) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 72

def add_child_section_block_no_dropdown_button(section, parent_id, block_type)
  button_to(
    editor_section_blocks_path(section, block_type: block_type, parent_id: parent_id,
                                        lock_version: source_lock_version,
                                        **maglev_editing_route_context),
    class: maglev_icon_button_classes,
    name: 'add_child_section_block',
    **section_block_button_common_attributes(section)
  ) do
    render Maglev::Uikit::IconComponent.new(name: 'add', size: '1.15rem')
  end
end

#add_section_block_button(section, block_definitions) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 29

def add_section_block_button(section, block_definitions)
  if block_definitions.blank?
    ''
  elsif block_definitions.one?
    add_section_block_no_dropdown_button(section, block_definitions.first.type)
  else
    add_section_block_dropdown_button(section, block_definitions)
  end
end

#add_section_block_dropdown_button(_section, block_definitions) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 49

def add_section_block_dropdown_button(_section, block_definitions)
  render Maglev::Uikit::DropdownComponent.new do |dropdown|
    dropdown.with_trigger do
      button_tag(t('maglev.editor.section_blocks.index.add_button'),
                 class: maglev_button_classes(size: :big),
                 **section_block_button_dropdown_attributes)
    end

    (:div, class: 'p-4 min-w-64') do
      render 'maglev/editor/section_blocks/new', blocks: block_definitions, parent_id: nil
    end
  end
end

#add_section_block_no_dropdown_button(section, block_type) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 39

def add_section_block_no_dropdown_button(section, block_type)
  button_to(
    t('maglev.editor.section_blocks.index.add_button'),
    editor_section_blocks_path(section, block_type: block_type, lock_version: source_lock_version,
                                        **maglev_editing_route_context),
    class: maglev_button_classes(size: :big),
    **section_block_button_common_attributes(section)
  )
end

#delete_section_block_button(section, section_block, maglev_editing_route_context) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 7

def delete_section_block_button(section, section_block, maglev_editing_route_context)
  button_to(
    editor_section_block_path(section, section_block, **maglev_editing_route_context),
    method: :delete,
    class: maglev_icon_button_classes,
    data: { turbo_confirm: t('maglev.editor.section_blocks.index.confirm_delete') },
    form: delete_section_block_button_form_attributes(section, section_block)
  ) do
    render Maglev::Uikit::IconComponent.new(name: 'delete_bin', size: '1.15rem')
  end
end

#delete_section_block_button_form_attributes(section, section_block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 19

def delete_section_block_button_form_attributes(section, section_block)
  {
    data: {
      action: 'turbo:submit-end->editor-preview-notification-center#deleteSectionBlock',
      'editor-preview-notification-center-section-id-param': section.id,
      'editor-preview-notification-center-section-block-id-param': section_block.id
    }
  }
end

#section_block_button_common_attributes(section) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 99

def section_block_button_common_attributes(section)
  {
    method: :post,
    form: {
      data: {
        turbo_frame: '_top',
        action: 'turbo:submit-end->editor-preview-notification-center#addSectionBlock',
        'editor-preview-notification-center-section-id-param': section.id
      }
    }
  }
end

#section_block_button_dropdown_attributesObject



112
113
114
115
116
117
118
119
120
# File 'app/helpers/maglev/editor/section_blocks_helper.rb', line 112

def section_block_button_dropdown_attributes
  {
    type: 'button',
    data: {
      action: 'click->uikit-dropdown#toggle',
      'uikit-dropdown-target': 'button'
    }
  }
end