Module: Cms::UiElementsHelper

Defined in:
app/helpers/cms/ui_elements_helper.rb

Overview

Defines functions for creating buttons and links using the CMS styling. I.e. Menus, Save, Publish buttons and links.

Instance Method Summary collapse

Instance Method Details

#bottom_buttons(form, partial_name = "buttons") ⇒ Object



25
26
27
# File 'app/helpers/cms/ui_elements_helper.rb', line 25

def bottom_buttons(form, partial_name="buttons")
  render(partial: partial_name, locals: {f: form, location: :bottom}, layout: 'row')
end

#button_menu(location) ⇒ Object



13
14
15
16
17
18
19
# File 'app/helpers/cms/ui_elements_helper.rb', line 13

def button_menu(location)
  container_class = location == :top ? 'span6 top-buttons' : 'form-actions clearfix'
  container_element = location == :top ? 'span' : 'div'
   container_element, class: container_class do
    yield if block_given?
  end
end

#cancel_button(location, label = "Cancel") ⇒ Object



7
8
9
10
11
# File 'app/helpers/cms/ui_elements_helper.rb', line 7

def cancel_button(location, label="Cancel")
  klass = ['btn']
  klass << 'btn-small' if location == :top
  link_to label, :back, class: klass
end

#delete_menu_button(content_item = nil, opts = {class: []}) ⇒ Object

Render a CMS styled ‘Delete’ button. This button will appear on tool bars, typically set apart visually from other buttons. Has a ‘confirm?’ popup attached to it as well. Assumes that javascript code to handle the ‘confirm’ has already been included in the page.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'app/helpers/cms/ui_elements_helper.rb', line 119

def delete_menu_button(content_item=nil, opts={class: []})
  classes = ["btn", "http_delete", "confirm_with_title"]
  if current_user.able_to_publish?(content_item)
    classes << 'btn-primary'
  else
    classes << 'disabled'
  end

  link_to_path = "#"
  options = {:id => 'delete_button', :class => classes}
  options[:class].concat(opts[:class]) if opts[:class]

  if content_item == nil || content_item.new_record?
    classes << 'disabled'
  else
    options[:title] = "Are you sure you want to delete '#{content_item.name}'?"
    link_to_path = engine_aware_path(content_item, nil)
  end
  if opts[:title]
    options[:title] = opts[:title]
  end
  link_to "Delete", link_to_path, options
end

#divider_tag(index = 1) ⇒ Object

Used by Twitter Bootstrap dropdown menus used to divide groups of menu items.

Parameters:

  • index (Integer) (defaults to: 1)


153
154
155
# File 'app/helpers/cms/ui_elements_helper.rb', line 153

def divider_tag(index = 1)
  (:li, "&nbsp;", {class: "divider"}) if index != 0
end

#edit_content_menu_button(content_item) ⇒ Object



61
62
63
64
65
66
67
# File 'app/helpers/cms/ui_elements_helper.rb', line 61

def edit_content_menu_button(content_item)
  path = "#"
  unless content_item.new_record?
    path = edit_engine_aware_path(content_item)
  end
  link_to "Edit Content", path, class: "btn btn-primary", id: "edit_button"
end

Generic bootstrap based menu button

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :enabled (Boolean)
  • :class (Array<String>)

    An array of additional classes to apply



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/cms/ui_elements_helper.rb', line 82

def menu_button(label, path, options={})
  defaults = {
      enabled: true,
      pull: 'left'
  }
  options = defaults.merge!(options)
  options[:class] = %w{btn btn-primary}
  if (options[:pull] == 'left' || options[:pull]== 'right')
    options[:class] << "pull-#{options.delete(:pull)}"
  end

  options[:class] << 'disabled' unless options[:enabled]
  options.delete(:enabled)
  options[:class] << 'http_put' if options[:method] == :put
  options[:class] << 'http_delete' if options[:method] == :delete
  options[:class] << 'confirm_with_title' if options[:method] == :delete

  options.delete(:method)
  copy_title(options, options)
  link_to(label, path, options)
end


157
158
159
# File 'app/helpers/cms/ui_elements_helper.rb', line 157

def nav_link_to(name, link, options={})
  (:li, link_to(name, link, options))
end

#page_title_with_buttons(form, partial_name = "buttons") ⇒ Object



21
22
23
# File 'app/helpers/cms/ui_elements_helper.rb', line 21

def page_title_with_buttons(form, partial_name="buttons")
  render(partial: partial_name, locals: {f: form, location: :top}, layout: 'page_title')
end

#publish_button(type) ⇒ Object

For simple publish buttons



42
43
44
45
# File 'app/helpers/cms/ui_elements_helper.rb', line 42

def publish_button(type)
  html = %Q{<button type="submit" name="#{type}[publish_on_save]" value="true" class="submit btn btn-primary"><span>Save And Publish</span></button>'}
  html.html_safe
end

#publish_menu_button(content_item) ⇒ Object

Renders a Publish button for the menu based on whether:

1. The current user can publish
2. The content item can or needs to be published.


50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/cms/ui_elements_helper.rb', line 50

def publish_menu_button(content_item)
  options = {class: ["btn", "btn-primary", "http_put"], id: "publish_button"}
  path = "#"
  if current_user.able_to?(:publish_content) && !content_item.new_record? && content_item.respond_to?(:live?) && !content_item.live?
    path = engine(@block).polymorphic_path([:publish, @block])
  else
    options[:class] << "disabled"
  end
  link_to "Publish", path, options
end

#save_and_publish_button(block, content_type) ⇒ Object

Renders a Save And Publish button if:

  1. Current User has publish rights

  2. Block is publishable



34
35
36
37
38
39
# File 'app/helpers/cms/ui_elements_helper.rb', line 34

def save_and_publish_button(block, content_type)
  if current_user.able_to?(:publish_content) && block.publishable?
    html = %Q{<button type="submit" name="#{content_type.content_block_type.singularize}[publish_on_save]" value="true" class="submit btn btn-primary" tabindex="#{next_tabindex}"><span>Save And Publish</span></button>}
    html.html_safe
  end
end

#select_content_type_tag(type, &block) ⇒ Object



143
144
145
146
147
148
149
# File 'app/helpers/cms/ui_elements_helper.rb', line 143

def select_content_type_tag(type, &block)
  options = {:rel => "select-#{type.param_key}"}
  if (defined?(content_type) && content_type == type)
    options[:class] = "on"
  end
  (:li, type, nil, options, &block)
end

#versions_menu_button(content_item) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'app/helpers/cms/ui_elements_helper.rb', line 104

def versions_menu_button(content_item)
  options = {class: ["btn", "btn-primary"], id: "revisions_button"}
  path = "#"
  if !content_item.new_record? && content_item.class.versioned?
    path = engine(content_item).polymorphic_path([:versions, content_item])
  else
    options[:class] << "disabled"
  end
  link_to "List Versions", path, options
end

#view_content_menu_button(content_item) ⇒ Object



69
70
71
72
73
74
75
# File 'app/helpers/cms/ui_elements_helper.rb', line 69

def view_content_menu_button(content_item)
  path = "#"
  unless content_item.new_record?
    path = engine_aware_path(content_item, nil)
  end
  link_to "View Content", path, class: "btn btn-primary", id: "view_button"
end