mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add edit order cycle controller, load basic data
This commit is contained in:
@@ -26,10 +26,43 @@ function AdminCreateOrderCycleCtrl($scope, $http, Enterprise) {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function AdminEditOrderCycleCtrl($scope, $http, OrderCycle, Enterprise) {
|
||||
// TODO: Research how to do route param parsing from regular url.
|
||||
// Does Angular have a way to do this?
|
||||
|
||||
OrderCycle.get({order_cycle_id: 24}, function(order_cycle) {
|
||||
$scope.order_cycle = order_cycle;
|
||||
$scope.order_cycle.incoming_exchanges = [];
|
||||
$scope.order_cycle.outgoing_exchanges = [];
|
||||
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});
|
||||
|
||||
} else if(exchange.receiver_id == order_cycle.coordinator_id) {
|
||||
$scope.order_cycle.incoming_exchanges.push({enterprise_id: exchange.sender_id});
|
||||
|
||||
} 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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
angular.module('order_cycle', ['ngResource']).
|
||||
config(function($httpProvider) {
|
||||
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
|
||||
}).
|
||||
factory('OrderCycle', function($resource) {
|
||||
return $resource('/admin/order_cycles/:order_cycle_id.json', {},
|
||||
{'index': { method: 'GET', isArray: true},
|
||||
'show': { method: 'GET', isArray: false}});
|
||||
}).
|
||||
factory('Enterprise', function($resource) {
|
||||
return $resource('/admin/enterprises/:enterprise_id.json', {},
|
||||
{'index': { method: 'GET', isArray: true}});
|
||||
|
||||
@@ -1,34 +1,33 @@
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng', 'ng-app' => 'order_cycle', 'ng-controller' => 'AdminCreateOrderCycleCtrl', 'ng-submit' => 'submit()'} do |f|
|
||||
= f.label :name
|
||||
= f.text_field :name, 'ng-model' => 'order_cycle.name', 'required' => true
|
||||
%br/
|
||||
= f.label :name
|
||||
= f.text_field :name, 'ng-model' => 'order_cycle.name', 'required' => true
|
||||
%br/
|
||||
|
||||
= f.label :orders_open_at, 'Orders open'
|
||||
= f.text_field :orders_open_at, 'class' => 'datetimepicker', 'ng-model' => 'order_cycle.orders_open_at'
|
||||
= f.label :orders_close_at, 'Orders close'
|
||||
= f.text_field :orders_close_at, 'class' => 'datetimepicker', 'ng-model' => 'order_cycle.orders_close_at'
|
||||
%br/
|
||||
= f.label :orders_open_at, 'Orders open'
|
||||
= f.text_field :orders_open_at, 'class' => 'datetimepicker', 'ng-model' => 'order_cycle.orders_open_at'
|
||||
= f.label :orders_close_at, 'Orders close'
|
||||
= f.text_field :orders_close_at, 'class' => 'datetimepicker', 'ng-model' => 'order_cycle.orders_close_at'
|
||||
%br/
|
||||
|
||||
|
||||
%h2 Incoming
|
||||
%table
|
||||
%tr{'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
|
||||
%td {{ enterprises[exchange.enterprise_id].name }}
|
||||
%h2 Incoming
|
||||
%table
|
||||
%tr{'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
|
||||
%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'}
|
||||
= f.submit 'Add supplier', 'ng-click' => 'addSupplier($event)'
|
||||
= 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)'
|
||||
|
||||
|
||||
%h2 Coordinator
|
||||
= f.label :coordinator_id, 'Coordinator'
|
||||
= f.collection_select :coordinator_id, Enterprise.all, :id, :name, {}, {'ng-model' => 'order_cycle.coordinator_id', 'required' => true}
|
||||
%h2 Coordinator
|
||||
= f.label :coordinator_id, 'Coordinator'
|
||||
= f.collection_select :coordinator_id, Enterprise.all, :id, :name, {}, {'ng-model' => 'order_cycle.coordinator_id', 'required' => true}
|
||||
|
||||
%h2 Outgoing
|
||||
%p TODO
|
||||
%h2 Outgoing
|
||||
%p TODO
|
||||
|
||||
= f.submit 'Create'
|
||||
or
|
||||
= link_to 'Cancel', main_app.admin_order_cycles_path
|
||||
= f.submit 'Create'
|
||||
or
|
||||
= link_to 'Cancel', main_app.admin_order_cycles_path
|
||||
|
||||
%pre {{ order_cycle | json }}
|
||||
%pre {{ enterprises | json }}
|
||||
%pre {{ order_cycle | json }}
|
||||
%pre {{ enterprises | json }}
|
||||
|
||||
4
app/views/admin/order_cycles/edit.html.haml
Normal file
4
app/views/admin/order_cycles/edit.html.haml
Normal file
@@ -0,0 +1,4 @@
|
||||
%h1 Edit Order Cycle
|
||||
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng', 'ng-app' => 'order_cycle', 'ng-controller' => 'AdminEditOrderCycleCtrl', 'ng-submit' => 'submit()'} do |f|
|
||||
= render 'form', :f => f
|
||||
@@ -1,3 +1,4 @@
|
||||
%h1 New Order Cycle
|
||||
|
||||
= render 'form'
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng', 'ng-app' => 'order_cycle', 'ng-controller' => 'AdminCreateOrderCycleCtrl', 'ng-submit' => 'submit()'} do |f|
|
||||
= render 'form', :f => f
|
||||
|
||||
Reference in New Issue
Block a user