mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-03 06:59:14 +00:00
Create factory to hold auxillary functions for subscriptions
NOTE: Moved estimatedSubtotal and estimatedTotal functions to the new factory from the subscription line items controller
This commit is contained in:
@@ -22,12 +22,3 @@ angular.module("admin.subscriptions").controller "SubscriptionLineItemsControlle
|
||||
sli.variant_id == $scope.newItem.variant_id
|
||||
return matching[0] if matching.length > 0
|
||||
null
|
||||
|
||||
$scope.estimatedSubtotal = ->
|
||||
$scope.subscription.subscription_line_items.reduce (subtotal, item) ->
|
||||
return subtotal if item._destroy
|
||||
subtotal += item.price_estimate * item.quantity
|
||||
, 0
|
||||
|
||||
$scope.estimatedTotal = ->
|
||||
$scope.estimatedSubtotal()
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# Provides additional auxillary functions to instances of SubsciptionResource
|
||||
# Used to extend the prototype of the subscription resource created by SubscriptionResource
|
||||
|
||||
angular.module("admin.subscriptions").factory 'SubscriptionFunctions', ->
|
||||
estimatedSubtotal: ->
|
||||
@subscription_line_items.reduce (subtotal, item) ->
|
||||
return subtotal if item._destroy
|
||||
subtotal += item.price_estimate * item.quantity
|
||||
, 0
|
||||
|
||||
estimatedTotal: ->
|
||||
@estimatedSubtotal()
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.subscriptions").factory 'SubscriptionResource', ($resource, SubscriptionActions) ->
|
||||
angular.module("admin.subscriptions").factory 'SubscriptionResource', ($resource, SubscriptionActions, SubscriptionFunctions) ->
|
||||
resource = $resource('/admin/subscriptions/:id/:action.json', {}, {
|
||||
'index':
|
||||
method: 'GET'
|
||||
@@ -27,5 +27,6 @@ angular.module("admin.subscriptions").factory 'SubscriptionResource', ($resource
|
||||
})
|
||||
|
||||
angular.extend(resource.prototype, SubscriptionActions)
|
||||
angular.extend(resource.prototype, SubscriptionFunctions)
|
||||
|
||||
resource
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
= t(:subtotal)
|
||||
\:
|
||||
%td.total.align-center
|
||||
%span {{ estimatedSubtotal() | currency }}
|
||||
%span {{ subscription.estimatedSubtotal() | currency }}
|
||||
%td.actions
|
||||
%tbody#order-total.grand-total.no-border-top{"data-hook" => "admin_order_form_total"}
|
||||
%tr
|
||||
@@ -38,5 +38,5 @@
|
||||
= t(:order_total_price)
|
||||
\:
|
||||
%td.total.align-center
|
||||
%span#order_form_total {{ estimatedTotal() | currency }}
|
||||
%span#order_form_total {{ subscription.estimatedTotal() | currency }}
|
||||
%td.actions
|
||||
|
||||
Reference in New Issue
Block a user