Module: Cms::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#able_to?(*perms, &block) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/helpers/cms/application_helper.rb', line 107

def able_to?(*perms, &block)
  yield if current_user.able_to?(*perms)
end

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



68
69
70
# File 'app/helpers/cms/application_helper.rb', line 68

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

#action_icon_src(name) ⇒ Object



64
65
66
# File 'app/helpers/cms/application_helper.rb', line 64

def action_icon_src(name)
  "cms/icons/actions/#{name}.png"
end

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



137
138
139
140
# File 'app/helpers/cms/application_helper.rb', line 137

def categories_for(category_type_name, order="name")
  cat_type = CategoryType.named(category_type_name).first
  cat_type ? cat_type.category_list(order) : []
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

#format_date(time) ⇒ Object



95
96
97
# File 'app/helpers/cms/application_helper.rb', line 95

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

#group_filterObject



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

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



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

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


99
100
101
# File 'app/helpers/cms/application_helper.rb', line 99

def link_to_check_all(selector, name="Check All")
  link_to_function name, "$('#{selector}').attr('checked', true)"
end


103
104
105
# File 'app/helpers/cms/application_helper.rb', line 103

def link_to_uncheck_all(selector, name="Uncheck All")
  link_to_function name, "$('#{selector}').attr('checked', false)"
end


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

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



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

def lt_button_wrapper(content)
<<LBW
  <div class="lt_button">
<img src="/images/cms/lt_button_l.gif" alt="" />
<div>
  #{ content }
</div>
<img src="/images/cms/lt_button_r.gif" alt="" style="margin-right: 10px;" />
  </div>
LBW
end

#page_title(*args) ⇒ Object



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

def page_title(*args)
  if args.first
    @controller.instance_variable_get("@template").instance_variable_set("@page_title", args.first)
  else
    @controller.instance_variable_get("@template").instance_variable_get("@page_title")
  end
end

#page_versions(page) ⇒ Object



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

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_cms_toolbar(tab = :dashboard) ⇒ Object



76
77
78
# File 'app/helpers/cms/application_helper.rb', line 76

def render_cms_toolbar(tab=:dashboard)
  render :partial => 'layouts/cms_toolbar', :locals => {:tab => tab}    
end

#render_connectable(content_block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/cms/application_helper.rb', line 48

def render_connectable(content_block)
  if content_block
    if content_block.class.renderable?
      logger.info "..... Rendering connectable #{content_block.class} ##{content_block.id} #{"v#{content_block.version}" if content_block.respond_to?(:version)}"
      content_block.perform_render(@controller)
    else
      logger.warn "Connectable #{content_block.class} ##{content_block.id} is not renderable"
    end
  else
    logger.warn "Connectable is null"
  end    
rescue Exception => e
  logger.error "Error occurred while rendering #{content_block.class}##{content_block.id}: #{e.message}\n#{e.backtrace.join("\n")}"
  "ERROR: #{e.message}"
end

#render_connector(connector) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/cms/application_helper.rb', line 35

def render_connector(connector)
  connectable = connector.connectable_with_deleted
  if logged_in? && @mode == "edit"
    if connectable.class.versioned?
      connectable = connectable.as_of_version(connector.connectable_version)
    end
    render :partial => 'cms/pages/edit_connector', 
      :locals => { :connector => connector, :connectable => connectable}
  else
    render_connectable(connectable)
  end
end

#render_pagination(collection, collection_name, options = {}) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/helpers/cms/application_helper.rb', line 142

def render_pagination(collection, collection_name, options={})
  if collection.blank?
    (: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(options)),
      :previous_page_path => send("cms_#{collection_name}_path", {:page => collection.previous_page ? collection.previous_page : 1}.merge(options)),
      :current_page_path => send("cms_#{collection_name}_path", options),
      :next_page_path => send("cms_#{collection_name}_path", {:page => collection.next_page ? collection.next_page : collection.current_page}.merge(options)),
      :last_page_path => send("cms_#{collection_name}_path", {:page => collection.total_pages}.merge(options))
    }
  end
end

#searchable_sections(selected = nil) ⇒ Object



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

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

#select_per_pageObject



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

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



111
112
113
# File 'app/helpers/cms/application_helper.rb', line 111

def span_tag(content)
   :span, content
end

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



72
73
74
# File 'app/helpers/cms/application_helper.rb', line 72

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

#tb_iframe(path, options = {}) ⇒ Object



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

def tb_iframe(path, options={})
  # The order of the parameters matters.  All parameters that should be sent to the server,
  # have to appear before TB_iframe.  All parameters that shouldn't be sent to the server and
  # that are just there for Thickbox should be after TB_iframe
  {:height => 600, :width => 600, :modal => true}.merge(options).inject("#{path}&TB_iframe=true") do |s, (k,v)|
    s << "&#{k}=#{CGI::escape(v.to_s)}"
  end
end

#time_on_date(time) ⇒ Object



91
92
93
# File 'app/helpers/cms/application_helper.rb', line 91

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

#url_with_mode(url, mode) ⇒ Object



157
158
159
160
161
162
163
164
165
166
# File 'app/helpers/cms/application_helper.rb', line 157

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