app/helpers/crud_helper.rb in templus_models-2.0.0 vs app/helpers/crud_helper.rb in templus_models-2.0.1
- old
+ new
@@ -108,16 +108,16 @@
permissions << m.name
end
permissions.uniq.flatten
end
- def render_plus_button(field,f,modelo,record)
- field[:sf][:wrapper] = :with_button
- render_field(field,f,modelo,record)
+ def render_plus_button(field, f, modelo, record, options = {})
+ field[:sf][:wrapper] = options[:wrapper] || :with_button
+ render_field(field, f, modelo, record)
end
- def render_field(field,f,modelo,record)
+ def render_field(field, f, modelo, record)
field[:sf][:wrapper] ||= :default
if field[:sf].present? && field[:sf][:if].present?
return unless field[:sf][:if].call(f.object)
end
field[:sf][:hint] = false if field[:sf].present? && !field[:sf][:hint].present?
@@ -127,36 +127,38 @@
end
if !field[:sf][:edit].nil? || !field[:sf][:create].nil?
if !field[:sf][:edit].nil? && !field[:sf][:edit] && !record.new_record?
elsif !field[:sf][:create].nil? && !field[:sf][:create] && record.new_record?
else
+ opts = field[:sf].merge(label: I18n.t(field[:sf][:label]))
unless modelo.reflect_on_association(field[:attribute])
if modelo.new.send(field[:attribute]).class.to_s =~ /Uploader/ and f.object.send(field[:attribute]).present?
- f.input field[:attribute], field[:sf].merge(hint: "Arquivo Atual: #{f.object.send(field[:attribute]).file.filename}")
+ f.input field[:attribute], opts.merge(hint: "Arquivo Atual: #{f.object.send(field[:attribute]).file.filename}")
else
- f.input field[:attribute], field[:sf]
+ f.input field[:attribute], opts
end
else
- f.association field[:attribute], field[:sf]
+ f.association field[:attribute], opts
end
end
else
if field[:sf][:value] and field[:sf][:value].class == Proc
field[:sf][:input_html] ||= {}
- field[:sf][:input_html][:value] = f.instance_eval &field[:sf][:value]
+ field[:sf][:input_html][:value] = f.instance_eval(&field[:sf][:value])
end
if field[:sf][:collection_if] and field[:sf][:collection_if].class == Proc
- field[:sf][:collection] = f.instance_eval &field[:sf][:collection_if]
+ field[:sf][:collection] = f.instance_eval(&field[:sf][:collection_if])
end
+ opts = field[:sf].merge(label: I18n.t(field[:sf][:label]))
unless modelo.reflect_on_association(field[:attribute])
if modelo.new.send(field[:attribute]).class.to_s =~ /Uploader/ and f.object.send(field[:attribute]).present?
- f.input field[:attribute], field[:sf].merge(hint: "Arquivo Atual: #{f.object.send(field[:attribute]).file.filename}")
+ f.input field[:attribute], opts.merge(hint: "Arquivo Atual: #{f.object.send(field[:attribute]).file.filename}")
else
- f.input field[:attribute], field[:sf]
+ f.input field[:attribute], opts
end
else
- f.association field[:attribute], field[:sf]
+ f.association field[:attribute], opts
end
end
end
def imagem?(file)
@@ -209,10 +211,10 @@
def should_destroy?(crud_helper,record)
return false unless can?(:destroy, record)
return true if crud_helper.condition_destroy_action.nil?
crud_helper.condition_destroy_action.call(record)
end
-
+
def should_listing?(crud_helper,model)
return false unless can?(:read, model)
return true if crud_helper.condition_listing_action.nil?
crud_helper.condition_listing_action.call(model)
end