mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-14 04:04:23 +00:00
Add shipping method js infrastructure for angularising admin enterprises page
This commit is contained in:
@@ -1,19 +1,35 @@
|
||||
angular.module("admin.enterprises")
|
||||
.controller "enterpriseCtrl", ($scope, Enterprise, PaymentMethods) ->
|
||||
.controller "enterpriseCtrl", ($scope, Enterprise, PaymentMethods, ShippingMethods) ->
|
||||
$scope.Enterprise = Enterprise.enterprise
|
||||
$scope.PaymentMethods = PaymentMethods.paymentMethods
|
||||
$scope.ShippingMethods = ShippingMethods.shippingMethods
|
||||
|
||||
for PaymentMethod in $scope.PaymentMethods
|
||||
PaymentMethod.selected = if PaymentMethod.id in $scope.Enterprise.payment_method_ids then true else false
|
||||
|
||||
$scope.paymentMethodsColor = ->
|
||||
if $scope.PaymentMethods.length > 0
|
||||
if $scope.selectedPaymentMethodsCount() > 0 then "blue" else "red"
|
||||
else
|
||||
"red"
|
||||
|
||||
$scope.selectedPaymentMethodsCount = ->
|
||||
$scope.PaymentMethods.reduce (count, PaymentMethod) ->
|
||||
count++ if PaymentMethod.selected
|
||||
count
|
||||
, 0
|
||||
|
||||
$scope.paymentMethodsColor = ->
|
||||
if $scope.PaymentMethods.length > 0
|
||||
if $scope.selectedPaymentMethodsCount() > 0 then "blue" else "red"
|
||||
for ShippingMethod in $scope.ShippingMethods
|
||||
ShippingMethod.selected = if ShippingMethod.id in $scope.Enterprise.shipping_method_ids then true else false
|
||||
|
||||
$scope.shippingMethodsColor = ->
|
||||
if $scope.ShippingMethods.length > 0
|
||||
if $scope.selectedShippingMethodsCount() > 0 then "blue" else "red"
|
||||
else
|
||||
"red"
|
||||
"red"
|
||||
|
||||
$scope.selectedShippingMethodsCount = ->
|
||||
$scope.ShippingMethods.reduce (count, ShippingMethod) ->
|
||||
count++ if ShippingMethod.selected
|
||||
count
|
||||
, 0
|
||||
@@ -1 +1 @@
|
||||
angular.module("admin.enterprises", ["admin.payment_methods"])
|
||||
angular.module("admin.enterprises", ["admin.payment_methods", "admin.shipping_methods"])
|
||||
@@ -0,0 +1,4 @@
|
||||
angular.module("admin.shipping_methods")
|
||||
.controller "shippingMethodCtrl", ($scope, ShippingMethods) ->
|
||||
$scope.findShippingMethodByID = (id) ->
|
||||
$scope.ShippingMethod = ShippingMethods.findByID(id)
|
||||
@@ -0,0 +1,8 @@
|
||||
angular.module("admin.shipping_methods")
|
||||
.factory "ShippingMethods", (shippingMethods) ->
|
||||
new class ShippingMethods
|
||||
shippingMethods: shippingMethods
|
||||
|
||||
findByID: (id) ->
|
||||
for shippingMethod in @shippingMethods
|
||||
return shippingMethod if shippingMethod.id is id
|
||||
@@ -0,0 +1 @@
|
||||
angular.module("admin.shipping_methods", [])
|
||||
Reference in New Issue
Block a user