Class: Katalyst::Content::Editor::NewItem

Inherits:
Base
  • Object
show all
Defined in:
app/helpers/katalyst/content/editor/new_item.rb

Constant Summary collapse

ACTIONS =
<<~ACTIONS.gsub(/\s+/, " ").freeze
  dragstart->#{NEW_ITEM_CONTROLLER}#dragstart
ACTIONS

Constants inherited from Base

Base::CONTAINER_CONTROLLER, Base::ITEM_CONTROLLER, Base::LIST_CONTROLLER, Base::NEW_ITEM_CONTROLLER, Base::STATUS_BAR_CONTROLLER, Base::TURBO_FRAME

Instance Attribute Summary

Attributes inherited from Base

#container, #template

Instance Method Summary collapse

Methods inherited from Base

#attributes_scope, #container_form_id, #initialize

Constructor Details

This class inherits a constructor from Katalyst::Content::Editor::Base

Instance Method Details

#build(item, **options, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/helpers/katalyst/content/editor/new_item.rb', line 11

def build(item, **options, &block)
  capture do
    concat(tag.div(**default_options(options)) do
      concat capture(&block)
      concat item_template(item)
    end)
    concat turbo_replace_placeholder(item)
  end
end

#item_template(item) ⇒ Object

Template is stored inside the new item dom, and copied into drag events when the user initiates drag so that it can be copied into the editor list on drop.



33
34
35
36
37
# File 'app/helpers/katalyst/content/editor/new_item.rb', line 33

def item_template(item)
  tag.template data: { "#{NEW_ITEM_CONTROLLER}-target" => "template" } do
    content_editor_items(item: item)
  end
end

#turbo_replace_placeholder(item) ⇒ Object

Remove items that are incomplete when rendering new items, this causes incomplete items to be removed from the list when the user cancels adding a new item by pressing ‘discard’ in the new item form.



24
25
26
27
28
# File 'app/helpers/katalyst/content/editor/new_item.rb', line 24

def turbo_replace_placeholder(item)
  turbo_stream.replace dom_id(item) do
    content_editor_item(item: item, data: { delete: "" })
  end
end