From e79a23a5542058ef5e6d241d12d97ba0fbfd88cd Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 28 Apr 2017 14:42:00 +1000 Subject: [PATCH] Disabling save button on order page until changes are made to the order --- .../javascripts/darkswarm/directives/on_hand.js.coffee | 6 +++++- app/views/spree/orders/form/_update_buttons.html.haml | 5 +++-- app/views/spree/shared/_order_details.html.haml | 2 +- config/locales/en.yml | 1 + spec/features/consumer/shopping/orders_spec.rb | 6 ++++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee b/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee index 610b11d3ca..3c51f86c2f 100644 --- a/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/on_hand.js.coffee @@ -6,7 +6,11 @@ Darkswarm.directive "ofnOnHand", -> # In cases where this field gets its value from the HTML element rather than the model, # initialise the model with the HTML value. if scope.$eval(attr.ngModel) == undefined - ngModel.$setViewValue elem.val() + # Don't dirty the model when we do this + setDirty = ngModel.$setDirty + ngModel.$setDirty = angular.noop + ngModel.$setViewValue(elem.val()) + ngModel.$setDirty = setDirty ngModel.$parsers.push (viewValue) -> on_hand = parseInt(attr.ofnOnHand) diff --git a/app/views/spree/orders/form/_update_buttons.html.haml b/app/views/spree/orders/form/_update_buttons.html.haml index 46d36e0e5c..35debc535f 100644 --- a/app/views/spree/orders/form/_update_buttons.html.haml +++ b/app/views/spree/orders/form/_update_buttons.html.haml @@ -15,6 +15,7 @@ %i.ofn-i_009-close = t(:cancel_order) .columns.small-12.medium-3 - = button_tag :class => 'button primary radius expand', :id => 'update-button' do + = button_tag :class => 'button primary radius expand', :id => 'update-button', "ng-disabled" => 'update_order_form.$pristine' do %i.ofn-i_051-check-big - = t(:save_changes) + %span{ ng: { show: 'update_order_form.$dirty' } }= t(:save_changes) + %span{ ng: { hide: 'update_order_form.$dirty' } }= t(:order_saved) diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index b9eeb26e77..50d72f8304 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -86,7 +86,7 @@ %br .row .columns.large-12 - = form_for order, html: {id: 'update-order'} do |order_form| + = form_for order, html: {id: 'update-order', name: 'update_order_form' } do |order_form| - if order.changes_allowed? = render 'spree/orders/form', order_form: order_form -else diff --git a/config/locales/en.yml b/config/locales/en.yml index f5935d819f..501b614e5a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1332,6 +1332,7 @@ Please follow the instructions there to make your enterprise visible on the Open price: "Price" on_hand: "On hand" save_changes: "Save Changes" + order_saved: "Order Saved" spree_admin_overview_enterprises_header: "My Enterprises" spree_admin_overview_enterprises_footer: "MANAGE MY ENTERPRISES" spree_admin_enterprises_hubs_name: "Name" diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb index f5962a232a..379f1b5197 100644 --- a/spec/features/consumer/shopping/orders_spec.rb +++ b/spec/features/consumer/shopping/orders_spec.rb @@ -43,12 +43,18 @@ feature "Order Management", js: true do it "allows quantity to be changed, items to be removed and the order to be cancelled" do visit spree.order_path(order) + expect(page).to have_button I18n.t(:order_saved), disabled: true + expect(page).to_not have_button I18n.t(:save_changes) + # Changing the quantity of an item within "tr.variant-#{item1.variant.id}" do expect(page).to have_content item1.product.name expect(page).to have_field 'order_line_items_attributes_0_quantity' fill_in 'order_line_items_attributes_0_quantity', with: 2 end + + expect(page).to have_button I18n.t(:save_changes) + expect(find("tr.variant-#{item2.variant.id}")).to have_content item2.product.name expect(find("tr.variant-#{item3.variant.id}")).to have_content item3.product.name expect(find("tr.order-adjustment")).to have_content "Shipping"