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, #js_filter_field, #link_to_confirm_dialog, #link_to_dialog, #link_url_regexp, #max_image_count, #merge_params, #merge_params_only, #merge_params_without, #new_asset_path_with_session_information, #render_alchemy_title, #render_hint_for, #sites_for_select, #toolbar, #toolbar_button, #translations_for_select

Methods included from NavigationHelper

#admin_subnavigation, #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

#_t, #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_alchemy_picture_path, #show_alchemy_picture_url, #show_page_path_params, #show_picture_path_params

Instance Method Details

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



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

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

#element_editor_classes(element, local_assigns) ⇒ Object

CSS classes for the element editor partial.



117
118
119
120
121
122
123
124
125
126
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 117

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)


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

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



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

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



11
12
13
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 11

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.


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

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)


129
130
131
132
133
134
135
136
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 129

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

#update_essence_select_elements(page, element) ⇒ Object

This helper loads all elements from page that have EssenceSelects in them.

It returns a javascript function that replaces all editor partials of this elements.

We need this while updating, creating or trashing an element, because another element on the same page could have a element selector in it.

In cases like this one wants Ember.js databinding!



106
107
108
109
110
111
112
113
114
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 106

def update_essence_select_elements(page, element)
  elements = page.elements.not_trashed.joins(:contents)
    .where(["#{Content.table_name}.element_id != ?", element.id])
    .where(Content.table_name => {essence_type: "Alchemy::EssenceSelect"})
  return if elements.blank?
  elements.collect do |el|
    render 'alchemy/admin/elements/refresh_editor', element: el
  end.join.html_safe
end