Sha256: 78f05e7eab7e84f7207778b5f49c81b0054fbe60e102781e7ecbb3084f780c50

Contents?: true

Size: 1.17 KB

Versions: 13

Compression:

Stored size: 1.17 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"), 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" }, { :data => { :confirm => Typus::I18n.t("Trash?") } }]]
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
brainsome_typus-4.0.0.beta13 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta12 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta11 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta10 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta9 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta8 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta7 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta6 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta5 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta4 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta3 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta2 app/helpers/admin/resources/data_types/has_one_helper.rb
brainsome_typus-4.0.0.beta1 app/helpers/admin/resources/data_types/has_one_helper.rb