Module: Alchemy::Admin::ContentsHelper

Includes:
BaseHelper
Included in:
ElementsHelper, EssencesHelper
Defined in:
app/helpers/alchemy/admin/contents_helper.rb

Instance Method Summary collapse

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

Instance Method Details

Renders a link for removing that content



94
95
96
97
98
99
100
101
102
# File 'app/helpers/alchemy/admin/contents_helper.rb', line 94

def delete_content_link(content)
  link_to_confirm_dialog(
    render_icon('delete-small'),
    _t('Do you really want to delete this content?'),
    alchemy.admin_content_path(content),
    class: 'icon_button small',
    title: _t('Remove this content')
  ) if content.settings[:deletable]
end

Renders the label and a remove link for a content.



105
106
107
108
109
# File 'app/helpers/alchemy/admin/contents_helper.rb', line 105

def label_and_remove_link(content)
   :label do
    [render_hint_for(content), render_content_name(content), delete_content_link(content)].compact.join(' ').html_safe
  end
end

#render_content_name(content) ⇒ Object

Renders the name of elements content.

Displays a warning icon if content is missing its description.

Displays a mandatory field indicator, if the content has validations.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/alchemy/admin/contents_helper.rb', line 12

def render_content_name(content)
  if content.blank?
    warning('Content is nil')
    return
  else
    content_name = content.name_for_label
  end
  if content.description.blank?
    warning("Content #{content.name} is missing its description")
    title = _t(:content_description_missing)
    content_name = %(<span class="warning icon" title="#{title}"></span>&nbsp;#{content_name}).html_safe
  end
  if content.has_validations?
    "#{content_name}<span class='validation_indicator'>*</span>".html_safe
  else
    content_name
  end
end

Renders a link that dynamically adds an additional content into your element editor view.

NOTE: You have to define additional contents in your elements.yml file first.

Example:

# config/alchemy/elements.yml
- name: downloads:
  contents:
  - name: file
    type: EssenceFile
  additional_contents:
  - name: file
    type: EssenceFile

Then add this helper into the elements editor view partial:

<%= render_create_content_link(element, 'file') %>

Optionally you can pass a label:

<%= render_create_content_link(element, 'file', label: 'Add a file') %>


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/alchemy/admin/contents_helper.rb', line 74

def render_create_content_link(element, content_name, options = {}, options_for_content = {})
  defaults = {
    label: _t('Add %{name}', name: _t(content_name, scope: :content_names))
  }
  options = defaults.merge(options)
  link_to(render_icon(:create) + options[:label], alchemy.admin_contents_path(
      content: {
        name: content_name,
        element_id: element.id
      },
      options: options_for_content.to_json
    ),
    method: :post,
    remote: true,
    id: "add_content_for_element_#{element.id}",
    class: 'button with_icon new_content_link'
  )
end

Renders a link to show the new content overlay that lets you add additional contents.

See render_create_content_link helper for examples on how to define additional contents.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/alchemy/admin/contents_helper.rb', line 35

def render_new_content_link(element)
  link_to_dialog(
    "#{render_icon(:create)} #{_t('add new content')}".html_safe,
    alchemy.new_admin_element_content_path(element),
    {
      size: '310x115',
      title: _t('Select an content'),
      overflow: true
    },
    {
      id: "add_content_for_element_#{element.id}",
      class: 'button with_icon new_content_link'
    }
  )
end