mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
Split out payment and shipping methods from admin enterprises controller as services
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
angular.module("admin.enterprises")
|
||||
.controller "enterpriseCtrl", ($scope, NavigationCheck, Enterprise, PaymentMethods, ShippingMethods, SideMenu) ->
|
||||
.controller "enterpriseCtrl", ($scope, NavigationCheck, Enterprise, EnterprisePaymentMethods, EnterpriseShippingMethods, SideMenu) ->
|
||||
$scope.Enterprise = Enterprise.enterprise
|
||||
$scope.PaymentMethods = PaymentMethods.paymentMethods
|
||||
$scope.ShippingMethods = ShippingMethods.shippingMethods
|
||||
console.log Enterprise
|
||||
$scope.PaymentMethods = EnterprisePaymentMethods.paymentMethods
|
||||
$scope.ShippingMethods = EnterpriseShippingMethods.shippingMethods
|
||||
$scope.navClear = NavigationCheck.clear
|
||||
# htmlVariable is used by textAngular wysiwyg for the long descrtiption.
|
||||
$scope.pristineEmail = $scope.Enterprise.email
|
||||
$scope.menu = SideMenu
|
||||
|
||||
@@ -17,33 +17,3 @@ angular.module("admin.enterprises")
|
||||
|
||||
# Register the NavigationCheck callback
|
||||
NavigationCheck.register(enterpriseNavCallback)
|
||||
|
||||
for payment_method in $scope.PaymentMethods
|
||||
payment_method.selected = payment_method.id in $scope.Enterprise.payment_method_ids
|
||||
|
||||
$scope.paymentMethodsColor = ->
|
||||
if $scope.PaymentMethods.length > 0
|
||||
if $scope.selectedPaymentMethodsCount() > 0 then "blue" else "red"
|
||||
else
|
||||
"red"
|
||||
|
||||
$scope.selectedPaymentMethodsCount = ->
|
||||
$scope.PaymentMethods.reduce (count, payment_method) ->
|
||||
count++ if payment_method.selected
|
||||
count
|
||||
, 0
|
||||
|
||||
for shipping_method in $scope.ShippingMethods
|
||||
shipping_method.selected = shipping_method.id in $scope.Enterprise.shipping_method_ids
|
||||
|
||||
$scope.shippingMethodsColor = ->
|
||||
if $scope.ShippingMethods.length > 0
|
||||
if $scope.selectedShippingMethodsCount() > 0 then "blue" else "red"
|
||||
else
|
||||
"red"
|
||||
|
||||
$scope.selectedShippingMethodsCount = ->
|
||||
$scope.ShippingMethods.reduce (count, shipping_method) ->
|
||||
count++ if shipping_method.selected
|
||||
count
|
||||
, 0
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
angular.module("admin.enterprises")
|
||||
.factory "EnterprisePaymentMethods", (Enterprise, PaymentMethods) ->
|
||||
new class EnterprisePaymentMethods
|
||||
paymentMethods: PaymentMethods.paymentMethods
|
||||
|
||||
constructor: ->
|
||||
for payment_method in @paymentMethods
|
||||
payment_method.selected = payment_method.id in Enterprise.enterprise.payment_method_ids
|
||||
|
||||
displayColor: ->
|
||||
if @paymentMethods.length > 0 && @selectedCount() > 0
|
||||
"blue"
|
||||
else
|
||||
"red"
|
||||
|
||||
selectedCount: ->
|
||||
@paymentMethods.reduce (count, payment_method) ->
|
||||
count++ if payment_method.selected
|
||||
count
|
||||
, 0
|
||||
@@ -0,0 +1,20 @@
|
||||
angular.module("admin.enterprises")
|
||||
.factory "EnterpriseShippingMethods", (Enterprise, ShippingMethods) ->
|
||||
new class EnterpriseShippingMethods
|
||||
shippingMethods: ShippingMethods.shippingMethods
|
||||
|
||||
constructor: ->
|
||||
for shipping_method in @shippingMethods
|
||||
shipping_method.selected = shipping_method.id in Enterprise.enterprise.shipping_method_ids
|
||||
|
||||
displayColor: ->
|
||||
if @shippingMethods.length > 0 && @selectedCount() > 0
|
||||
"blue"
|
||||
else
|
||||
"red"
|
||||
|
||||
selectedCount: ->
|
||||
@shippingMethods.reduce (count, shipping_method) ->
|
||||
count++ if shipping_method.selected
|
||||
count
|
||||
, 0
|
||||
@@ -2,7 +2,7 @@ angular.module("admin.payment_methods")
|
||||
.factory "PaymentMethods", (paymentMethods) ->
|
||||
new class PaymentMethods
|
||||
paymentMethods: paymentMethods
|
||||
|
||||
|
||||
findByID: (id) ->
|
||||
for paymentMethod in @paymentMethods
|
||||
return paymentMethod if paymentMethod.id is id
|
||||
|
||||
@@ -2,7 +2,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user