module InlineFormsHelper # load form elements. Each element goes into a separate file # and defines a _show, _edit and _update method. # INLINE_FORMS_PATH = File.dirname(__FILE__) + "/form_elements/" Dir[INLINE_FORMS_PATH + "*.rb"].each do |form_element| require form_element end private # close link def close_link( object, update_span ) link_to image_tag( 'css/close.png', :class => "close_icon" ), send( object.class.to_s.underscore + '_path', object, :update => update_span, :close => true ), :remote => true end # link_to_inline_edit def link_to_inline_edit(object, attribute, attribute_value='') attribute_value = h(attribute_value) spaces = attribute_value.length > 40 ? 0 : 40 - attribute_value.length attribute_value << " ".html_safe * spaces css_class_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}" if cancan_disabled? || ( can? :update, object ) link_to attribute_value, send( 'edit_' + object.class.to_s.underscore + '_path', object, :attribute => attribute.to_s, :form_element => calling_method.sub(/_[a-z]+$/,''), :update => css_class_id ), :remote => true else attribute_value end end # link to inline image edit def link_to_inline_image_edit(object, attribute) text= image_tag object.send(attribute).send('url', :thumb) link_to text, send('edit_' + @Klass.to_s.underscore + '_path', object, :attribute => attribute.to_s, :form_element => calling_method.sub(/_[a-z]+$/,''), :update => "attribute_#{attribute}_#{object.id}" ), :remote => true end def link_to_new_record(text, model, path_to_new, update_span, parent_class, parent_id) out = "" out << "