Make distributor payment method multi-select

This commit is contained in:
David Cook
2013-09-13 12:03:37 +10:00
parent 107c6978c2
commit ee9d9a36d5
3 changed files with 12 additions and 15 deletions

View File

@@ -3,18 +3,15 @@ Spree::PaymentMethod.class_eval do
belongs_to :distributor, :class_name => 'Enterprise'
validates_presence_of :distributor_id
attr_accessible :distributor_id
attr_accessible :distributor_ids
# -- Scopes
scope :in_distributor, lambda { |distributor| where(:distributor_id => distributor) }
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')
scoped
else
where('distributor_id IN (?)', user.enterprises)
joins(:distributors).
where('distributors_payment_methods.distributor_id IN (?)', user.enterprises)
end
}

View File

@@ -1,9 +0,0 @@
/
insert_before '[data-hook="environment"]'
= f.field_container :distributor do
= f.label :distributor
%br
= collection_select(:payment_method, :distributor_id, Enterprise.is_distributor.managed_by(spree_current_user), :id, :name, {:include_blank => false}, {:class => "select2 fullwidth"})
= f.error_message_on :distributor

View File

@@ -0,0 +1,9 @@
/
insert_before '[data-hook="environment"]'
= f.field_container :distributors do
= f.label :distributors
%br
- distributors = Enterprise.is_distributor.managed_by(spree_current_user) | f.object.distributors
= collection_select(:payment_method, :distributor_ids, distributors, :id, :name, {include_blank: false}, {class: "select2 fullwidth", multiple: true})
= f.error_message_on :distributors