Module: Alchemy::Admin::ElementsHelper

Includes:
BaseHelper, ContentsHelper, EssencesHelper, ElementsBlockHelper, ElementsHelper
Defined in:
app/helpers/alchemy/admin/elements_helper.rb

Instance Method Summary collapse

Methods included from EssencesHelper

#edit_picture_dialog_size, #essence_picture_thumbnail, #pages_for_select, #render_essence_editor, #render_essence_editor_by_name, #render_missing_content

Methods included from ContentsHelper

#content_label, #render_content_name

Methods included from BaseHelper

#alchemy_body_class, #alchemy_datepicker, #button_with_confirm, #clipboard_select_tag_options, #current_alchemy_user_name, #delete_button, #hint_with_tooltip, #js_filter_field, #link_to_confirm_dialog, #link_to_dialog, #link_url_regexp, #max_image_count, #new_asset_path_with_session_information, #page_layout_missing_warning, #render_alchemy_title, #render_hint_for, #sites_for_select, #toolbar, #toolbar_button, #translations_for_select

Methods included from NavigationHelper

#alchemy_main_navigation_entry, #entry_active?, #main_navigation_css_classes, #navigate_module, #sorted_alchemy_modules, #url_for_module, #url_for_module_sub_navigation

Methods included from BaseHelper

#message_icon_class, #page_or_find, #render_flash_notice, #render_icon, #render_message, #shorten, #warning

Methods included from EssencesHelper

#render_essence, #render_essence_view, #render_essence_view_by_name

Methods included from ElementsBlockHelper

#element_editor_for, #element_view_for

Methods included from ElementsHelper

#element_dom_id, #element_preview_code, #element_preview_code_attributes, #element_tags, #element_tags_attributes, #render_element, #render_elements, #sort_elements_by_content

Methods included from UrlHelper

#download_alchemy_attachment_path, #download_alchemy_attachment_url, #full_url_for_element, #show_alchemy_page_path, #show_alchemy_page_url, #show_page_path_params

Instance Method Details

#element_array_for_options(element, object_method, cell = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 85

def element_array_for_options(element, object_method, cell = nil)
  case element
  when Alchemy::Element
    [
      element.display_name_with_preview_text,
      element.send(object_method).to_s + (cell ? "##{cell['name']}" : "")
    ]
  else
    [
      Element.display_name_for(element['name']),
      element[object_method] + (cell ? "##{cell['name']}" : "")
    ]
  end
end

#element_editor_classes(element, local_assigns) ⇒ Object

CSS classes for the element editor partial.



101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 101

def element_editor_classes(element, local_assigns)
  [
    'element-editor',
    element.content_definitions.present? ? 'with-contents' : 'without-contents',
    element.nestable_elements.any? ? 'nestable' : 'not-nestable',
    element.taggable? ? 'taggable' : 'not-taggable',
    element.folded ? 'folded' : 'expanded',
    local_assigns[:draggable] == false ? 'not-draggable' : 'draggable'
  ].join(' ')
end

#elements_for_select(elements) ⇒ Array

Returns an elements array for select helper.

Parameters:

  • elements (Array)

    definitions

Returns:

  • (Array)


48
49
50
51
52
53
54
55
56
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 48

def elements_for_select(elements)
  return [] if elements.nil?
  elements.collect do |e|
    [
      Element.display_name_for(e['name']),
      e['name']
    ]
  end
end

#grouped_elements_for_select(elements, object_method = 'name') ⇒ Object

Returns all elements that can be placed on the current page. The elements will be grouped by cell.

Parameters:

  • elements (Array)

    collection of element objects

  • object_method (String) (defaults to: 'name')

    method that is called on the element objects used for the select option value



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 66

def grouped_elements_for_select(elements, object_method = 'name')
  return [] if elements.blank?
  cells_definition = @page.cell_definitions
  return [] if cells_definition.blank?
  options = {}
  cells_definition.each do |cell|
    cell_elements = elements_for_cell(elements, cell)
    optgroup_label = Cell.translated_label_for(cell['name'])
    options[optgroup_label] = cell_elements.map do |e|
      element_array_for_options(e, object_method, cell)
    end
  end
  options[Alchemy.t(:main_content)] = elements_for_main_content(elements).map do |e|
    element_array_for_options(e, object_method)
  end
  # Remove empty cells
  options.delete_if { |_c, e| e.blank? }
end

#render_editor(element) ⇒ Object

Renders the element editor partial



13
14
15
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 13

def render_editor(element)
  render_element(element, :editor)
end

Renders a drag’n’drop picture gallery editor for all EssencePictures.

It brings full functionality for adding images, deleting images and sorting them via drag’n’drop. Just place this helper inside your element editor view, pass the element as parameter and that’s it.

Options:

:maximum_amount_of_images    [Integer]   # This option let you handle the amount of images your customer can add to this element.


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 26

def render_picture_gallery_editor(element, options = {})
  default_options = {
    maximum_amount_of_images: nil,
    grouped: true
  }
  options = default_options.merge(options)
  render(
    partial: "alchemy/admin/elements/picture_gallery_editor",
    locals: {
      pictures: element.contents.gallery_pictures,
      element: element,
      options: options
    }
  )
end

#show_element_footer?(element, with_nestable_elements = nil) ⇒ Boolean

Tells us, if we should show the element footer.

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 113

def show_element_footer?(element, with_nestable_elements = nil)
  return false if element.folded?
  if with_nestable_elements
    element.content_definitions.present? || element.taggable?
  else
    element.nestable_elements.empty?
  end
end