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
- #bottom_buttons(form, partial_name = "buttons") ⇒ Object
- #button_menu(location) ⇒ Object
- #cancel_button(location, label = "Cancel") ⇒ Object
-
#delete_menu_button(content_item = nil, opts = {class: []}) ⇒ Object
Render a CMS styled ‘Delete’ button.
-
#divider_tag(index = 1) ⇒ Object
Used by Twitter Bootstrap dropdown menus used to divide groups of menu items.
- #edit_content_menu_button(content_item) ⇒ Object
-
#menu_button(label, path, options = {}) ⇒ Object
Generic bootstrap based menu button.
- #nav_link_to(name, link, options = {}) ⇒ Object
- #page_title_with_buttons(form, partial_name = "buttons") ⇒ Object
-
#publish_button(type) ⇒ Object
For simple publish buttons.
-
#publish_menu_button(content_item) ⇒ Object
Renders a Publish button for the menu based on whether: 1.
-
#save_and_publish_button(block, content_type) ⇒ Object
Renders a Save And Publish button if: 1.
- #select_content_type_tag(type, &block) ⇒ Object
- #versions_menu_button(content_item) ⇒ Object
- #view_content_menu_button(content_item) ⇒ Object
Instance Method Details
#bottom_buttons(form, partial_name = "buttons") ⇒ Object
25 26 27 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 25 def (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 (location) container_class = location == :top ? 'span6 top-buttons' : 'form-actions clearfix' container_element = location == :top ? 'span' : 'div' content_tag 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 (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.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 121 def (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 = "#" = {:id => 'delete_button', :class => classes} [:class].concat(opts[:class]) if opts[:class] if content_item == nil || content_item.new_record? classes << 'disabled' else [:title] = "Are you sure you want to delete '#{content_item.name}'?" link_to_path = engine_aware_path(content_item, nil) end if opts[:title] [:title] = opts[:title] end link_to "Delete", link_to_path, end |
#divider_tag(index = 1) ⇒ Object
Used by Twitter Bootstrap dropdown menus used to divide groups of menu items.
155 156 157 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 155 def divider_tag(index = 1) content_tag(:li, " ", {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 (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 |
#menu_button(label, path, options = {}) ⇒ Object
Generic bootstrap based menu button
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 82 def (label, path, ={}) return '' unless path.present? defaults = { enabled: true, pull: 'left' } = defaults.merge!() [:class] = [:class].presence || %w{btn btn-primary} if [:pull] == 'left' || [:pull] == 'right' [:class] << "pull-#{options.delete(:pull)}" end [:class] << 'disabled' unless [:enabled] .delete(:enabled) [:class] << 'http_put' if [:method] == :put [:class] << 'http_delete' if [:method] == :delete [:class] << 'confirm_with_title' if [:method] == :delete .delete(:method) copy_title(, ) link_to(label, path, ) end |
#nav_link_to(name, link, options = {}) ⇒ Object
159 160 161 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 159 def nav_link_to(name, link, ={}) content_tag(:li, link_to(name, link, )) end |
#page_title_with_buttons(form, partial_name = "buttons") ⇒ Object
21 22 23 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 21 def (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 (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 (content_item) = {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 [:class] << "disabled" end link_to "Publish", path, end |
#save_and_publish_button(block, content_type) ⇒ Object
Renders a Save And Publish button if:
-
Current User has publish rights
-
Block is publishable
34 35 36 37 38 39 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 34 def (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
145 146 147 148 149 150 151 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 145 def select_content_type_tag(type, &block) = {:rel => "select-#{type.param_key}"} if (defined?(content_type) && content_type == type) [:class] = "on" end content_tag_for(:li, type, nil, , &block) end |
#versions_menu_button(content_item) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'app/helpers/cms/ui_elements_helper.rb', line 106 def (content_item) = {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 [:class] << "disabled" end link_to "List Versions", path, 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 (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 |