Module: Manage::BaseHelper

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

Instance Method Summary collapse

Instance Method Details



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

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, h("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


76
77
78
79
80
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 76

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


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

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

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



66
67
68
69
70
71
72
73
74
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 66

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
21
22
23
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 18

def options_for_ckeditor(options = {})
  {:width=>700, :height=>400, 
   :swf_params=>{:assetable_type=>current_user.class.name, :assetable_id=>current_user.id}
     
  }.update(options)
end


49
50
51
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 49

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

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



25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/sunrise/templates/helpers/manage/base_helper.rb', line 25

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