Module: Carnival::BaseAdminHelper
- Defined in:
- app/helpers/carnival/base_admin_helper.rb
Instance Method Summary collapse
- #caminho_modelo(action, extra_params = nil) ⇒ Object
- #constant_exists?(item, field) ⇒ Boolean
- #field_to_show(presenter, field, record, show_only_value = false) ⇒ Object
- #field_type(presenter, field) ⇒ Object
- #link_to_add_fields(name, f, association, path = "") ⇒ Object
- #link_to_remove_fields(name, f) ⇒ Object
- #set_resource_actived_if_current(path) ⇒ Object
- #show_messages ⇒ Object
Instance Method Details
#caminho_modelo(action, extra_params = nil) ⇒ Object
34 35 36 37 38 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 34 def caminho_modelo(action, extra_params=nil) params = {controller: controller.controller_name, action: action} params = params.merge(extra_params) if extra_params.present? url_for(params) end |
#constant_exists?(item, field) ⇒ Boolean
40 41 42 43 44 45 46 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 40 def constant_exists?(item, field) begin item.class.const_get(field.to_s.upcase).present? rescue false end end |
#field_to_show(presenter, field, record, show_only_value = false) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 58 def field_to_show(presenter, field, record, show_only_value=false) current_type = field_type(presenter,field) if current_type == :relation if show_only_value record.send(field.to_s).to_s else return link_to presenter.relation_label(field.to_sym, record), presenter.relation_path(field.to_sym, record) end else result = record.send(field.to_s) if current_type == :date if result.nil? return result else return result.strftime("%d/%m/%y %H:%M:%S") end end return number_with_precision(result, :precision => 2, :separator => ",") if current_type == :number return record.class.const_get(field.to_s.upcase)[result] if current_type == :enum result end end |
#field_type(presenter, field) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 48 def field_type(presenter,field) return :relation if presenter.relation_field?(field.to_sym) field_type = nil field_type = presenter.model_class.columns_hash[field.to_s].type if presenter.model_class.columns_hash[field.to_s].present? return :date if field_type == :datetime or field_type == :date return :number if field_type == :decimal or field_type == :float return :enum if field_type == :integer and constant_exists?(presenter.model_class,field) :other end |
#link_to_add_fields(name, f, association, path = "") ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 21 def link_to_add_fields(name, f, association, path="") new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, [new_object], :child_index => "new_#{association}") do |builder| render(path + association.to_s.singularize + "_fields", :f => builder) end fields = fields.gsub("\"","'").gsub("&",'&').gsub("<",'<').gsub(">",'>').gsub("\n", '') link_to_function(name, ("addFields(this, '#{association}', \"#{raw(fields)}\")")) end |
#link_to_remove_fields(name, f) ⇒ Object
30 31 32 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 30 def link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to_function(name, "removeFields(this)") end |
#set_resource_actived_if_current(path) ⇒ Object
3 4 5 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 3 def set_resource_actived_if_current(path) (request.fullpath == path)? 'actived' : '' end |
#show_messages ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/carnival/base_admin_helper.rb', line 7 def = '' flash.each do |type, | = @type = type end javascript = "noty({'text':'#{@messages}', 'layout':'bottom','type':'#{@type}','animateOpen':{'height':'toggle'}, 'animateClose':{'height':'toggle'},'speed':500,'timeout':4000, 'closeButton':false,'closeOnSelfClick':true,'closeOnSelfOver':true});" return javascript if defined?(@type) '' end |