Module: Cms::ApplicationHelper
- Defined in:
- app/helpers/cms/application_helper.rb
Instance Method Summary collapse
- #action_icon(name, options = {}) ⇒ Object
- #action_icon_src(name) ⇒ Object
-
#add_button(path, options = {}) ⇒ Object
Render a CMS styled ‘Add’ button.
- #categories_for(category_type_name, order = "name") ⇒ Object
-
#check_uncheck_tag(selector) ⇒ Object
Renders two links that will check/uncheck a set of checkboxes.
-
#delete_button(options = {}) ⇒ Object
Render a CMS styled ‘X Delete’ button.
- #determine_order(current_order, order) ⇒ Object
- #dk_button_wrapper(content) ⇒ Object
-
#edit_button(options = {}) ⇒ Object
Render a CMS styled ‘Edit’ button.
- #format_date(time) ⇒ Object
- #group_filter ⇒ Object
- #group_ids ⇒ Object
-
#link_to_check_all(selector, name = "Check All") ⇒ Object
deprecated
Deprecated.
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
-
#link_to_uncheck_all(selector, name = "Uncheck All") ⇒ Object
deprecated
Deprecated.
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
- #link_to_usages(block) ⇒ Object
- #lt_button_wrapper(content) ⇒ Object
- #page_versions(page) ⇒ Object
- #render_pagination(collection, collection_name, options = {}) ⇒ Object
- #require_javascript_include(sources = (), content_area = :html_head) ⇒ Object
- #require_stylesheet_link(sources = (), content_area = :html_head) ⇒ Object
- #searchable_sections(selected = nil) ⇒ Object
- #select_per_page ⇒ Object
- #span_tag(content) ⇒ Object
- #status_icon(status, options = {}) ⇒ Object
- #time_on_date(time) ⇒ Object
- #url_with_mode(url, mode) ⇒ Object
Instance Method Details
#action_icon(name, options = {}) ⇒ Object
49 50 51 |
# File 'app/helpers/cms/application_helper.rb', line 49 def action_icon(name, ={}) image_tag action_icon_src(name), {:alt => name.to_s.titleize}.merge() end |
#action_icon_src(name) ⇒ Object
45 46 47 |
# File 'app/helpers/cms/application_helper.rb', line 45 def action_icon_src(name) "cms/icons/actions/#{name}.png" end |
#add_button(path, options = {}) ⇒ Object
Render a CMS styled ‘Add’ button. This button will appear on tool bars, typically set apart visually from other buttons.
243 244 245 246 247 |
# File 'app/helpers/cms/application_helper.rb', line 243 def (path, ={}) classes = "button" = {:class => classes} link_to span_tag(" Add ".html_safe), path, end |
#categories_for(category_type_name, order = "name") ⇒ Object
161 162 163 164 |
# File 'app/helpers/cms/application_helper.rb', line 161 def categories_for(category_type_name, order="name") cat_type = CategoryType.named(category_type_name).first cat_type ? cat_type.category_list(order) : [] end |
#check_uncheck_tag(selector) ⇒ Object
Renders two links that will check/uncheck a set of checkboxes.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/cms/application_helper.rb', line 79 def check_uncheck_tag(selector) check_id = to_id(selector, "check") uncheck_id = to_id(selector, "uncheck") content_for :html_head do html = <<HTML jQuery(function($) { $('a##{check_id}').click(function() { $('#{selector}').attr('checked', true); }); $('a##{uncheck_id}').click(function() { $('#{selector}').attr('checked', false); }); }) HTML javascript_tag html end "#{link_to "Check All", '#', :id=>check_id}, #{link_to "Uncheck All", '#', :id=>uncheck_id}".html_safe end |
#delete_button(options = {}) ⇒ Object
Render a CMS styled ‘X 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.
212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'app/helpers/cms/application_helper.rb', line 212 def (={}) classes = "button" classes << " disabled" if ![:enabled] classes << " delete_button" classes << " http_delete confirm_with_title" if [:title] link_to_path = [:path] ? [:path] : "#" = {:id => 'delete_button', :class => classes} [:title] = [:title] if (![:title].blank? && [:title].class == String) link_to span_tag("<span class=\"delete_img\"> </span>Delete".html_safe), link_to_path, end |
#determine_order(current_order, order) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/helpers/cms/application_helper.rb', line 192 def determine_order(current_order, order) if current_order == order if order =~ / desc$/i order.sub(/ desc$/i, '') else order << ' desc' end else order end end |
#dk_button_wrapper(content) ⇒ Object
149 150 151 |
# File 'app/helpers/cms/application_helper.rb', line 149 def (content) (content).gsub("lt_button_", "dk_button_") end |
#edit_button(options = {}) ⇒ Object
Render a CMS styled ‘Edit’ button. This button will appear on tool bars, typically set apart visually from other buttons.
230 231 232 233 234 235 236 237 238 |
# File 'app/helpers/cms/application_helper.rb', line 230 def (={}) classes = "button" classes << " disabled" if ![:enabled] link_to_path = [:path] ? [:path] : "#" = {:id => 'edit_button', :class => classes} link_to span_tag(" Edit ".html_safe), link_to_path, end |
#format_date(time) ⇒ Object
72 73 74 |
# File 'app/helpers/cms/application_helper.rb', line 72 def format_date(time) time && "#{time.strftime("%b %e, %Y")}" end |
#group_filter ⇒ Object
157 158 159 |
# File 'app/helpers/cms/application_helper.rb', line 157 def group_filter select_tag("group_id", (Group.all.insert(0, Group.new(:id => nil, :name => "Show All Groups")), "id", "name", params[:group_id].to_i)) end |
#group_ids ⇒ Object
153 154 155 |
# File 'app/helpers/cms/application_helper.rb', line 153 def group_ids (params[:group_ids] || @user.group_ids).collect { |g| g.to_i } end |
#link_to_check_all(selector, name = "Check All") ⇒ Object
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/cms/application_helper.rb', line 101 def link_to_check_all(selector, name="Check All") id = to_id(selector, "check") content_for :html_head do html = <<HTML jQuery(function($) { $('a##{id}').click(function() { $('#{selector}').attr('checked', true); }); }) HTML javascript_tag html end link_to name, '#', :id=>id end |
#link_to_uncheck_all(selector, name = "Uncheck All") ⇒ Object
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/cms/application_helper.rb', line 117 def link_to_uncheck_all(selector, name="Uncheck All") id = to_id(selector, "uncheck") content_for :html_head do html = <<HTML jQuery(function($) { $('a##{id}').click(function() { $('#{selector}').attr('checked', false); }); }) HTML javascript_tag html end link_to name, '#', :id=>id end |
#link_to_usages(block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/cms/application_helper.rb', line 57 def link_to_usages(block) count = block.connected_pages.count if count > 0 # Would love a cleaner solution to this problem, see http://stackoverflow.com/questions/702728 path = Portlet === block ? usages_cms_portlet_path(block) : [:usages, :cms, block] link_to count, path, :id => block.id, :block_type => block.content_block_type else count end end |
#lt_button_wrapper(content) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/helpers/cms/application_helper.rb', line 136 def (content) = <<LBW <div class="lt_button"> <img src="/images/cms/lt_button_l.gif" alt="" /> <div class="lt_button_content"> <span>#{ content }</span> </div> <img src="/images/cms/lt_button_r.gif" alt="" style="margin-right: 10px;" /> </div> LBW .html_safe end |
#page_versions(page) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/cms/application_helper.rb', line 35 def page_versions(page) text = select_tag(:version, (page.versions.all(:order => "version desc").map { |r| ["v#{r.version}: #{r.version_comment} by #{r.updated_by.login} at #{time_on_date(r.updated_at)}", r.version] }, page.version), :onchange => 'this.form.submit(); return false') text << javascript_tag("$('version').selectedIndex = 0") if page.live? text end |
#render_pagination(collection, collection_name, options = {}) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/helpers/cms/application_helper.rb', line 166 def render_pagination(collection, collection_name, ={}) if collection.blank? content_tag(:div, "No Content", :class => "pagination") else render :partial => "cms/shared/pagination", :locals => { :collection => collection, :first_page_path => send("cms_#{collection_name}_path", {:page => 1}.merge()), :previous_page_path => send("cms_#{collection_name}_path", {:page => collection.previous_page ? collection.previous_page : 1}.merge()), :current_page_path => send("cms_#{collection_name}_path", ), :next_page_path => send("cms_#{collection_name}_path", {:page => collection.next_page ? collection.next_page : collection.current_page}.merge()), :last_page_path => send("cms_#{collection_name}_path", {:page => collection.total_pages}.merge()) } end end |
#require_javascript_include(sources = (), content_area = :html_head) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/helpers/cms/application_helper.rb', line 14 def require_javascript_include(sources=(), content_area=:html_head) @required_javascript_includes ||= [] new_links = Array(sources) - @required_javascript_includes if !new_links.empty? @required_javascript_includes |= new_links content_for(content_area, javascript_include_tag(new_links)) end end |
#require_stylesheet_link(sources = (), content_area = :html_head) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/helpers/cms/application_helper.rb', line 5 def require_stylesheet_link(sources=(), content_area=:html_head) @required_stylesheet_links ||= [] new_links = Array(sources) - @required_stylesheet_links if !new_links.empty? @required_stylesheet_links |= new_links content_for(content_area, stylesheet_link_tag(new_links)) end end |
#searchable_sections(selected = nil) ⇒ Object
23 24 25 26 27 28 |
# File 'app/helpers/cms/application_helper.rb', line 23 def searchable_sections(selected = nil) root = Section.root.first = [['All sections', 'all'], [root.name, root.id]] root.all_children_with_name.each { |s| << [s.full_path, s.id] } (, selected.to_i) end |
#select_per_page ⇒ Object
30 31 32 33 |
# File 'app/helpers/cms/application_helper.rb', line 30 def select_per_page = [10, 20, 50, 100].collect { |c| ["#{c} per page", c] } select_tag("per_page", (, params[:per_page].to_i)) end |
#span_tag(content) ⇒ Object
132 133 134 |
# File 'app/helpers/cms/application_helper.rb', line 132 def span_tag(content) content_tag :span, content end |
#status_icon(status, options = {}) ⇒ Object
53 54 55 |
# File 'app/helpers/cms/application_helper.rb', line 53 def status_icon(status, ={}) image_tag "cms/icons/status/#{status.to_s.underscore}.gif", {:alt => status.to_s.titleize}.merge() end |
#time_on_date(time) ⇒ Object
68 69 70 |
# File 'app/helpers/cms/application_helper.rb', line 68 def time_on_date(time) time && "#{time.strftime("%l:%M %p")} on #{time.strftime("%b %e, %Y")}" end |
#url_with_mode(url, mode) ⇒ Object
181 182 183 184 185 186 187 188 189 190 |
# File 'app/helpers/cms/application_helper.rb', line 181 def url_with_mode(url, mode) uri = URI.parse(url) if uri.query =~ /mode=[^&]*/ "#{uri.path}?#{uri.query.gsub(/((^|&)mode=)[^&]*/) { |s| "#{$1}#{mode}" }}" elsif uri.query "#{uri.path}?#{uri.query}&mode=#{mode}" else "#{uri.path}?mode=#{mode}" end end |