spree_frontend 3.6.6 → 3.7.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/frontend.js +8 -0
  3. data/app/assets/javascripts/spree/frontend/api_tokens.js +17 -0
  4. data/app/assets/javascripts/spree/frontend/cart.js +59 -0
  5. data/app/assets/javascripts/spree/frontend/checkout.js +19 -0
  6. data/app/assets/javascripts/spree/frontend/checkout/address.js +102 -0
  7. data/app/assets/javascripts/spree/frontend/checkout/payment.js +57 -0
  8. data/app/assets/javascripts/spree/frontend/checkout/shipment.js +47 -0
  9. data/app/assets/javascripts/spree/frontend/coupon_manager.js +45 -0
  10. data/app/assets/javascripts/spree/frontend/product.js +104 -51
  11. data/app/controllers/spree/checkout_controller.rb +7 -13
  12. data/app/controllers/spree/locale_controller.rb +1 -3
  13. data/app/controllers/spree/orders_controller.rb +25 -10
  14. data/app/controllers/spree/store_controller.rb +12 -0
  15. data/app/helpers/spree/frontend_helper.rb +8 -12
  16. data/app/views/spree/checkout/_payment.html.erb +3 -3
  17. data/app/views/spree/checkout/edit.html.erb +1 -1
  18. data/app/views/spree/orders/edit.html.erb +1 -2
  19. data/app/views/spree/products/_cart_form.html.erb +10 -4
  20. data/app/views/spree/products/_properties.html.erb +1 -1
  21. data/app/views/spree/products/_thumbnails.html.erb +4 -2
  22. data/config/routes.rb +3 -0
  23. data/lib/generators/spree/frontend/copy_views/copy_views_generator.rb +1 -1
  24. data/spree_frontend.gemspec +2 -2
  25. metadata +18 -23
  26. data/app/assets/javascripts/spree/frontend/cart.js.coffee +0 -28
  27. data/app/assets/javascripts/spree/frontend/checkout.js.coffee +0 -16
  28. data/app/assets/javascripts/spree/frontend/checkout/address.js.coffee +0 -81
  29. data/app/assets/javascripts/spree/frontend/checkout/payment.js.coffee +0 -57
  30. data/app/assets/javascripts/spree/frontend/checkout/shipment.js.coffee +0 -41
  31. data/app/assets/javascripts/spree/frontend/coupon_manager.js.coffee +0 -37
@@ -1,28 +0,0 @@
1
- #= require spree/frontend/coupon_manager
2
-
3
- Spree.ready ($) ->
4
- if ($ 'form#update-cart').length
5
- ($ 'form#update-cart a.delete').show().one 'click', ->
6
- ($ this).parents('.line-item').first().find('input.line_item_quantity').val 0
7
- ($ this).parents('form').first().submit()
8
- false
9
-
10
- ($ 'form#update-cart').submit (event) ->
11
- ($ 'form#update-cart #update-button').attr('disabled', true)
12
- input =
13
- couponCodeField: $('#order_coupon_code')
14
- couponStatus: $('#coupon_status')
15
- if $.trim(input.couponCodeField.val()).length > 0
16
- if new CouponManager(input).applyCoupon()
17
- @submit()
18
- return true
19
- else
20
- ($ 'form#update-cart #update-button').attr('disabled', false)
21
- event.preventDefault()
22
- return false
23
-
24
- Spree.fetch_cart = ->
25
- $.ajax
26
- url: Spree.pathFor("cart_link"),
27
- success: (data) ->
28
- $('#link-to-cart').html data
@@ -1,16 +0,0 @@
1
- Spree.disableSaveOnClick = ->
2
- ($ 'form.edit_order').on('submit', (e) ->
3
- if (($ this).data('submitted') == true)
4
- # Previously submitted, don't submit again
5
- e.preventDefault()
6
- else
7
- # Mark it so that the next submit gets ignored
8
- ($ this).data('submitted', true)
9
- ($ this).find(':submit, :image').removeClass('primary').addClass 'disabled'
10
- )
11
-
12
- Spree.enableSave = ->
13
- ($ 'form.edit_order').data('submitted', false).find(':submit, :image').attr('disabled', false).addClass('primary').removeClass 'disabled'
14
-
15
- Spree.ready ($) ->
16
- Spree.Checkout = {}
@@ -1,81 +0,0 @@
1
- Spree.ready ($) ->
2
- Spree.onAddress = () ->
3
- if ($ '#checkout_form_address').length
4
- getCountryId = (region) ->
5
- $('#' + region + 'country select').val()
6
-
7
- Spree.updateState = (region) ->
8
- countryId = getCountryId(region)
9
- if countryId?
10
- unless Spree.Checkout[countryId]?
11
- $.get Spree.routes.states_search, {country_id: countryId}, (data) ->
12
- Spree.Checkout[countryId] =
13
- states: data.states
14
- states_required: data.states_required
15
- Spree.fillStates(Spree.Checkout[countryId], region)
16
- else
17
- Spree.fillStates(Spree.Checkout[countryId], region)
18
-
19
- Spree.fillStates = (data, region) ->
20
- statesRequired = data.states_required
21
- states = data.states
22
-
23
- statePara = ($ '#' + region + 'state')
24
- stateSelect = statePara.find('select')
25
- stateInput = statePara.find('input')
26
- stateSpanRequired = statePara.find('[id$="state-required"]')
27
- if states.length > 0
28
- selected = parseInt stateSelect.val()
29
- stateSelect.html ''
30
- statesWithBlank = [{ name: '', id: ''}].concat(states)
31
- $.each statesWithBlank, (idx, state) ->
32
- opt = ($ document.createElement('option')).attr('value', state.id).html(state.name)
33
- opt.prop 'selected', true if selected is state.id
34
- stateSelect.append opt
35
-
36
- stateSelect.prop('disabled', false).show()
37
- stateInput.hide().prop 'disabled', true
38
- statePara.show()
39
- stateSpanRequired.show()
40
- stateSelect.addClass('required') if statesRequired
41
- stateSelect.removeClass('hidden')
42
- stateInput.removeClass('required')
43
- else
44
- stateSelect.hide().prop 'disabled', true
45
- stateInput.show()
46
- if statesRequired
47
- stateSpanRequired.show()
48
- stateInput.addClass('required')
49
- else
50
- stateInput.val ''
51
- stateSpanRequired.hide()
52
- stateInput.removeClass('required')
53
- statePara.toggle(!!statesRequired)
54
- stateInput.prop('disabled', !statesRequired)
55
- stateInput.removeClass('hidden')
56
- stateSelect.removeClass('required')
57
-
58
- ($ '#bcountry select').change ->
59
- Spree.updateState 'b'
60
-
61
- ($ '#scountry select').change ->
62
- Spree.updateState 's'
63
-
64
- Spree.updateState 'b'
65
-
66
- order_use_billing = ($ 'input#order_use_billing')
67
- order_use_billing.change ->
68
- update_shipping_form_state order_use_billing
69
-
70
- update_shipping_form_state = (order_use_billing) ->
71
- if order_use_billing.is(':checked')
72
- ($ '#shipping .inner').hide()
73
- ($ '#shipping .inner input, #shipping .inner select').prop 'disabled', true
74
- else
75
- ($ '#shipping .inner').show()
76
- ($ '#shipping .inner input, #shipping .inner select').prop 'disabled', false
77
- Spree.updateState('s')
78
-
79
- update_shipping_form_state order_use_billing
80
-
81
- Spree.onAddress()
@@ -1,57 +0,0 @@
1
- #= require spree/frontend/coupon_manager
2
- Spree.ready ($) ->
3
- Spree.onPayment = () ->
4
- if ($ '#checkout_form_payment').length
5
-
6
- if ($ '#existing_cards').length
7
- ($ '#payment-method-fields').hide()
8
- ($ '#payment-methods').hide()
9
-
10
- ($ '#use_existing_card_yes').click ->
11
- ($ '#payment-method-fields').hide()
12
- ($ '#payment-methods').hide()
13
- ($ '.existing-cc-radio').prop("disabled", false)
14
-
15
- ($ '#use_existing_card_no').click ->
16
- ($ '#payment-method-fields').show()
17
- ($ '#payment-methods').show()
18
- ($ '.existing-cc-radio').prop("disabled", true)
19
-
20
-
21
- $(".cardNumber").payment('formatCardNumber')
22
- $(".cardExpiry").payment('formatCardExpiry')
23
- $(".cardCode").payment('formatCardCVC')
24
-
25
- $(".cardNumber").change ->
26
- $(this).parent().siblings(".ccType").val($.payment.cardType(@value))
27
-
28
- ($ 'input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(->
29
- ($ '#payment-methods li').hide()
30
- ($ '#payment_method_' + @value).show() if @checked
31
- )
32
-
33
- ($ document).on('click', '#cvv_link', (event) ->
34
- windowName = 'cvv_info'
35
- windowOptions = 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1'
36
- window.open(($ this).attr('href'), windowName, windowOptions)
37
- event.preventDefault()
38
- )
39
-
40
- # Activate already checked payment method if form is re-rendered
41
- # i.e. if user enters invalid data
42
- ($ 'input[type="radio"]:checked').click()
43
-
44
- $('#checkout_form_payment').submit (event) ->
45
- input =
46
- couponCodeField: $('#order_coupon_code')
47
- couponStatus: $('#coupon_status')
48
- if $.trim(input.couponCodeField.val()).length > 0
49
- if new CouponManager(input).applyCoupon()
50
- @submit()
51
- return true
52
- else
53
- Spree.enableSave()
54
- event.preventDefault()
55
- return false
56
-
57
- Spree.onPayment()
@@ -1,41 +0,0 @@
1
- class @ShippingTotalManager
2
- constructor: (@input) ->
3
- @shippingMethods = @input.shippingMethods
4
- @shipmentTotal = @input.shipmentTotal
5
- @orderTotal = @input.orderTotal
6
- @formatOptions = {
7
- symbol : @shipmentTotal.data('currency'),
8
- decimal : @shipmentTotal.attr('decimal-mark'),
9
- thousand: @shipmentTotal.attr('thousands-separator'),
10
- precision : 2 }
11
-
12
- calculateShipmentTotal: ->
13
- @sum = 0
14
- $.each ($(@shippingMethods).filter(':checked')), (idx, shippingMethod) =>
15
- @sum += @parseCurrencyToFloat($(shippingMethod).data('cost'))
16
-
17
- @readjustSummarySection(
18
- @parseCurrencyToFloat(@orderTotal.html()),
19
- @sum,
20
- @parseCurrencyToFloat(@shipmentTotal.html())
21
- )
22
-
23
- parseCurrencyToFloat: (input) ->
24
- accounting.unformat(input, @formatOptions.decimal)
25
-
26
- readjustSummarySection: (orderTotal, newShipmentTotal, oldShipmentTotal) ->
27
- newOrderTotal = orderTotal + (newShipmentTotal - oldShipmentTotal)
28
- @shipmentTotal.html(accounting.formatMoney(newShipmentTotal, @formatOptions))
29
- @orderTotal.html(accounting.formatMoney(newOrderTotal, @formatOptions))
30
-
31
- bindEvent: ->
32
- @shippingMethods.change =>
33
- @calculateShipmentTotal()
34
-
35
- Spree.ready ($) ->
36
- input =
37
- orderTotal: $('#summary-order-total')
38
- shipmentTotal: $("[data-hook='shipping-total']")
39
- shippingMethods: $("input[data-behavior='shipping-method-selector']")
40
-
41
- new ShippingTotalManager(input).bindEvent()
@@ -1,37 +0,0 @@
1
- class @CouponManager
2
- constructor: (@input) ->
3
- @couponCodeField = @input.couponCodeField
4
- @couponApplied = false
5
- @couponStatus = @input.couponStatus
6
-
7
- applyCoupon: ->
8
- @couponCode = $.trim($(@couponCodeField).val())
9
- if @couponCode != ''
10
- if @couponStatus.length == 0
11
- @couponStatus = $('<div/>', { id: 'coupon_status' })
12
- @couponCodeField.parent().append @couponStatus
13
- @createUrl()
14
- @couponStatus.removeClass()
15
- @sendRequest()
16
- @couponApplied
17
- else
18
- true
19
-
20
- createUrl: ->
21
- @url = Spree.url(Spree.routes.apply_coupon_code(Spree.current_order_id),
22
- order_token: Spree.current_order_token
23
- coupon_code: @couponCode)
24
-
25
- sendRequest: ->
26
- $.ajax
27
- async: false
28
- method: 'PUT'
29
- url: @url
30
- success: =>
31
- @couponCodeField.val ''
32
- @couponStatus.addClass('alert-success')
33
- .html Spree.translations.coupon_code_applied
34
- @couponApplied = true
35
- error: (xhr) =>
36
- handler = JSON.parse(xhr.responseText)
37
- @couponStatus.addClass('alert-error').html handler['error']