Module: Cms::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#action_icon(name, options = {}) ⇒ Object



37
38
39
# File 'app/helpers/cms/application_helper.rb', line 37

def action_icon(name, options={})
  image_tag action_icon_src(name), {:alt => name.to_s.titleize}.merge(options)
end

#action_icon_src(name) ⇒ Object



33
34
35
# File 'app/helpers/cms/application_helper.rb', line 33

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.

Parameters:

  • The (Path)

    path or URL to link_to. Takes same types at url_for or link_to.



228
229
230
231
232
# File 'app/helpers/cms/application_helper.rb', line 228

def add_button(path, options={})
  classes = "button"
  span_options = {:class => classes}
  link_to span_tag(" Add ".html_safe), path, span_options
end

#categories_for(category_type_name, order = "name") ⇒ Object

Fetches a list of categories for a cms_drop_down. Will prompt users to create Categories/Categories types if the proper ones don't exist.



139
140
141
142
143
# File 'app/helpers/cms/application_helper.rb', line 139

def categories_for(category_type_name, order="name")
  cat_type = CategoryType.named(category_type_name).first
  categories = cat_type ? cat_type.category_list(order) : [Category.new(:name => "-- You must first create a 'Category Type' named '#{category_type_name}'")]
  categories.empty? ? [Category.new(:name => "-- You must first create a Category with a Category Type of '#{category_type_name}'.")] : categories
end

#check_uncheck_tag(selector) ⇒ Object

Renders two links that will check/uncheck a set of checkboxes.

Parameters:

  • selector (String)

    The CSS selector for the checkboxes that should be mass checked/unchecked.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/cms/application_helper.rb', line 56

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

#cms_handler_path(*args) ⇒ Object

Deprecated.

Help with deprecations messages



7
8
9
# File 'app/helpers/cms/application_helper.rb', line 7

def cms_handler_path(*args)
  raise "The #cms_handler_path helper method has been removed from BrowserCMS. Use '#handler_path instead'."
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.

Parameters:

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

    The options for this tag

Options Hash (options):

  • :title (String or Boolean)

    Title for 'confirm' popup. If specified as 'true' or with a string value a standard 'confirm yes/no' window should be used. If true is specified, its assume that the javascript popup handles the title.

  • :path (Path)

    The path or URL to link_to. Takes same types at url_for or link_to. Defaults to '#' if not specified.

  • :enabled (Boolean)

    If false, the button will be marked disabled. Default to false.



197
198
199
200
201
202
203
204
205
206
207
208
# File 'app/helpers/cms/application_helper.rb', line 197

def delete_button(options={})
  classes = "button"
  classes << " disabled" if !options[:enabled]
  classes << " delete_button"
  classes << " http_delete confirm_with_title" if options[:title]

  link_to_path = options[:path] ? options[:path] : "#"

  span_options = {:id => 'delete_button', :class => classes}
  span_options[:title] = options[:title] if (!options[:title].blank? && options[:title].class == String)
  link_to span_tag("<span class=\"delete_img\">&nbsp;</span>Delete".html_safe), link_to_path, span_options
end

#determine_order(current_order, order) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
# File 'app/helpers/cms/application_helper.rb', line 177

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



126
127
128
# File 'app/helpers/cms/application_helper.rb', line 126

def dk_button_wrapper(content)
  lt_button_wrapper(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.

Parameters:

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

    The options for this tag

Options Hash (options):

  • :path (Path)

    The path or URL to link_to. Takes same types at url_for or link_to. Defaults to '#' if not specified.

  • :enabled (Boolean)

    If false, the button will be marked disabled. Default to false.



215
216
217
218
219
220
221
222
223
# File 'app/helpers/cms/application_helper.rb', line 215

def edit_button(options={})
  classes = "button"
  classes << " disabled" if !options[:enabled]

  link_to_path = options[:path] ? options[:path] : "#"
  span_options = {:id => 'edit_button', :class => classes}
  link_to span_tag("&nbsp;Edit&nbsp;".html_safe), link_to_path, span_options

end

#format_date(time) ⇒ Object



49
50
51
# File 'app/helpers/cms/application_helper.rb', line 49

def format_date(time)
  time && "#{time.strftime("%b %e, %Y")}"
end

#group_filterObject



134
135
136
# File 'app/helpers/cms/application_helper.rb', line 134

def group_filter
  select_tag("group_id", options_from_collection_for_select(Group.all.insert(0, Group.new(:id => nil, :name => "Show All Groups")), "id", "name", params[:group_id].to_i))
end

#group_idsObject



130
131
132
# File 'app/helpers/cms/application_helper.rb', line 130

def group_ids
  (params[:group_ids] || @user.group_ids).collect { |g| g.to_i }
end
Deprecated.

Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/cms/application_helper.rb', line 78

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
Deprecated.

Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/cms/application_helper.rb', line 94

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

#lt_button_wrapper(content) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/cms/application_helper.rb', line 113

def lt_button_wrapper(content)
  button = <<LBW
  <div class="lt_button">
#{image_tag "cms/lt_button_l.gif"}
<div class="lt_button_content">
  <span>#{ content }</span>
</div>
#{image_tag "cms/lt_button_r.gif", :style => "margin-right: 10px;"}
  </div>
LBW
  button.html_safe
end

#page_versions(page) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'app/helpers/cms/application_helper.rb', line 23

def page_versions(page)
  text = select_tag(:version,
                    options_for_select(page.versions.all(:order => "version desc").map { |r|
                      ["v#{r.version}: #{r.version_comment} by #{r.updated_by.} 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, content_type, options = {}) ⇒ Object

Generates the HTML to render a paging control, if there is more than one page to be shown.

Parameters:

  • collection (Array)

    List of content to be shown

  • content_type (Cms::ContentType)

    The content type of the collection (used to generate links to Previous/Next)

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


150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/helpers/cms/application_helper.rb', line 150

def render_pagination(collection, content_type, options={})
  if collection.blank?
    (:div, "No Content", :class => "pagination")
  else
    render :partial => "cms/shared/pagination", :locals => {
        :collection => collection,
        :first_page_path => cms_connectable_path(content_type, {:page => 1}.merge(options)),
        :previous_page_path => cms_connectable_path(content_type, {:page => collection.previous_page ? collection.previous_page : 1}.merge(options)),
        :current_page_path => cms_connectable_path(content_type, options),
        :next_page_path => cms_connectable_path(content_type, {:page => collection.next_page ? collection.next_page : collection.current_page}.merge(options)),
        :last_page_path => cms_connectable_path(content_type, {:page => collection.total_pages}.merge(options))
    }
  end
end

#searchable_sections(selected = nil) ⇒ Object



11
12
13
14
15
16
# File 'app/helpers/cms/application_helper.rb', line 11

def searchable_sections(selected = nil)
  root = Section.root.first
  options = [['All sections', 'all'], [root.name, root.id]]
  root.master_section_list.each { |s| options << [s.full_path, s.id] }
  options_for_select(options, selected.to_i)
end

#select_per_pageObject



18
19
20
21
# File 'app/helpers/cms/application_helper.rb', line 18

def select_per_page
  options = [10, 20, 50, 100].collect { |c| ["#{c} per page", c] }
  select_tag("per_page", options_for_select(options, params[:per_page].to_i))
end

#span_tag(content) ⇒ Object



109
110
111
# File 'app/helpers/cms/application_helper.rb', line 109

def span_tag(content)
   :span, content
end

#status_icon(status, options = {}) ⇒ Object



41
42
43
# File 'app/helpers/cms/application_helper.rb', line 41

def status_icon(status, options={})
  image_tag "cms/icons/status/#{status.to_s.underscore}.gif", {:alt => status.to_s.titleize}.merge(options)
end

#time_on_date(time) ⇒ Object



45
46
47
# File 'app/helpers/cms/application_helper.rb', line 45

def time_on_date(time)
  time && "#{time.strftime("%l:%M %p")} on #{time.strftime("%b %e, %Y")}"
end

#url_with_mode(url, mode) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
# File 'app/helpers/cms/application_helper.rb', line 165

def url_with_mode(url, mode)
  url = "" unless url # Handles cases where request.referrer is nil (see cms/_page_toolbar.html.erb for an example)
  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