diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index 129d4c3308..f1aa48f95c 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -5,6 +5,9 @@ Spree::Admin::OrdersController.class_eval do helper CheckoutHelper before_filter :load_spree_api_key, :only => :bulk_management + # Ensure that the distributor is set for an order when + before_filter :ensure_distribution, only: :new + # We need to add expections for collection actions other than :index here # because spree_auth_devise causes load_order to be called, which results # in an auth failure as the @order object is nil for collection actions @@ -131,4 +134,10 @@ Spree::Admin::OrdersController.class_eval do ocs.closed + ocs.undated end + + def ensure_distribution + unless @order.distribution_set? + render 'set_distribution' + end + end end diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 22791661fb..4ed822396a 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -186,6 +186,12 @@ Spree::OrdersController.class_eval do private + def ensure_distributor + unless @order.distributor_id + render 'set_distribution' + end + end + def populate_variant_attributes order = current_order.reload diff --git a/app/overrides/spree/admin/orders/_form/add_distribution_fields.html.haml.deface b/app/overrides/spree/admin/orders/_form/add_distribution_fields.html.haml.deface index a6c51d517c..f8b9e769f7 100644 --- a/app/overrides/spree/admin/orders/_form/add_distribution_fields.html.haml.deface +++ b/app/overrides/spree/admin/orders/_form/add_distribution_fields.html.haml.deface @@ -1,38 +1,3 @@ / insert_before "[data-hook='admin_order_form_buttons']" -%fieldset.no-border-bottom - %legend{align: 'center'} Distribution - - - if @order.complete? - .alpha.six.columns - %p - %b Distributor: - = f.object.distributor.andand.name || "None" - = f.hidden_field :distributor_id - .omega.six.columns - %p - %b Order cycle: - = f.object.order_cycle.andand.name || "None" - = f.hidden_field :order_cycle_id - - - else - .alpha.six.columns - .field - %label{for: "order_distributor_id"} Distributor - %input.ofn-select2.fullwidth{id: "order_distributor_id", - type: 'number', - name: "order[distributor_id]", - "ng-model" => 'distributor_id', - data: "shops" } - - .omega.six.columns - .field - %label{ for: "order_order_cycle_id"} Order Cycle - %input.ofn-select2.fullwidth{id: "order_order_cycle_id", - type: 'number', - name: "order[order_cycle_id]", - "ng-model" => 'order_cycle_id', - "ng-disabled" => "!distributor_id", - data: "orderCycles", - text: "name_and_status", - filter: "validOrderCycle" } += render partial: 'distribution_fields' diff --git a/app/views/spree/admin/orders/_form/_distribution_fields.html.haml b/app/views/spree/admin/orders/_form/_distribution_fields.html.haml new file mode 100644 index 0000000000..1657fcaf71 --- /dev/null +++ b/app/views/spree/admin/orders/_form/_distribution_fields.html.haml @@ -0,0 +1,36 @@ +%fieldset.no-border-bottom + %legend{align: 'center'} Distribution + + - if @order.complete? + .alpha.six.columns + %p + %b Distributor: + = f.object.distributor.andand.name || "None" + = f.hidden_field :distributor_id + .omega.six.columns + %p + %b Order cycle: + = f.object.order_cycle.andand.name || "None" + = f.hidden_field :order_cycle_id + + - else + .alpha.six.columns + .field + %label{for: "order_distributor_id"} Distributor + %input.ofn-select2.fullwidth{id: "order_distributor_id", + type: 'number', + name: "order[distributor_id]", + "ng-model" => 'distributor_id', + data: "shops" } + + .omega.six.columns + .field + %label{ for: "order_order_cycle_id"} Order Cycle + %input.ofn-select2.fullwidth{id: "order_order_cycle_id", + type: 'number', + name: "order[order_cycle_id]", + "ng-model" => 'order_cycle_id', + "ng-disabled" => "!distributor_id", + data: "orderCycles", + text: "name_and_status", + filter: "validOrderCycle" } diff --git a/app/views/spree/admin/orders/set_distribution.html.haml b/app/views/spree/admin/orders/set_distribution.html.haml new file mode 100644 index 0000000000..f867ad4cb1 --- /dev/null +++ b/app/views/spree/admin/orders/set_distribution.html.haml @@ -0,0 +1,20 @@ +- content_for :page_title do + = t(:new) + +- content_for :page_actions do + %li= button_link_to t(:back_to_orders_list), spree.admin_orders_path, :icon => 'icon-arrow-left' + += admin_inject_shops 'admin.orders' += admin_inject_order_cycles + += render 'spree/admin/shared/order_tabs', :current => 'Order Details' + += csrf_meta_tags + +%div{"data-hook" => "admin_order_new_header"} + = render 'spree/shared/error_messages', :target => @order + +%div{"ng-app" => "admin.orders", "ng-controller" => "ordersCtrl"} + = form_for @order, url: admin_order_url(@order), method: :put do |f| + = render '_form/_distribution_fields.html.haml' + # ......