Display only coordinator fees belonging to the selected coordinator

This commit is contained in:
Rohan Mitchell
2013-07-30 10:19:38 +10:00
parent 43474d6408
commit ae0f82b479
3 changed files with 32 additions and 5 deletions

View File

@@ -25,6 +25,9 @@ angular.module('order_cycle', ['ngResource'])
$event.preventDefault()
OrderCycle.toggleProducts(exchange)
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
$scope.addSupplier = ($event) ->
$event.preventDefault()
OrderCycle.addSupplier($scope.new_supplier_id)
@@ -64,6 +67,9 @@ angular.module('order_cycle', ['ngResource'])
$event.preventDefault()
OrderCycle.toggleProducts(exchange)
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
$scope.addSupplier = ($event) ->
$event.preventDefault()
OrderCycle.addSupplier($scope.new_supplier_id)
@@ -217,6 +223,9 @@ angular.module('order_cycle', ['ngResource'])
index: ->
this.enterprise_fees = EnterpriseFee.index()
forEnterprise: (enterprise_id) ->
enterprise_fee for enterprise_fee in this.enterprise_fees when enterprise_fee.enterprise_id == enterprise_id
}])
.directive('datetimepicker', ['$parse', ($parse) ->

View File

@@ -34,7 +34,7 @@
%table
%tr{'ng-repeat' => 'enterprise_fee in order_cycle.coordinator_fees'}
%td= select_tag 'order_cycle_coordinator_fee_{{ $index }}_id', nil, {'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterprise_fees'}
%td= select_tag 'order_cycle_coordinator_fee_{{ $index }}_id', nil, {'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterpriseFeesForEnterprise(order_cycle.coordinator_id)'}
%h2 Outgoing

View File

@@ -27,6 +27,7 @@ describe 'OrderCycle controllers', ->
totalVariants: jasmine.createSpy('totalVariants').andReturn('variants total')
EnterpriseFee =
index: jasmine.createSpy('index').andReturn('enterprise fees list')
forEnterprise: jasmine.createSpy('forEnterprise').andReturn('enterprise fees for enterprise')
module('order_cycle')
inject ($controller) ->
@@ -66,6 +67,10 @@ describe 'OrderCycle controllers', ->
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange')
it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', ->
scope.enterpriseFeesForEnterprise('123')
expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123)
it 'Adds order cycle suppliers', ->
scope.new_supplier_id = 'new supplier id'
scope.addSupplier(event)
@@ -113,6 +118,7 @@ describe 'OrderCycle controllers', ->
totalVariants: jasmine.createSpy('totalVariants').andReturn('variants total')
EnterpriseFee =
index: jasmine.createSpy('index').andReturn('enterprise fees list')
forEnterprise: jasmine.createSpy('forEnterprise').andReturn('enterprise fees for enterprise')
module('order_cycle')
inject ($controller) ->
@@ -151,6 +157,10 @@ describe 'OrderCycle controllers', ->
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange')
it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', ->
scope.enterpriseFeesForEnterprise('123')
expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123)
it 'Adds order cycle suppliers', ->
scope.new_supplier_id = 'new supplier id'
scope.addSupplier(event)
@@ -218,16 +228,24 @@ describe 'OrderCycle services', ->
EnterpriseFee = $injector.get('EnterpriseFee')
$httpBackend = _$httpBackend_
$httpBackend.whenGET('/admin/enterprise_fees.json').respond [
{id: 1, name: "Yayfee"}
{id: 2, name: "FeeTwo"}
{id: 1, name: "Yayfee", enterprise_id: 1}
{id: 2, name: "FeeTwo", enterprise_id: 2}
]
it 'loads enterprise fees', ->
enterprise_fees = EnterpriseFee.index()
$httpBackend.flush()
expect(enterprise_fees).toEqual [
new EnterpriseFee.EnterpriseFee({id: 1, name: "Yayfee"})
new EnterpriseFee.EnterpriseFee({id: 2, name: "FeeTwo"})
new EnterpriseFee.EnterpriseFee({id: 1, name: "Yayfee", enterprise_id: 1})
new EnterpriseFee.EnterpriseFee({id: 2, name: "FeeTwo", enterprise_id: 2})
]
it 'returns enterprise fees for an enterprise', ->
all_enterprise_fees = EnterpriseFee.index()
$httpBackend.flush()
enterprise_fees = EnterpriseFee.forEnterprise(1)
expect(enterprise_fees).toEqual [
new EnterpriseFee.EnterpriseFee({id: 1, name: "Yayfee", enterprise_id: 1})
]