Angularise new order form

This commit is contained in:
Rohan Mitchell
2015-12-04 08:45:32 +11:00
parent eb07680f1f
commit 2daceb1111
6 changed files with 50 additions and 26 deletions

View File

@@ -0,0 +1,4 @@
angular.module("admin.orders").controller "ordersCtrl", ($scope, $compile, shops, orderCycles) ->
$scope.$compile = $compile
$scope.shops = shops
$scope.orderCycles = orderCycles

View File

@@ -0,0 +1,29 @@
/ 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
%select{id: "order_distributor_id", name: "order[distributor_id]", 'ng-model' => 'distributor_id'}
%option{"ng-repeat" => "shop in shops", "ng-value" => "shop.id", "ng-selected" => "distributor_id == shop.id", "ng-bind" => "shop.name"}
.omega.six.columns
.field
%label{for: "order_order_cycle_id"} Order Cycle
%select{id: "order_order_cycle_id", name: "order[order_cycle_id]", 'ng-model' => 'order_cycle_id'}
%option{"ng-repeat" => "oc in orderCycles", "ng-value" => "oc.id", "ng-selected" => "order_cycle_id == oc.id", "ng-bind" => "oc.name"}

View File

@@ -0,0 +1,5 @@
// The admin order form contains angular directives, so it needs to be
// compiled before insertion into the DOM
var scope = angular.element("#order-form-wrapper").scope();
$("#order-form-wrapper").html(scope.$compile('<%= escape_javascript(render :partial => "spree/admin/orders/form") %>')(scope));
scope.$apply();

View File

@@ -1,14 +0,0 @@
%fieldset.no-border-bottom
%legend{align: 'center'} Distribution
.alpha.six.columns
.field
%label{for: "distributor_id"} Distributor
%select{id: "distributor_id", 'ng-model' => "", 'ng-options' => ''}
-#= f.collection_select :distributor_id, Enterprise.is_distributor.managed_by(spree_current_user), :id, :name, include_blank: true
.omega.six.columns
.field
%label{for: "order_cycle_id"} Order Cycle
%select{id: "order_cycle_id", 'ng-model' => "", 'ng-options' => ''}
-#= f.collection_select :order_cycle_id, OrderCycle.managed_by(spree_current_user), :id, :name, include_blank: true

View File

@@ -14,14 +14,13 @@
%div{"data-hook" => "admin_order_new_header"}
= render 'spree/shared/error_messages', :target => @order
= render 'distribution_fields'
%div{"ng-app" => "admin.orders", "ng-controller" => "ordersCtrl"}
= render 'add_product'
= render 'add_product'
- unless @order.line_items.any?
%div{"data-hook" => "admin_order_new_form"}
#order-form-wrapper
= render 'form'
- unless @order.line_items.any?
%div{"data-hook" => "admin_order_new_form"}
#order-form-wrapper
= render 'form'
- content_for :head do
= javascript_tag 'var expand_variants = true;'

View File

@@ -22,23 +22,24 @@ feature %q{
end
scenario "creating an order with distributor and order cycle", js: true, retry: 3 do
order_cycle = create(:order_cycle)
distributor = order_cycle.distributors.first
product = order_cycle.products.first
distributor = create(:distributor_enterprise)
product = create(:simple_product)
order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.variants.first])
login_to_admin_section
visit '/admin/orders'
click_link 'New Order'
select distributor.name, from: 'order_distributor_id'
select order_cycle.name, from: 'order_order_cycle_id'
page.should have_content 'ADD PRODUCT'
targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
click_link 'Add'
page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
page.should have_selector 'td', text: product.name
select distributor.name, from: 'order_distributor_id'
select order_cycle.name, from: 'order_order_cycle_id'
click_button 'Update'
page.should have_selector 'h1', text: 'Customer Details'