Module: Alchemy::Admin::ElementsHelper
- Includes:
- BaseHelper, ContentsHelper, EssencesHelper, ElementsBlockHelper, ElementsHelper
- Defined in:
- app/helpers/alchemy/admin/elements_helper.rb
Instance Method Summary collapse
- #element_array_for_options(e, object_method, cell = nil) ⇒ Object
-
#elements_for_select(elements) ⇒ Array
Returns an elements array for select helper.
-
#grouped_elements_for_select(elements, object_method = 'name') ⇒ Object
Returns all elements that can be placed on the current page.
-
#render_editor(element) ⇒ Object
Renders the element editor partial.
-
#render_picture_gallery_editor(element, options = {}) ⇒ Object
(also: #render_picture_editor)
Renders a drag’n’drop picture gallery editor for all EssencePictures.
-
#update_essence_select_elements(page, element) ⇒ Object
This helper loads all elements from page that have EssenceSelects in them.
Methods included from EssencesHelper
#essence_picture_thumbnail, #pages_for_select, #render_essence_editor, #render_essence_editor_by_name, #render_missing_content
Methods included from ContentsHelper
#delete_content_link, #label_and_remove_link, #render_content_name, #render_create_content_link, #render_new_content_link
Methods included from BaseHelper
#alchemy_datepicker, #body_class, #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, #render_resources, #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, #parse_sitemap_name, #render_flash_notice, #render_icon, #render_message, #shorten, #warning
Methods included from EssencesHelper
#content_settings_value, #render_essence, #render_essence_picture_view, #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 (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 |
#elements_for_select(elements) ⇒ Array
Returns an elements array for select helper.
47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 47 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.
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 65 def grouped_elements_for_select(elements, object_method = 'name') return [] if elements.blank? cells_definition = @page.cell_definitions return [] if cells_definition.blank? = {} cells_definition.each do |cell| cell_elements = elements_for_cell(elements, cell) optgroup_label = Cell.translated_label_for(cell['name']) [optgroup_label] = cell_elements.map do |e| (e, object_method, cell) end end [_t(:main_content)] = elements_for_main_content(elements).map do |e| (e, object_method) end .delete_if { |_cell, elements| elements.blank? } # Throw out empty cells end |
#render_editor(element) ⇒ Object
Renders the element editor partial
12 13 14 |
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 12 def render_editor(element) render_element(element, :editor) end |
#render_picture_gallery_editor(element, options = {}) ⇒ Object Also known as: render_picture_editor
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.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/alchemy/admin/elements_helper.rb', line 25 def render_picture_gallery_editor(element, ={}) = { :maximum_amount_of_images => nil, :grouped => true } = .merge() render( :partial => "alchemy/admin/elements/picture_gallery_editor", :locals => { :pictures => element.contents.gallery_pictures, :element => element, :options => } ) 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 |element| render 'alchemy/admin/elements/refresh_editor', element: element end.join.html_safe end |