List and add distributor exchanges

This commit is contained in:
Rohan Mitchell
2013-01-11 15:53:51 +11:00
parent 9e59dead07
commit a10eb0d0c7
7 changed files with 73 additions and 20 deletions

View File

@@ -19,6 +19,10 @@ app.controller 'AdminCreateOrderCycleCtrl', ($scope, OrderCycle, Enterprise) ->
$event.preventDefault()
OrderCycle.addSupplier($scope.new_supplier_id)
$scope.addDistributor = ($event) ->
$event.preventDefault()
OrderCycle.addDistributor($scope.new_distributor_id)
$scope.submit = ->
OrderCycle.create()
@@ -43,6 +47,10 @@ app.controller 'AdminEditOrderCycleCtrl', ($scope, $location, OrderCycle, Enterp
$event.preventDefault()
OrderCycle.addSupplier($scope.new_supplier_id)
$scope.addDistributor = ($event) ->
$event.preventDefault()
OrderCycle.addDistributor($scope.new_distributor_id)
$scope.submit = ->
OrderCycle.update()
@@ -72,6 +80,9 @@ app.factory 'OrderCycle', ($resource, $window) ->
addSupplier: (new_supplier_id) ->
this.order_cycle.incoming_exchanges.push({enterprise_id: new_supplier_id, active: true, variants: {}})
addDistributor: (new_distributor_id) ->
this.order_cycle.outgoing_exchanges.push({enterprise_id: new_distributor_id, active: true, variants: {}})
load: (order_cycle_id) ->
service = this

View File

@@ -61,4 +61,7 @@ form.order_cycle {
}
}
}
.actions {
margin-top: 3em;
}
}

View File

@@ -0,0 +1,5 @@
%td.active= check_box_tag 'order_cycle_exchange_{{ exchange.id }}_active', 1, 1, 'ng-model' => 'exchange.active', 'id' => 'order_cycle_exchange_{{ exchange.id }}_active'
%td.supplier_name {{ enterprises[exchange.enterprise_id].name }}
%td.products
= f.submit 'Products', 'ng-click' => 'toggleProducts($event, exchange)'
{{ exchangeSelectedVariants(exchange) }} / {{ enterpriseTotalVariants(enterprises[exchange.enterprise_id]) }} selected

View File

@@ -1,8 +1,9 @@
.exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'}
.exchange-product-details
= check_box_tag 'order_cycle_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants', 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}'
%img{'ng-src' => '{{ product.image_url }}'}
{{ product.name }}
.exchange-product-variant{'ng-repeat' => 'variant in product.variants'}
= check_box_tag 'order_cycle_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}'
{{ variant.label }}
%td{:colspan => 3}
.exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'}
.exchange-product-details
= check_box_tag 'order_cycle_exchange_{{ exchange.id }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants', 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_exchange_{{ exchange.id }}_variants_{{ product.master_id }}'
%img{'ng-src' => '{{ product.image_url }}'}
{{ product.name }}
.exchange-product-variant{'ng-repeat' => 'variant in product.variants'}
= check_box_tag 'order_cycle_exchange_{{ exchange.id }}_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_exchange_{{ exchange.id }}_variants_{{ variant.id }}'
{{ variant.label }}

View File

@@ -20,14 +20,9 @@
%th Products
%tbody{'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
%tr.supplier
%td.active= check_box_tag 'order_cycle_exchange_{{ $index }}_active', 1, 1, 'ng-model' => 'exchange.active', 'id' => 'order_cycle_exchange_{{ $index }}_active'
%td.supplier_name {{ enterprises[exchange.enterprise_id].name }}
%td.products
= f.submit 'Products', 'ng-click' => 'toggleProducts($event, exchange)'
{{ exchangeSelectedVariants(exchange) }} / {{ enterpriseTotalVariants(enterprises[exchange.enterprise_id]) }} selected
= render 'exchange_form', :f => f
%tr.products{'ng-show' => 'exchange.showProducts'}
%td{:colspan => 3}
= render 'exchange_product_form'
= render 'exchange_product_form'
= select_tag :new_supplier_id, options_from_collection_for_select(Enterprise.is_primary_producer, :id, :name), {'ng-model' => 'new_supplier_id'}
= f.submit 'Add supplier', 'ng-click' => 'addSupplier($event)'
@@ -38,14 +33,28 @@
= f.collection_select :coordinator_id, Enterprise.all, :id, :name, {}, {'ng-model' => 'order_cycle.coordinator_id', 'required' => true}
%h2 Outgoing
%p TODO
%table.exchanges
%thead
%tr
%th
%th Distributor
%th Products
%tbody{'ng-repeat' => 'exchange in order_cycle.outgoing_exchanges'}
%tr.supplier
= render 'exchange_form', :f => f
%tr.products{'ng-show' => 'exchange.showProducts'}
= render 'exchange_product_form'
= f.submit @order_cycle.new_record? ? 'Create' : 'Update'
or
= link_to 'Cancel', main_app.admin_order_cycles_path
= select_tag :new_distributor_id, options_from_collection_for_select(Enterprise.is_distributor, :id, :name), {'ng-model' => 'new_distributor_id'}
= f.submit 'Add distributor', 'ng-click' => 'addDistributor($event)'
.actions
= f.submit @order_cycle.new_record? ? 'Create' : 'Update'
or
= link_to 'Cancel', main_app.admin_order_cycles_path
<h2>Debug information</h2>
%h2 Debug information
%pre order_cycle = {{ order_cycle | json }}
%pre enterprises = {{ enterprises | json }}

View File

@@ -5,6 +5,7 @@ r.element :order_cycle, @order_cycle do
r.element :orders_close_at, @order_cycle.orders_close_at.to_s
r.element :coordinator_id
r.list_of :exchanges do |exchange|
r.element :id
r.element :sender_id
r.element :receiver_id

View File

@@ -16,6 +16,7 @@ describe 'OrderCycle controllers', ->
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').andReturn('variants selected')
toggleProducts: jasmine.createSpy('toggleProducts')
addSupplier: jasmine.createSpy('addSupplier')
addDistributor: jasmine.createSpy('addDistributor')
create: jasmine.createSpy('create')
Enterprise =
index: jasmine.createSpy('index').andReturn('enterprises list')
@@ -52,6 +53,12 @@ describe 'OrderCycle controllers', ->
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
it 'Adds order cycle distributors', ->
scope.new_distributor_id = 'new distributor id'
scope.addDistributor(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addDistributor).toHaveBeenCalledWith('new distributor id')
it 'Submits the order cycle via OrderCycle create', ->
scope.submit()
expect(OrderCycle.create).toHaveBeenCalled()
@@ -76,6 +83,7 @@ describe 'OrderCycle controllers', ->
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').andReturn('variants selected')
toggleProducts: jasmine.createSpy('toggleProducts')
addSupplier: jasmine.createSpy('addSupplier')
addDistributor: jasmine.createSpy('addDistributor')
update: jasmine.createSpy('update')
Enterprise =
index: jasmine.createSpy('index').andReturn('enterprises list')
@@ -111,6 +119,12 @@ describe 'OrderCycle controllers', ->
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
it 'Adds order cycle distributors', ->
scope.new_distributor_id = 'new distributor id'
scope.addDistributor(event)
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.addDistributor).toHaveBeenCalledWith('new distributor id')
it 'Submits the order cycle via OrderCycle update', ->
scope.submit()
expect(OrderCycle.update).toHaveBeenCalled()
@@ -213,6 +227,15 @@ describe 'OrderCycle services', ->
{enterprise_id: '123', active: true, variants: {}}
]
describe 'adding distributors', ->
exchange = null
it 'adds the distributor to outgoing exchanges', ->
OrderCycle.addDistributor('123')
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
{enterprise_id: '123', active: true, variants: {}}
]
describe 'loading an order cycle', ->
beforeEach ->
OrderCycle.load('123')