mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Working with ngForm and subcontrollers. Also fixing bulk order specs
This commit is contained in:
@@ -338,4 +338,4 @@ formatDate = (date) ->
|
||||
twoDigitNumber = (number) ->
|
||||
twoDigits = "" + number
|
||||
twoDigits = ("0" + number) if number < 10
|
||||
twoDigits
|
||||
twoDigits
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Darkswarm.controller "BillingCtrl", ($scope) ->
|
||||
angular.extend(this, new FieldsetMixin($scope))
|
||||
$scope.name = "billing"
|
||||
@@ -0,0 +1,3 @@
|
||||
Darkswarm.controller "ShippingCtrl", ($scope) ->
|
||||
angular.extend(this, new FieldsetMixin($scope))
|
||||
$scope.name = "shipping"
|
||||
@@ -1,5 +1,4 @@
|
||||
Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage) ->
|
||||
window.tmp = $scope
|
||||
$scope.Order = Order
|
||||
$scope.order = Order.order
|
||||
$scope.accordion = {}
|
||||
@@ -12,8 +11,9 @@ Darkswarm.controller "CheckoutCtrl", ($scope, Order, storage) ->
|
||||
storage.bind $scope, "accordion.billing"
|
||||
storage.bind $scope, "accordion.shipping"
|
||||
storage.bind $scope, "accordion.payment"
|
||||
storage.bind $scope, "order.ship_address_same_as_billing", { defaultValue: true}
|
||||
storage.bind $scope, "order.shipping_method_id"
|
||||
|
||||
$scope.purchase = (event)->
|
||||
event.preventDefault()
|
||||
$scope.Order.submit()
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
window.FieldsetMixin = ($scope)->
|
||||
$scope.valid = ->
|
||||
$scope.form().$valid
|
||||
|
||||
$scope.form = ->
|
||||
$scope[$scope.name]
|
||||
|
||||
$scope.field = (path)->
|
||||
$scope[$scope.name][path]
|
||||
$scope.form()[path]
|
||||
|
||||
$scope.fieldValid = (path)->
|
||||
not ($scope.dirty(path) and $scope.invalid(path))
|
||||
@@ -23,6 +29,3 @@ window.FieldsetMixin = ($scope)->
|
||||
when "number" then "must be number"
|
||||
when "email" then "must be email address"
|
||||
(errors.filter (error) -> error?).join ", "
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,17 +3,21 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)->
|
||||
errors: {}
|
||||
constructor: ->
|
||||
@order = order
|
||||
# Here we default to the first shipping method if none is selected
|
||||
# Default to first shipping method if none selected
|
||||
@order.shipping_method_id ||= parseInt(Object.keys(@order.shipping_methods)[0])
|
||||
@order.ship_address_same_as_billing ?= true
|
||||
|
||||
navigate: (path)->
|
||||
console.log path
|
||||
window.location.pathname = path
|
||||
|
||||
submit: ->
|
||||
$http.put('/shop/checkout', {order: @preprocess()}).success (data, status)=>
|
||||
console.log data
|
||||
window.location.pathname = data.path
|
||||
@navigate(data.path)
|
||||
.error (errors, status)=>
|
||||
console.log "error"
|
||||
@errors = errors
|
||||
|
||||
|
||||
|
||||
# Rails wants our Spree::Address data to be provided with _attributes
|
||||
preprocess: ->
|
||||
@@ -27,6 +31,9 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)->
|
||||
munged_order["payments_attributes"] = [{payment_method_id: value}]
|
||||
else
|
||||
munged_order[name] = value
|
||||
# TODO: this
|
||||
if munged_order.ship_address_same_as_billing
|
||||
munged_order.ship_address_attributes = munged_order.bill_address_attributes
|
||||
munged_order
|
||||
|
||||
shippingMethod: ->
|
||||
@@ -43,4 +50,3 @@ Darkswarm.factory 'Order', ($resource, Product, order, $http)->
|
||||
|
||||
cartTotal: ->
|
||||
@shippingPrice() + @order.display_total
|
||||
|
||||
|
||||
Reference in New Issue
Block a user