Module: E9Crm::BaseHelper
- Defined in:
- app/helpers/e9_crm/base_helper.rb
Instance Method Summary collapse
-
#build_associated_resource(association_name) ⇒ Object
tries to build an associated resource, looking to the assocatiaon’s model for a method named “%association_name_build_parameters}” first for any default params.
- #help_label(form_or_id, key, options = {}) ⇒ Object
- #help_tooltip(string, data_title = nil) ⇒ Object
- #kramdown(string) ⇒ Object (also: #k)
-
#link_to_add_record_attribute(association_name) ⇒ Object
Misc.
- #link_to_destroy_record_attribute ⇒ Object
- #record_attribute_template(association_name, builder, options = {}) ⇒ Object
-
#records_table_field_map(options = {}) ⇒ Object
Field maps.
- #render_record_attribute_association(association_name, form, options = {}) ⇒ Object
- #render_record_attribute_form(association_name, form) ⇒ Object
- #sortable_controller? ⇒ Boolean
Instance Method Details
#build_associated_resource(association_name) ⇒ Object
tries to build an associated resource, looking to the assocatiaon’s model for a method named “%association_name_build_parameters}” first for any default params
106 107 108 109 110 |
# File 'app/helpers/e9_crm/base_helper.rb', line 106 def build_associated_resource(association_name) params_method = "#{association_name}_build_parameters" build_params = resource_class.send(params_method) if resource_class.respond_to?(params_method) resource.send(association_name).build(build_params || {}) end |
#help_label(form_or_id, key, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/e9_crm/base_helper.rb', line 15 def help_label(form_or_id, key, = {}) [:key] ||= :"#{key}_help" help_title = .delete(:title) || resource_humanize(.delete(:key)) str = ''.html_safe str.safe_concat resource_humanize(key) str.safe_concat ' ' str.safe_concat help_tooltip(help_title, .delete(:header)) if form_or_id.respond_to?(:label) form_or_id.label(key, str, ) else label_tag(form_or_id, str, ) end end |
#help_tooltip(string, data_title = nil) ⇒ Object
9 10 11 12 13 |
# File 'app/helpers/e9_crm/base_helper.rb', line 9 def help_tooltip(string, data_title = nil) return <<-HTML.strip.html_safe <span class="help" rel="tooltip" #{data_title ? %Q[data-title="#{data_title}"] : nil } title="#{CGI.escape_html(string)}">#{t(:inline_help_link)}</span> HTML end |
#kramdown(string) ⇒ Object Also known as: k
3 4 5 |
# File 'app/helpers/e9_crm/base_helper.rb', line 3 def kramdown(string) Kramdown::Document.new(string).to_html.html_safe end |
#link_to_add_record_attribute(association_name) ⇒ Object
Misc
59 60 61 62 63 64 65 66 |
# File 'app/helpers/e9_crm/base_helper.rb', line 59 def link_to_add_record_attribute(association_name) link_to( t(:add_record_attribute, :scope => :e9_crm), 'javascript:;', :class => 'add-nested-association', 'data-association' => association_name ) end |
#link_to_destroy_record_attribute ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/helpers/e9_crm/base_helper.rb', line 68 def link_to_destroy_record_attribute link_to( t(:destroy_record_attribute, :scope => :e9_crm), 'javascript:;', :class => 'destroy-nested-association' ) end |
#record_attribute_template(association_name, builder, options = {}) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'app/helpers/e9_crm/base_helper.rb', line 95 def record_attribute_template(association_name, builder, = {}) .symbolize_keys! render( :partial => [:partial] || "e9_crm/record_attributes/#{association_name.to_s.singularize}", :locals => { :f => builder } ) end |
#records_table_field_map(options = {}) ⇒ Object
Field maps
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/e9_crm/base_helper.rb', line 36 def records_table_field_map( = {}) .symbolize_keys! .reverse_merge!(:class_name => resource_class.name.underscore) base_map = { :fields => { :id => nil }, :links => lambda {|r| [link_to_edit_resource(r), link_to_destroy_resource(r)] } } method_name = "records_table_field_map_for_#{[:class_name]}" if respond_to?(method_name) base_map.merge! send(method_name) end base_map end |
#render_record_attribute_association(association_name, form, options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/e9_crm/base_helper.rb', line 83 def render_record_attribute_association(association_name, form, = {}) .symbolize_keys! association = resource.send(association_name) unless association.empty? form.fields_for(association_name) do |f| concat record_attribute_template(association_name, f, ) end end end |
#render_record_attribute_form(association_name, form) ⇒ Object
76 77 78 79 80 81 |
# File 'app/helpers/e9_crm/base_helper.rb', line 76 def render_record_attribute_form(association_name, form) render('e9_crm/record_attributes/form_partial', { :form => form, :association_name => association_name }) end |
#sortable_controller? ⇒ Boolean
112 113 114 |
# File 'app/helpers/e9_crm/base_helper.rb', line 112 def sortable_controller? @_sortable_controller ||= controller.class.ancestors.member?(E9Rails::Controllers::Sortable) end |