Remove enterprise options from list when added

This commit is contained in:
Rohan Mitchell
2015-11-20 09:27:24 +11:00
parent ef603a070e
commit d4ee20455e
5 changed files with 14 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ angular.module('admin.orderCycles')
$scope.supplied_products = Enterprise.supplied_products
$scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id)
$scope.OrderCycle = OrderCycle
$scope.order_cycle = OrderCycle.new({ coordinator_id: ocInstance.coordinator_id})
$scope.loaded = ->

View File

@@ -1,4 +1,5 @@
angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, OrderCycle, Enterprise, EnterpriseFee, ocInstance) ->
$scope.OrderCycle = OrderCycle
$scope.order_cycle = OrderCycle.new {coordinator_id: ocInstance.coordinator_id}, =>
# TODO: make this a get method, which only fetches one enterprise
$scope.enterprises = Enterprise.index {coordinator_id: ocInstance.coordinator_id}, (enterprises) =>

View File

@@ -1,11 +1,11 @@
angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $timeout) ->
OrderCycle = $resource '/admin/order_cycles/:action_name/:order_cycle_id.json', {}, {
OrderCycleResource = $resource '/admin/order_cycles/:action_name/:order_cycle_id.json', {}, {
'index': { method: 'GET', isArray: true}
'new' : { method: 'GET', params: { action_name: "new" } }
'create': { method: 'POST'}
'update': { method: 'PUT'}}
{
new class OrderCycle
order_cycle: {incoming_exchanges: [], outgoing_exchanges: []}
showProducts: {incoming: false, outgoing: false}
@@ -14,10 +14,10 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
exchangeIds: (direction) ->
parseInt(exchange.enterprise_id) for exchange in @exchangesByDirection(direction)
novelSupplier: (enterprise) ->
novelSupplier: (enterprise) =>
@exchangeIds('incoming').indexOf(enterprise.id) == -1
novelDistributor: (enterprise) ->
novelDistributor: (enterprise) =>
@exchangeIds('outgoing').indexOf(enterprise.id) == -1
exchangeSelectedVariants: (exchange) ->
@@ -105,7 +105,7 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
exchange.variants[variant_id] = false
new: (params, callback=null) ->
OrderCycle.new params, (oc) =>
OrderCycleResource.new params, (oc) =>
delete oc.$promise
delete oc.$resolved
angular.extend(@order_cycle, oc)
@@ -120,7 +120,7 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
load: (order_cycle_id, callback=null) ->
service = this
OrderCycle.get {order_cycle_id: order_cycle_id}, (oc) ->
OrderCycleResource.get {order_cycle_id: order_cycle_id}, (oc) ->
delete oc.$promise
delete oc.$resolved
angular.extend(service.order_cycle, oc)
@@ -144,7 +144,7 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
this.order_cycle
create: (destination) ->
oc = new OrderCycle({order_cycle: this.dataForSubmit()})
oc = new OrderCycleResource({order_cycle: this.dataForSubmit()})
oc.$create (data) ->
if data['success']
$window.location = destination
@@ -152,7 +152,7 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
console.log('Failed to create order cycle')
update: (destination) ->
oc = new OrderCycle({order_cycle: this.dataForSubmit()})
oc = new OrderCycleResource({order_cycle: this.dataForSubmit()})
oc.$update {order_cycle_id: this.order_cycle.id, reloading: (if destination? then 1 else 0)}, (data) =>
if data['success']
if destination?
@@ -229,5 +229,3 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
$timeout =>
this.message = null
, 5000
})

View File

@@ -1,5 +1,5 @@
%select{id: "new_#{type}_id", name: "new_#{type}_id", 'ng-model' => "new_#{type}_id"}
%option{"ng-repeat" => "enterprise in #{type}_enterprises|orderBy:'name'", "value" => "{{ enterprise.id }}", "ng-disabled" => "enterprise.issues_summary_#{type}"}
%option{"ng-repeat" => "enterprise in #{type}_enterprises|filter:OrderCycle.novel#{type.capitalize}|orderBy:'name'", "value" => "{{ enterprise.id }}", "ng-disabled" => "enterprise.issues_summary_#{type}"}
{{ enterprise.name }}
= "{{ enterprise.issues_summary_#{type} ? '('+enterprise.issues_summary_#{type}+')' : '' }}"

View File

@@ -106,6 +106,9 @@ feature %q{
check "order_cycle_incoming_exchange_0_variants_#{v1.id}"
check "order_cycle_incoming_exchange_0_variants_#{v2.id}"
# I should not be able to re-add the supplier
page.should_not have_select 'new_supplier_id', with_options: ['My supplier']
# And I add a supplier fee
within("tr.supplier-#{supplier.id}") { click_button 'Add fee' }
select 'My supplier', from: 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_id'