From 7dbb7a5c2c3c404aba8ddfec46287a7d74bb2d6c Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 31 Jan 2014 11:17:27 +0800 Subject: [PATCH] BOM: applying ofnLineItemUpdAttr directive to quantity field, tracks changes with update-pending class --- .../admin/bulk_order_management.js.coffee | 2 +- .../admin/orders/bulk_management.html.haml | 2 +- .../admin/bulk_order_management_spec.rb | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_order_management.js.coffee b/app/assets/javascripts/admin/bulk_order_management.js.coffee index fe4d6b5978..48cc961a37 100644 --- a/app/assets/javascripts/admin/bulk_order_management.js.coffee +++ b/app/assets/javascripts/admin/bulk_order_management.js.coffee @@ -29,7 +29,7 @@ orderManagementModule.directive "ofnLineItemUpdAttr", [ element: element attrName: attrName url: "/api/orders/#{scope.line_item.order.number}/line_items/#{scope.line_item.id}?line_item[#{attrName}]=#{value}" - pendingChanges.addItem(scope.line_item.id, attrName, changeObj) + pendingChanges.add(scope.line_item.id, attrName, changeObj) switchClass( element, "update-pending", ["update-error", "update-success"], false ) ] diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index 8bdf358ce9..96bc32b0cf 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -36,7 +36,7 @@ %td.producer {{ line_item.supplier.name }} %td.variant {{ line_item.variant_unit_text }} %td.quantity - %input{ :type => 'number', :name => 'quantity', 'ng-model' => "line_item.quantity" } + %input{ :type => 'number', :name => 'quantity', 'ng-model' => "line_item.quantity", 'ofn-line-item-upd-attr' => "quantity" } %td.max {{ line_item.max }} %td.actions %a{ 'ng-click' => "deleteLineItem(line_item)", :class => "delete-line-item icon-trash no-text" } \ No newline at end of file diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 19345c584c..4ad336e66d 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -83,6 +83,27 @@ feature %q{ end end + context "altering line item properties" do + before :each do + login_to_admin_section + end + + context "tracking changes" do + let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) } + let!(:li1) { FactoryGirl.create(:line_item, order: o1, :quantity => 5 ) } + + before :each do + visit '/admin/orders/bulk_management' + end + + it "adds the class 'update-pending' to input elements when value is altered" do + page.should_not have_css "input[name='quantity'].update-pending" + fill_in "quantity", :with => 2 + page.should have_css "input[name='quantity'].update-pending" + end + end + end + context "using page page controls" do before :each do login_to_admin_section