Module: Cms::CommonHelper

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

Instance Method Summary collapse

Instance Method Details

#asset_preview_optionObject



104
105
106
# File 'app/helpers/cms/common_helper.rb', line 104

def asset_preview_option
  cookie_jar('toggle')['on'] == false ? 'style="display:none"' : ''
end

#cms_ajax_update_form(page, object, path) ⇒ Object



28
29
30
31
32
33
34
# File 'app/helpers/cms/common_helper.rb', line 28

def cms_ajax_update_form(page, object, path)
  if object.errors.empty?
    page << cms_flash_message
  else
    page.replace_html 'content', :file => "cms/#{path}/edit.html.erb"
  end
end

#cms_flash_messageObject



14
15
16
17
# File 'app/helpers/cms/common_helper.rb', line 14

def cms_flash_message
  type = (flash[:error] ? :error : :notice)
  flash[type].present? ? "humanMsg.displayMsg('#{escape_javascript(flash[type])}', '#{type}')" : nil
end

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



10
11
12
# File 'app/helpers/cms/common_helper.rb', line 10

def cms_icon(name, options = {})
  image_tag "/cms/images/icons/#{name}", options.merge(:size => '16x16')
end

#cms_row_classObject



24
25
26
# File 'app/helpers/cms/common_helper.rb', line 24

def cms_row_class
  cycle 'dark', 'light'
end

#codemirror_edit(content_type, form, content_id, use_ajax = true, liquid_support = false) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/cms/common_helper.rb', line 36

def codemirror_edit(content_type, form, content_id, use_ajax = true, liquid_support = false)
  mode = nil

  case content_type
  when "text/css"
    mode = 'css'
    content_for :cms_styles do
      javascript_include_tag '/cms/codemirror/mode/css/css'
    end
  when "text/javascript"
    mode = 'javascript'
    content_for :cms_styles do
      javascript_include_tag '/cms/codemirror/mode/javascript/javascript'
    end
  else
    mode = 'htmlmixed'
    content_for :cms_styles do
      javascript_include_tag '/cms/codemirror/mode/htmlmixed/htmlmixed'
    end
  end

  javascript_tag %(initCodemirror('#{mode}', $$('#{form}').first(), $('#{content_id}'), #{use_ajax}, #{liquid_support}))
end

js cookie accessor



3
4
5
6
7
8
# File 'app/helpers/cms/common_helper.rb', line 3

def cookie_jar(key)
  # if the cookie hasn't been set, need to return '{}' to return a proper hash
  # and if the cookie has been set, but is 'null', we need to then return a ruby hash
  # __CJ_ is the cookiejar js lib postfix value for cookies
  ActiveSupport::JSON.decode(cookies["__CJ_#{key}".to_sym] || '{}') || {}
end

#file_type_icon(file_name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/cms/common_helper.rb', line 60

def file_type_icon(file_name)
  icon = case File.extname(file_name).downcase
  when ".xls"
    'page_white_excel.png'
  when ".doc"
    'page_white_word.png'
  when ".pdf"
    'page_white_acrobat.png'
  when ".zip"
    'page_white_compressed.png'
  when ".ppt"
    'page_white_powerpoint.png'
  when /\.(ico|bmp|gif|jpg|jpeg|png)$/
    'page_white_camera.png'
  when ".js"
    'script.png'
  when ".css"
    'css.png'
  when ".xml"
    'xhtml.png'
  else
    'page_white.png'
  end

  cms_icon(icon)
end

#load_cms_flash_messageObject



19
20
21
22
# File 'app/helpers/cms/common_helper.rb', line 19

def load_cms_flash_message
  msg = cms_flash_message
  msg.present? ? javascript_tag("document.observe('dom:loaded', function(){ #{msg} })") : nil
end

#page_icon(page) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/cms/common_helper.rb', line 87

def page_icon(page)
  icon = case page.content_type
  when 'text/css'
    'css.png'
  when 'text/javascript'
    'script.png'
  when 'text/xml'
    'xhtml.png'
  when 'text/plain'
    'page_white.png'
  else
    'html.png'
  end 

  cms_icon(icon)
end