module Admin::BaseHelper
def field_container(model, method, options = {}, &block)
unless error_message_on(model, method).blank?
css_class = 'withError'
end
content_tag('p', capture(&block), :class => css_class)
end
def error_message_on(object, method, options = {})
object = convert_to_model(object)
obj = object.respond_to?(:errors) ? object : instance_variable_get("@#{object}")
if obj && obj.errors[method].present?
errors = obj.errors[method].map{|err| h(err)}.join(' ').html_safe
content_tag(:span, errors, :class => 'formError')
else
''
end
end
def spree_date_picker(object, method, options = {}, html_options = {})
options.merge!(:format => "y-m-d")
unobtrusive_date_text_picker(object, method, options, html_options)
end
def class_for_error(model, method)
if error_message_on :product, :name
end
end
#You can add additional_fields to the product and variant models. See section 4.2 here: http://spreecommerce.com/documentation/extensions.html
#If you do choose to add additional_fields, you can utilize the :use parameter to set the input type for any such fields. For example, :use => 'check_box'
#In the event that you add this functionality, the following method takes care of rendering the proper input type and logic for the supported input-types, which are text_field, check_box, radio_button, and select.
def get_additional_field_value(controller, field)
attribute = attribute_name_for(field[:name])
value = eval("@" + controller.controller_name.singularize + "." + attribute)
if value.nil? && controller.controller_name == "variants"
value = @variant.product.has_attribute?(attribute) ? @variant.product[attribute] : nil
end
if value.nil?
return value
else
return field.key?(:format) ? sprintf(field[:format], value) : value
end
end
# This method demonstrates the use of the :child_index option to render a
# form partial for, for instance, client side addition of new nested
# records.
#
# This specific example creates a link which uses javascript to add a new
# form partial to the DOM.
#
# <%= form_for @project do |project_form| %>
#