Module: Manage::BaseHelper

Defined in:
lib/generators/sunrise/templates/helpers/manage/base_helper.rb

Instance Method Summary collapse

Instance Method Details



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 50

def add_child_link(name, f, method, options={})
  options.symbolize_keys!
  
  html_options = options.delete(:html) || {}
  fields = new_child_fields(f, method, options)
  
  html_options[:class] ||= "new"
  
  (:div, 
    link_to_function(name, raw("insert_fields(this, \"#{method}\", \"#{escape_javascript(fields)}\")"), html_options),
    :class=>"add-bl")
end

#content_manager?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 2

def content_manager?
  user_signed_in? && current_user.admin?
end


73
74
75
76
77
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 73

def (tag_name, options={}, &block)
  key = options[:id]
  options[:style] = "display:none;" if !cookies[key].blank? && cookies[key].to_i != 1
  (tag_name, options, &block)
end


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 33

def link_to_sort(title, options = {})
  options.symbolize_keys!
  
  order_type = options[:order_type] || 'asc'
  order_column = options[:name] || 'id'
  class_name = options[:class] || nil
                  
  search_options = request.params[:search] || {}
  search_options.update(:order_column => order_column, :order_type => order_type)
  
  link_to(title, :search => search_options, :class => class_name)
end


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 6

def link_to_unless_current_span2(name, options = {}, html_options = {}, &block)
   if current_page?(options)
		if block_given?
			block.arity <= 1 ? yield(name) : yield(name, options, html_options)
		else
		 (:span, (:span, name), html_options)
		end
	else
		link_to(name, options, html_options)
	end
end

#manage_icon(image, options = {}) ⇒ Object



79
80
81
82
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 79

def manage_icon(image, options = {})
  options = { :alt => t(image, :scope => 'manage.icons'), :title => t(image, :scope => 'manage.icons') }.merge(options)
  image_tag("manage/ico_#{image}.gif", options)
end

#new_child_fields(form_builder, method, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 63

def new_child_fields(form_builder, method, options = {})
  options[:object] ||= form_builder.object.class.reflect_on_association(method).klass.new
  options[:partial] ||= method.to_s.singularize
  options[:form_builder_local] ||= :form
  
  form_builder.fields_for(method, options[:object], :child_index => "new_#{method}") do |f|
    render(:partial => options[:partial], :locals => { options[:form_builder_local] => f })
  end
end

#options_for_ckeditor(options = {}) ⇒ Object



18
19
20
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 18

def options_for_ckeditor(options = {})
  { :width => 860, :height => 400 }.merge(options)
end


46
47
48
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 46

def remove_child_link(name, f)
  f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
end

#white_block_form(options = {}, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 22

def white_block_form(options = {}, &block)
  title = options[:title]
  
  concat((:div, {:class=>"edit-white-bl"}) do
    concat((:div, {:class=>"bot-bg"}) do
      concat((:div, title, :class=>"wh-title")) unless title.blank?
      yield if block_given?
    end)
  end)
end