Confirm change hub when it would empty cart

This commit is contained in:
Rohan Mitchell
2013-09-23 10:07:25 +10:00
parent 767478a0ee
commit 803594b4d7
5 changed files with 45 additions and 5 deletions

View File

@@ -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."

View File

@@ -1,4 +1,4 @@
class HomeController < ApplicationController
class HomeController < BaseController
layout 'landing_page'
def new_landing_page

View File

@@ -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

View File

@@ -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 "<strong>#{distributor.name}</strong>".html_safe, shop_enterprise_path(distributor)
= link_to "<strong>#{distributor.name}</strong>".html_safe, shop_enterprise_path(distributor), {class: temp_landing_page_distributor_link_class(distributor)}
%span.secondary= distributor.city
%footer

View File

@@ -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