Enterprise fees admin page for a specific enterprise auto-selects that enterprise for new fees and only allows selection of managed enterprises

This commit is contained in:
Rohan Mitchell
2013-10-30 17:00:05 +11:00
parent 32889715f0
commit 5386fa72cc
5 changed files with 25 additions and 12 deletions

View File

@@ -14,10 +14,6 @@ angular.module('enterprise_fees', [])
$http.get($scope.enterpriseFeesUrl()).success(function(data) {
$scope.enterprise_fees = data;
for(i=0; i<3; i++) {
$scope.enterprise_fees.push({});
}
// TODO: Angular 1.1.0 will have a means to reset a form to its pristine state, which
// would avoid the need to save off original calculator types for comparison.
for(i in $scope.enterprise_fees) {

View File

@@ -8,6 +8,10 @@ module Admin
def index
@include_calculators = params[:include_calculators].present?
blank_enterprise_fee = EnterpriseFee.new
blank_enterprise_fee.enterprise = current_enterprise
3.times { @collection << blank_enterprise_fee }
respond_to do |format|
format.html
format.json { @presented_collection = @collection.each_with_index.map { |ef, i| EnterpriseFeePresenter.new(self, ef, i) } }
@@ -52,13 +56,13 @@ module Admin
def collection
collection = EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name')
if params.key? :enterprise_id
enterprise = Enterprise.find params[:enterprise_id]
collection = collection.for_enterprise(enterprise)
end
collection = collection.for_enterprise(current_enterprise) if current_enterprise
collection
end
def current_enterprise
Enterprise.find params[:enterprise_id] if params.key? :enterprise_id
end
end
end

View File

@@ -1,7 +1,7 @@
class EnterpriseFeeSet < ModelSet
def initialize(attributes={})
super(EnterpriseFee, EnterpriseFee.all,
proc { |attrs| attrs[:enterprise_id].blank? },
proc { |attrs| attrs[:name].blank? },
attributes)
end
end

View File

@@ -23,7 +23,7 @@
%tr{'ng-repeat' => 'enterprise_fee in enterprise_fees | filter:query'}
%td
= f.ng_hidden_field :id
= f.ng_collection_select :enterprise_id, Enterprise.all, :id, :name, 'enterprise_fee.enterprise_id', :include_blank => true
= f.ng_collection_select :enterprise_id, Enterprise.managed_by(spree_current_user), :id, :name, 'enterprise_fee.enterprise_id', :include_blank => true
%td= f.ng_select :fee_type, enterprise_fee_type_options, 'enterprise_fee.fee_type'
%td= f.ng_text_field :name
%td= f.ng_collection_select :calculator_type, @calculators, :name, :description, 'enterprise_fee.calculator_type', {'class' => 'calculator_type', 'ng-model' => 'calculatorType', 'spree-ensure-calculator-preferences-match-type' => "1"}

View File

@@ -128,6 +128,7 @@ feature %q{
let(:enterprise_user) { create_enterprise_user }
let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') }
let(:distributor2) { create(:distributor_enterprise, name: 'Second Distributor') }
let(:distributor3) { create(:distributor_enterprise, name: 'Third Distributor') }
let(:ef1) { create(:enterprise_fee, name: 'One', enterprise: distributor1) }
let(:ef2) { create(:enterprise_fee, name: 'Two', enterprise: distributor2) }
@@ -166,5 +167,17 @@ feature %q{
page.should_not have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'One'
page.should have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'Two'
end
it "only allows me to select enterprises I have access to" do
ef1
ef2
distributor3
click_link 'Enterprises'
within(".enterprise-#{distributor2.id}") { click_link 'Enterprise Fees' }
page.should have_select('enterprise_fee_set_collection_attributes_1_enterprise_id',
selected: 'Second Distributor',
options: ['', 'First Distributor', 'Second Distributor'])
end
end
end