module MuckEngineHelper def custom_form_for(record_or_name_or_array, *args, &proc) options = args.detect { |argument| argument.is_a?(Hash) } if options.nil? options = {:builder => MuckCustomFormBuilder} args << options end options[:builder] = MuckCustomFormBuilder unless options.nil? form_for(record_or_name_or_array, *args, &proc) end def custom_remote_form_for(record_or_name_or_array, *args, &proc) options = args.detect { |argument| argument.is_a?(Hash) } if options.nil? options = {:builder => MuckCustomFormBuilder} args << options end options[:builder] = MuckCustomFormBuilder unless options.nil? remote_form_for(record_or_name_or_array, *args, &proc) end def output_errors(title, options = {}, fields = nil) fields = [fields] unless fields.is_a?(Array) flash_html = render(:partial => 'shared/flash_messages') flash.clear field_errors = render(:partial => 'shared/field_error', :collection => fields) css_class = "class=\"#{options[:class]}\"" unless options[:class].nil? if !flash_html.empty? && field_errors.empty? # only flash. Don't render the render(:partial => 'shared/flash_error_box', :locals => {:flash_html => flash_html, :css_class => css_class}) elsif !field_errors.empty? # field errors and/or flash render(:partial => 'shared/error_box', :locals => {:title => title, :flash_html => flash_html, :field_errors => field_errors, :css_class => css_class, :extra_html => options[:extra_html]}) else #nothing '' end end def icon(object, size = :icon) return "" if object.blank? || object.photo.blank? link_to(image_tag(object.photo.url(size), :class => size), object, { :title => object.full_name }) end def secure_mail_to(email) mail_to email, nil, :encode => 'javascript' end # Used inside of format.js to return a message to the client. # If jGrowl is enabled the message will show up as a growl instead of a popup def page_alert(page, message, title = '') if GlobalConfig.growl_enabled page << "jQuery.jGrowl.error('" + message + "', {header:'" + title + "'});" else page.alert(message) end end end