Class: Releaf::Content::Nodes::FormBuilder

Inherits:
Builders::FormBuilder
  • Object
show all
Defined in:
app/builders/releaf/content/nodes/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#content_builder_classObject



34
35
36
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 34

def content_builder_class
  Releaf::Content::Nodes::ContentFormBuilder
end

#field_namesObject



3
4
5
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 3

def field_names
  %w(node_fields_block content_fields_block)
end

#item_position_optionsObject



71
72
73
74
75
76
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 71

def item_position_options
  {
    include_blank: false,
    select_options: options_for_select(item_position_select_options, object.item_position)
  }
end

#item_position_select_optionsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 78

def item_position_select_options
  after_text = t("After")
  list = [[t("First"), 0]]

  order_nodes = object.self_and_siblings.reorder(:item_position).to_a
  order_nodes.each_with_index do |node, index|
    next if node == object

    if index == order_nodes.size - 1
      next_position = node.item_position + 1
    else
      next_position = order_nodes[index + 1].item_position
    end

    list.push [after_text + ' ' + node.name, next_position ]
  end

  list
end

#node_fieldsObject



7
8
9
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 7

def node_fields
  [:parent_id, :name, :content_type, :slug, :item_position, :active, :locale]
end

#render_content_fields_blockObject



25
26
27
28
29
30
31
32
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 25

def render_content_fields_block
  return unless render_content_fields_block?
  tag(:div, class: ["section", "content-fields"]) do
    fields_for(:content, object.content, builder: content_builder_class) do |form|
      form.releaf_fields(form.field_names.to_a)
    end
  end
end

#render_content_fields_block?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 21

def render_content_fields_block?
  object.content_class.respond_to?(:acts_as_node_fields)
end

#render_content_typeObject



49
50
51
52
53
54
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 49

def render_content_type
  input = {disabled: true, value: t(object.content_type.underscore, scope: 'admin.content_types')}
  releaf_text_field(:content_type, input: input) do
    hidden_field_tag(:content_type, params[:content_type]) if object.new_record?
  end
end

#render_item_positionObject



67
68
69
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 67

def render_item_position
  releaf_item_field(:item_position, options: item_position_options)
end

#render_localeObject



38
39
40
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 38

def render_locale
  releaf_item_field(:locale, options: render_locale_options) if object.locale_selection_enabled?
end

#render_locale_optionsObject



42
43
44
45
46
47
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 42

def render_locale_options
  {
    select_options: I18n.available_locales,
    include_blank: object.locale.blank?
  }
end

#render_node_fields_blockObject



11
12
13
14
15
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 11

def render_node_fields_block
  tag(:div, class: ["section", "node-fields"]) do
    releaf_fields(node_fields)
  end
end

#render_parent_idObject



17
18
19
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 17

def render_parent_id
  hidden_field(:parent_id) if object.new_record?
end

#render_slugObject



56
57
58
59
60
61
62
63
64
65
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 56

def render_slug
  url = url_for(controller: controller.controller_path, action: "generate_url", parent_id: object.parent_id, id: object.id)
  input = {
    data: {'generator-url' => url}
  }

  releaf_field(:slug, input: input) do
    slug_button << wrapper(slug_link, class: "link")
  end
end

#slug_base_urlObject



98
99
100
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 98

def slug_base_url
  "#{request.protocol}#{request.host_with_port}#{object.parent.try(:path)}" + (object.trailing_slash_for_path? ? "" : "/")
end

#slug_buttonObject



110
111
112
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 110

def slug_button
  button(nil, "keyboard-o", title: t('Suggest slug'), class: "secondary generate")
end


102
103
104
105
106
107
108
# File 'app/builders/releaf/content/nodes/form_builder.rb', line 102

def slug_link
  link_to(object.path) do
    safe_join do
      [slug_base_url, tag(:span, object.slug), (object.trailing_slash_for_path? ? "/" : "")]
    end
  end
end