Add viewing_as_coordiantor flag to serialized order cycles and a managed flag to serialized enterprises for_order_cycle(s)

This commit is contained in:
Rob Harrington
2015-04-09 10:31:17 +10:00
parent adc1b639bc
commit fbcfe9b2a4
3 changed files with 9 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
attributes :id, :name, :orders_open_at, :orders_close_at, :coordinator_id, :exchanges
attributes :viewing_as_coordinator
attributes :editable_variants_for_incoming_exchanges, :editable_variants_for_outgoing_exchanges
attributes :visible_variants_for_outgoing_exchanges
@@ -13,6 +14,10 @@ class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
object.orders_close_at.to_s
end
def viewing_as_coordinator
Enterprise.managed_by(options[:current_user]).include? object.coordinator
end
def exchanges
scoped_exchanges = OpenFoodNetwork::Permissions.new(options[:current_user]).order_cycle_exchanges(object).order('id ASC')
ActiveModel::ArraySerializer.new(scoped_exchanges, {each_serializer: Api::Admin::ExchangeSerializer, current_user: options[:current_user] })

View File

@@ -2,6 +2,8 @@ collection @collection
attributes :id, :name
node(:managed) { |enterprise| Enterprise.managed_by(spree_current_user).include? enterprise }
node(:supplied_products) do |enterprise|
enterprise.supplied_products.not_deleted.map do |product|
partial 'admin/enterprises/supplied_product', object: product

View File

@@ -9,9 +9,9 @@
selected
- if type == 'distributor'
%td.collection-details
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', 'placeholder' => 'Ready for (ie. Date / Time)', 'ng-model' => 'exchange.pickup_time'
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', 'placeholder' => 'Ready for (ie. Date / Time)', 'ng-model' => 'exchange.pickup_time', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%br/
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', 'placeholder' => 'Pick-up instructions', 'ng-model' => 'exchange.pickup_instructions'
= text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', 'placeholder' => 'Pick-up instructions', 'ng-model' => 'exchange.pickup_instructions', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator'
%td.fees
%ol
%li{'ng-repeat' => 'enterprise_fee in exchange.enterprise_fees'}