diff --git a/app/assets/javascripts/store/shop_front.js.coffee b/app/assets/javascripts/store/shop_front.js.coffee index 2de0c9e530..1a7044732f 100644 --- a/app/assets/javascripts/store/shop_front.js.coffee +++ b/app/assets/javascripts/store/shop_front.js.coffee @@ -1,5 +1,4 @@ $(document).ready -> $("#order_order_cycle_id").change -> $("#order_cycle_select").submit() - $("#reset_order_cycle").click -> return false unless confirm "Performing this action will clear your cart." - - + $("#reset_order_cycle").click -> return false unless confirm "Changing your collection date will clear your cart." + $(".shop-distributor.empties-cart").click -> return false unless confirm "Changing your location will clear your cart." diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 54e876e9a3..1fc4191ce4 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,4 @@ -class HomeController < ApplicationController +class HomeController < BaseController layout 'landing_page' def new_landing_page diff --git a/app/helpers/temp_landing_page_helper.rb b/app/helpers/temp_landing_page_helper.rb new file mode 100644 index 0000000000..b511d9fae6 --- /dev/null +++ b/app/helpers/temp_landing_page_helper.rb @@ -0,0 +1,9 @@ +module TempLandingPageHelper + def temp_landing_page_distributor_link_class(distributor) + cart = current_order(true) + + klass = "shop-distributor" + klass += " empties-cart" unless cart.line_items.empty? || cart.distributor == distributor + klass + end +end diff --git a/app/views/home/temp_landing_page.html.haml b/app/views/home/temp_landing_page.html.haml index 5f974531c8..519778fc89 100644 --- a/app/views/home/temp_landing_page.html.haml +++ b/app/views/home/temp_landing_page.html.haml @@ -8,6 +8,7 @@ = favicon_link_tag "favicon.ico" = stylesheet_link_tag "search/all" = javascript_include_tag "search/all" + = javascript_include_tag "store/shop_front" = render "layouts/bugherd_script" = csrf_meta_tags @@ -37,7 +38,7 @@ .row.distributor-link-row .large-12.columns = succeed ',' do - = link_to "#{distributor.name}".html_safe, shop_enterprise_path(distributor) + = link_to "#{distributor.name}".html_safe, shop_enterprise_path(distributor), {class: temp_landing_page_distributor_link_class(distributor)} %span.secondary= distributor.city %footer diff --git a/spec/helpers/temp_landing_page_helper_spec.rb b/spec/helpers/temp_landing_page_helper_spec.rb new file mode 100644 index 0000000000..804b34c355 --- /dev/null +++ b/spec/helpers/temp_landing_page_helper_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe HtmlHelper do + subject do + obj = Object.new + obj.extend TempLandingPageHelper + end + + it "does not require emptying the cart when it is empty" do + d = double(:distributor) + order = double(:order, line_items: []) + subject.stub(:current_order) { order } + subject.temp_landing_page_distributor_link_class(d).should_not =~ /empties-cart/ + end + + it "does not require emptying the cart when we are on the same distributor" do + d = double(:distributor) + order = double(:order, line_items: [double(:line_item)], distributor: d) + subject.stub(:current_order) { order } + subject.temp_landing_page_distributor_link_class(d).should_not =~ /empties-cart/ + end + + it "requires emptying the cart otherwise" do + d1 = double(:distributor) + d2 = double(:distributor) + order = double(:order, line_items: [double(:line_item)], distributor: d2) + subject.stub(:current_order) { order } + subject.temp_landing_page_distributor_link_class(d1).should =~ /empties-cart/ + end + +end