Sha256: 3a0bf23891d85ec904e44f97c34c9c49202886e7372c5d07f9325e4f70d0e129

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

module Admin::Resources::DataTypes::HasOneHelper

  def typus_form_has_one(field)
    setup_relationship(field)

    related_items = @item.send(field)
    @items =  related_items ? [related_items] : []

    set_has_one_resource_actions

    locals = { :association_name => @association_name, :table => build_relationship_table, :add_new => nil }

    if @items.empty?
      options = { "resource[#{@reflection.foreign_key}]" => @item.id }
      locals[:add_new] = build_add_new_for_has_one(@model_to_relate, field, options)
    end

    render "admin/templates/has_one", locals
  end

  def build_add_new_for_has_one(klass, field, options = {})
    if admin_user.can?("create", klass)
      default_options = { :controller => "/admin/#{klass.to_resource}",
                          :action => "new",
                          :_popup => true }

      link_to Typus::I18n.t("Add New"), default_options.merge(options), { :class => "iframe_with_page_reload" }
    end
  end

  def set_has_one_resource_actions
    @resource_actions = [["Edit", { :action => "edit" }, {}],
                         ["Trash", { :action => "destroy" }, { :confirm => "Trash?" }]]
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
typus-3.1.10 app/helpers/admin/resources/data_types/has_one_helper.rb
typus-3.1.9 app/helpers/admin/resources/data_types/has_one_helper.rb
typus-3.1.8 app/helpers/admin/resources/data_types/has_one_helper.rb
typus-3.1.7 app/helpers/admin/resources/data_types/has_one_helper.rb
typus-3.1.6 app/helpers/admin/resources/data_types/has_one_helper.rb
typus-3.1.5 app/helpers/admin/resources/data_types/has_one_helper.rb
typus-3.1.4 app/helpers/admin/resources/data_types/has_one_helper.rb
typus-3.1.3 app/helpers/admin/resources/data_types/has_one_helper.rb