mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove exchanges in both create and edit
This commit is contained in:
@@ -12,10 +12,12 @@ function AdminCreateOrderCycleCtrl($scope, $http, Enterprise) {
|
||||
|
||||
$scope.addSupplier = function($event) {
|
||||
$event.preventDefault();
|
||||
$scope.order_cycle.incoming_exchanges.push({'enterprise_id': $scope.new_supplier_id});
|
||||
$scope.order_cycle.incoming_exchanges.push({enterprise_id: $scope.new_supplier_id, active: true});
|
||||
};
|
||||
|
||||
$scope.submit = function() {
|
||||
$scope.removeInactiveExchanges();
|
||||
|
||||
$http.post('/admin/order_cycles', {order_cycle: $scope.order_cycle}).success(function(data) {
|
||||
if(data['success']) {
|
||||
window.location = '/admin/order_cycles';
|
||||
@@ -24,6 +26,15 @@ function AdminCreateOrderCycleCtrl($scope, $http, Enterprise) {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.removeInactiveExchanges = function() {
|
||||
for(var i=0; i < $scope.order_cycle.incoming_exchanges.length; i++) {
|
||||
if(!$scope.order_cycle.incoming_exchanges[i].active) {
|
||||
$scope.order_cycle.incoming_exchanges.splice(i, 1)
|
||||
i--;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -43,26 +54,27 @@ function AdminEditOrderCycleCtrl($scope, $http, OrderCycle, Enterprise) {
|
||||
for(i in order_cycle.exchanges) {
|
||||
var exchange = order_cycle.exchanges[i];
|
||||
if(exchange.sender_id == order_cycle.coordinator_id) {
|
||||
$scope.order_cycle.outgoing_exchanges.push({enterprise_id: exchange.receiver_id});
|
||||
$scope.order_cycle.outgoing_exchanges.push({enterprise_id: exchange.receiver_id, active: true});
|
||||
|
||||
} else if(exchange.receiver_id == order_cycle.coordinator_id) {
|
||||
$scope.order_cycle.incoming_exchanges.push({enterprise_id: exchange.sender_id});
|
||||
$scope.order_cycle.incoming_exchanges.push({enterprise_id: exchange.sender_id, active: true});
|
||||
|
||||
} else {
|
||||
console.log('Exchange between two enterprises, neither of which is coordinator!');
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check if this is the best way
|
||||
delete($scope.order_cycle.exchanges);
|
||||
});
|
||||
|
||||
$scope.addSupplier = function($event) {
|
||||
$event.preventDefault();
|
||||
$scope.order_cycle.incoming_exchanges.push({'enterprise_id': $scope.new_supplier_id});
|
||||
$scope.order_cycle.incoming_exchanges.push({enterprise_id: $scope.new_supplier_id, active: true});
|
||||
};
|
||||
|
||||
$scope.submit = function() {
|
||||
$scope.removeInactiveExchanges();
|
||||
|
||||
var path = '/admin/order_cycles/' + $scope.order_cycle.id
|
||||
$http.put(path, {order_cycle: $scope.order_cycle}).success(function(data) {
|
||||
if(data['success']) {
|
||||
@@ -72,6 +84,15 @@ function AdminEditOrderCycleCtrl($scope, $http, OrderCycle, Enterprise) {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.removeInactiveExchanges = function() {
|
||||
for(var i=0; i < $scope.order_cycle.incoming_exchanges.length; i++) {
|
||||
if(!$scope.order_cycle.incoming_exchanges[i].active) {
|
||||
$scope.order_cycle.incoming_exchanges.splice(i, 1)
|
||||
i--;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
%h2 Incoming
|
||||
%table
|
||||
%tr{'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
|
||||
%td= check_box_tag 'order_cycle_exchange_{{ $index }}_active', 1, 1, 'ng-model' => 'exchange.active', 'id' => 'order_cycle_exchange_{{ $index }}_active'
|
||||
%td {{ enterprises[exchange.enterprise_id].name }}
|
||||
|
||||
= select_tag :new_supplier_id, options_from_collection_for_select(Enterprise.is_primary_producer, :id, :name), {'ng-model' => 'new_supplier_id'}
|
||||
|
||||
Reference in New Issue
Block a user