mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Merge branch 'master' into laura_and_will
Conflicts: app/views/shopping_shared/_contact.html.haml
This commit is contained in:
@@ -9,8 +9,8 @@ Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout) ->
|
||||
$scope.show = (name)->
|
||||
$scope.accordion[name] = true
|
||||
|
||||
$timeout =>
|
||||
if $scope.checkout.$valid
|
||||
for k, v of $scope.accordion
|
||||
$scope.accordion[k] = false
|
||||
#$timeout =>
|
||||
#if $scope.checkout.$valid
|
||||
#for k, v of $scope.accordion
|
||||
#$scope.accordion[k] = false
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Darkswarm.controller "BillingCtrl", ($scope) ->
|
||||
Darkswarm.controller "BillingCtrl", ($scope, $timeout) ->
|
||||
angular.extend(this, new FieldsetMixin($scope))
|
||||
$scope.name = "billing"
|
||||
$scope.nextPanel = "shipping"
|
||||
@@ -8,3 +8,4 @@ Darkswarm.controller "BillingCtrl", ($scope) ->
|
||||
$scope.order.bill_address.city,
|
||||
$scope.order.bill_address.zipcode]
|
||||
|
||||
#$timeout $scope.onTimeout
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
Darkswarm.controller "CheckoutCtrl", ($scope, storage, CheckoutFormState, Order, CurrentUser) ->
|
||||
Darkswarm.controller "CheckoutCtrl", ($scope, storage, Order, CurrentUser) ->
|
||||
$scope.Order = Order
|
||||
storage.bind $scope, "Order.order", {storeName: "order_#{Order.order.id}#{Order.order.user_id}"}
|
||||
Order.bindFieldsToLocalStorage($scope)
|
||||
|
||||
$scope.order = Order.order # Ordering is important
|
||||
$scope.secrets = Order.secrets
|
||||
|
||||
$scope.enabled = if CurrentUser then true else false
|
||||
|
||||
$scope.purchase = (event)->
|
||||
event.preventDefault()
|
||||
$scope.Order.submit()
|
||||
|
||||
$scope.CheckoutFormState = CheckoutFormState
|
||||
storage.bind $scope, "CheckoutFormState.ship_address_same_as_billing", { defaultValue: true}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
Darkswarm.controller "DetailsCtrl", ($scope) ->
|
||||
Darkswarm.controller "DetailsCtrl", ($scope, $timeout) ->
|
||||
angular.extend(this, new FieldsetMixin($scope))
|
||||
|
||||
$scope.name = "details"
|
||||
$scope.nextPanel = "billing"
|
||||
|
||||
@@ -12,3 +11,5 @@ Darkswarm.controller "DetailsCtrl", ($scope) ->
|
||||
$scope.fullName = ->
|
||||
[$scope.order.bill_address.firstname ? null,
|
||||
$scope.order.bill_address.lastname ? null].join(" ").trim()
|
||||
|
||||
$timeout $scope.onTimeout
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
Darkswarm.controller "PaymentCtrl", ($scope) ->
|
||||
Darkswarm.controller "PaymentCtrl", ($scope, $timeout) ->
|
||||
angular.extend(this, new FieldsetMixin($scope))
|
||||
$scope.name = "payment"
|
||||
|
||||
$scope.months = {1: "January", 2: "February", 3: "March", 4: "April", 5: "May", 6: "June", 7: "July", 8: "August", 9: "September", 10: "October", 11: "November", 12: "December"}
|
||||
$scope.years = [moment().year()..(moment().year()+15)]
|
||||
$scope.secrets.card_month = "1"
|
||||
$scope.secrets.card_year = moment().year()
|
||||
$timeout $scope.onTimeout
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Darkswarm.controller "ShippingCtrl", ($scope) ->
|
||||
Darkswarm.controller "ShippingCtrl", ($scope, $timeout) ->
|
||||
angular.extend(this, new FieldsetMixin($scope))
|
||||
$scope.name = "shipping"
|
||||
$scope.nextPanel = "payment"
|
||||
|
||||
$timeout $scope.onTimeout
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
Darkswarm.directive "ofnFlash", (flash, $timeout)->
|
||||
typePairings =
|
||||
info: "standard"
|
||||
error: "alert"
|
||||
success: "success"
|
||||
scope: {}
|
||||
restrict: 'AE'
|
||||
template: "<alert ng-repeat='flash in flashes' type='flash.type'>{{flash.message}}</alert>"
|
||||
templateUrl: "flash.html"
|
||||
controller: ($scope)->
|
||||
$scope.closeAlert = (index)->
|
||||
$scope.flashes.splice(index, 1)
|
||||
|
||||
link: ($scope, element, attr) ->
|
||||
$scope.flashes = []
|
||||
show = (message, type)->
|
||||
show = (message, type)=>
|
||||
if message
|
||||
$scope.flashes.push({message: message, type: type})
|
||||
$scope.flashes.push({message: message, type: typePairings[type]})
|
||||
$timeout($scope.delete, 5000)
|
||||
|
||||
$scope.delete = ->
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
window.FieldsetMixin = ($scope)->
|
||||
$scope.next = (event)->
|
||||
event.preventDefault()
|
||||
$scope.next = (event = false)->
|
||||
event.preventDefault() if event
|
||||
$scope.show $scope.nextPanel
|
||||
|
||||
$scope.onTimeout = ->
|
||||
if $scope[$scope.name].$valid
|
||||
$scope.next()
|
||||
|
||||
$scope.valid = ->
|
||||
$scope.form().$valid
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
Darkswarm.factory 'CheckoutFormState', ()->
|
||||
# Just a singleton place to store data about the form state
|
||||
new class CheckoutFormState
|
||||
@@ -2,6 +2,5 @@ Darkswarm.factory 'CurrentOrder', (currentOrder) ->
|
||||
new class CurrentOrder
|
||||
constructor: ->
|
||||
@[k] = v for k, v of currentOrder
|
||||
|
||||
empty: =>
|
||||
@line_items.length == 0
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
Darkswarm.factory 'Flash', (flash)->
|
||||
new class Flash
|
||||
loadFlash: (rails_flash)->
|
||||
for type, message of rails_flash
|
||||
switch type
|
||||
when "notice"
|
||||
flash.info = message
|
||||
else
|
||||
flash[type] = message
|
||||
@@ -1,9 +1,23 @@
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, CheckoutFormState, flash, Navigation)->
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, flash, Navigation, storage)->
|
||||
new class Order
|
||||
errors: {}
|
||||
secrets: {}
|
||||
order: order
|
||||
ship_address_same_as_billing: true
|
||||
|
||||
constructor: ->
|
||||
@order = order
|
||||
#Whitelist of fields from Order.order to bind into localStorage
|
||||
fieldsToBind: ["bill_address", "email", "payment_method_id", "shipping_method_id", "ship_address"]
|
||||
|
||||
# Bind all the fields from fieldsToBind, + anything on the Order class
|
||||
bindFieldsToLocalStorage: (scope)=>
|
||||
prefix = "order_#{@order.id}#{@order.user_id}"
|
||||
for field in @fieldsToBind
|
||||
storage.bind scope, "Order.order.#{field}",
|
||||
storeName: "#{prefix}_#{field}"
|
||||
|
||||
storage.bind scope, "Order.ship_address_same_as_billing",
|
||||
storeName: "#{prefix}_sameasbilling"
|
||||
defaultValue: true
|
||||
|
||||
submit: ->
|
||||
$http.put('/checkout', {order: @preprocess()}).success (data, status)=>
|
||||
@@ -24,12 +38,25 @@ Darkswarm.factory 'Order', ($resource, order, $http, CheckoutFormState, flash, N
|
||||
munged_order["ship_address_attributes"] = value
|
||||
when "payment_method_id"
|
||||
munged_order["payments_attributes"] = [{payment_method_id: value}]
|
||||
|
||||
when "form_state" # don't keep this shit
|
||||
else
|
||||
munged_order[name] = value
|
||||
|
||||
if CheckoutFormState.ship_address_same_as_billing
|
||||
if @ship_address_same_as_billing
|
||||
munged_order.ship_address_attributes = munged_order.bill_address_attributes
|
||||
|
||||
if @paymentMethod()?.method_type == 'gateway'
|
||||
angular.extend munged_order.payments_attributes[0], {
|
||||
source_attributes:
|
||||
number: @secrets.card_number
|
||||
month: @secrets.card_month
|
||||
year: @secrets.card_year
|
||||
verification_value: @secrets.card_verification_value
|
||||
first_name: @order.bill_address.firstname
|
||||
last_name: @order.bill_address.lastname
|
||||
}
|
||||
|
||||
munged_order
|
||||
|
||||
shippingMethod: ->
|
||||
@@ -39,7 +66,7 @@ Darkswarm.factory 'Order', ($resource, order, $http, CheckoutFormState, flash, N
|
||||
@shippingMethod()?.require_ship_address
|
||||
|
||||
shippingPrice: ->
|
||||
@shippingMethod()?.price
|
||||
@shippingMethod()?.price || 0.0
|
||||
|
||||
paymentMethod: ->
|
||||
@order.payment_methods[@order.payment_method_id]
|
||||
|
||||
2
app/assets/javascripts/templates/flash.html.haml
Normal file
2
app/assets/javascripts/templates/flash.html.haml
Normal file
@@ -0,0 +1,2 @@
|
||||
%alert{close: "closeAlert($index)", "ng-repeat" => "flash in flashes", type: "flash.type"}
|
||||
{{ flash.message }}
|
||||
Reference in New Issue
Block a user