Replace references to 'standing order' with 'subscription' (JS)

This commit is contained in:
Rob Harrington
2018-02-02 16:25:42 +11:00
parent 672f96b85b
commit b3eaa30f3d
19 changed files with 101 additions and 101 deletions

View File

@@ -40,7 +40,7 @@
//= require ./resources/resources
//= require ./shipping_methods/shipping_methods
//= require ./side_menu/side_menu
//= require ./standing_orders/standing_orders
//= require ./subscriptions/subscriptions
//= require ./tag_rules/tag_rules
//= require ./taxons/taxons
//= require ./utils/utils

View File

@@ -1,26 +1,26 @@
angular.module("admin.standingOrders").controller "AddressController", ($scope, $filter, StatusMessage, availableCountries) ->
angular.module("admin.subscriptions").controller "AddressController", ($scope, $filter, StatusMessage, availableCountries) ->
$scope.countries = availableCountries
$scope.statesFor = (country_id) ->
return [] unless country_id
$filter('filter')(availableCountries, {id: country_id})[0].states
$scope.billStates = $scope.statesFor($scope.standingOrder.bill_address.country_id)
$scope.shipStates = $scope.statesFor($scope.standingOrder.ship_address.country_id)
$scope.billStates = $scope.statesFor($scope.subscription.bill_address.country_id)
$scope.shipStates = $scope.statesFor($scope.subscription.ship_address.country_id)
$scope.registerNextCallback 'address', ->
$scope.standing_order_form.$submitted = true
if $scope.standing_order_address_form.$valid
$scope.standing_order_form.$setPristine()
$scope.subscription_form.$submitted = true
if $scope.subscription_address_form.$valid
$scope.subscription_form.$setPristine()
StatusMessage.clear()
$scope.setView('products')
else
StatusMessage.display 'failure', t('admin.standing_orders.details.invalid_error')
StatusMessage.display 'failure', t('admin.subscriptions.details.invalid_error')
$scope.registerBackCallback 'address', ->
StatusMessage.clear()
$scope.setView('details')
$scope.$watch 'standingOrder.bill_address.country_id', (newValue, oldValue) ->
$scope.$watch 'subscription.bill_address.country_id', (newValue, oldValue) ->
$scope.billStates = $scope.statesFor(newValue) if newValue?
$scope.$watch 'standingOrder.ship_address.country_id', (newValue, oldValue) ->
$scope.$watch 'subscription.ship_address.country_id', (newValue, oldValue) ->
$scope.shipStates = $scope.statesFor(newValue) if newValue?

View File

@@ -1,21 +1,21 @@
angular.module("admin.standingOrders").controller "DetailsController", ($scope, $http, CreditCardResource, StatusMessage) ->
angular.module("admin.subscriptions").controller "DetailsController", ($scope, $http, CreditCardResource, StatusMessage) ->
$scope.cardRequired = false
$scope.registerNextCallback 'details', ->
$scope.standing_order_form.$submitted = true
if $scope.standing_order_details_form.$valid
$scope.standing_order_form.$setPristine()
$scope.subscription_form.$submitted = true
if $scope.subscription_details_form.$valid
$scope.subscription_form.$setPristine()
StatusMessage.clear()
$scope.setView('address')
else
StatusMessage.display 'failure', t('admin.standing_orders.details.invalid_error')
StatusMessage.display 'failure', t('admin.subscriptions.details.invalid_error')
$scope.$watch "standingOrder.customer_id", (newValue, oldValue) ->
$scope.$watch "subscription.customer_id", (newValue, oldValue) ->
return if !newValue?
$scope.loadAddresses(newValue) unless $scope.standingOrder.id?
$scope.loadAddresses(newValue) unless $scope.subscription.id?
$scope.loadCreditCards(newValue)
$scope.$watch "standingOrder.payment_method_id", (newValue, oldValue) ->
$scope.$watch "subscription.payment_method_id", (newValue, oldValue) ->
return if !newValue?
paymentMethod = ($scope.paymentMethods.filter (pm) -> pm.id == newValue)[0]
return unless paymentMethod?
@@ -23,15 +23,15 @@ angular.module("admin.standingOrders").controller "DetailsController", ($scope,
$scope.cardRequired = true
else
$scope.cardRequired = false
$scope.standingOrder.credit_card_id = null
$scope.subscription.credit_card_id = null
$scope.loadAddresses = (customer_id) ->
$http.get("/admin/customers/#{customer_id}/addresses")
.success (response) =>
delete response.bill_address.id
delete response.ship_address.id
angular.extend($scope.standingOrder.bill_address, response.bill_address)
angular.extend($scope.standingOrder.ship_address, response.ship_address)
angular.extend($scope.subscription.bill_address, response.bill_address)
angular.extend($scope.subscription.ship_address, response.ship_address)
$scope.shipAddressFromBilling() unless response.ship_address.address1?
$scope.loadCreditCards = (customer_id) ->

View File

@@ -1,4 +1,4 @@
angular.module("admin.standingOrders").controller "OrderUpdateIssuesController", ($scope, OrderCycles) ->
angular.module("admin.subscriptions").controller "OrderUpdateIssuesController", ($scope, OrderCycles) ->
$scope.proxyOrders = $scope.options.proxyOrders
$scope.orderCycleName = (id) ->

View File

@@ -1,13 +1,13 @@
angular.module("admin.standingOrders").controller "OrdersPanelController", ($scope, OrderCycles) ->
$scope.standingOrder = $scope.object
angular.module("admin.subscriptions").controller "OrdersPanelController", ($scope, OrderCycles) ->
$scope.subscription = $scope.object
$scope.cancelOrder = (order) ->
if confirm(t('are_you_sure'))
$scope.standingOrder.cancelOrder(order)
$scope.subscription.cancelOrder(order)
$scope.resumeOrder = (order) ->
if confirm(t('are_you_sure'))
$scope.standingOrder.resumeOrder(order)
$scope.subscription.resumeOrder(order)
$scope.orderCycleName = (id) ->
OrderCycles.byID[id].name

View File

@@ -1,8 +1,8 @@
angular.module("admin.standingOrders").controller "ProductsController", ($scope, StatusMessage) ->
angular.module("admin.subscriptions").controller "ProductsController", ($scope, StatusMessage) ->
$scope.registerNextCallback 'products', ->
$scope.standing_order_form.$submitted = true
if $scope.standingOrder.standing_line_items.length > 0
$scope.standing_order_form.$setPristine()
$scope.subscription_form.$submitted = true
if $scope.subscription.standing_line_items.length > 0
$scope.subscription_form.$setPristine()
StatusMessage.clear()
$scope.setView('review')
else

View File

@@ -1,17 +1,17 @@
angular.module("admin.standingOrders").controller "ProductsPanelController", ($scope, StandingOrders, StatusMessage) ->
$scope.standingOrder = $scope.object
$scope.distributor_id = $scope.standingOrder.shop_id
angular.module("admin.subscriptions").controller "ProductsPanelController", ($scope, Subscriptions, StatusMessage) ->
$scope.subscription = $scope.object
$scope.distributor_id = $scope.subscription.shop_id
$scope.saving = false
$scope.saved = ->
pristine = StandingOrders.pristineByID[$scope.standingOrder.id].standing_line_items
return false unless angular.equals($scope.standingOrder.standing_line_items, pristine)
pristine = Subscriptions.pristineByID[$scope.subscription.id].standing_line_items
return false unless angular.equals($scope.subscription.standing_line_items, pristine)
true
$scope.save = ->
$scope.saving = true
StatusMessage.display 'progress', 'Saving...'
$scope.standingOrder.update().then (response) ->
$scope.subscription.update().then (response) ->
$scope.saving = false
StatusMessage.display 'success', 'Saved'
, (response) ->

View File

@@ -1,4 +1,4 @@
angular.module("admin.standingOrders").controller "StandingLineItemsController", ($scope, InfoDialog) ->
angular.module("admin.subscriptions").controller "StandingLineItemsController", ($scope, InfoDialog) ->
$scope.newItem = { variant_id: 0, quantity: 1 }
$scope.addStandingLineItem = ->
@@ -8,23 +8,23 @@ angular.module("admin.standingOrders").controller "StandingLineItemsController",
angular.extend(match, $scope.newItem)
delete match._destroy
else
InfoDialog.open 'error', t('admin.standing_orders.product_already_in_order')
InfoDialog.open 'error', t('admin.subscriptions.product_already_in_order')
else
$scope.standing_order_form.$setDirty()
$scope.standingOrder.buildItem($scope.newItem)
$scope.subscription_form.$setDirty()
$scope.subscription.buildItem($scope.newItem)
$scope.removeStandingLineItem = (item) ->
$scope.standing_order_form.$setDirty()
$scope.standingOrder.removeItem(item)
$scope.subscription_form.$setDirty()
$scope.subscription.removeItem(item)
$scope.match = ->
matching = $scope.standingOrder.standing_line_items.filter (sli) ->
matching = $scope.subscription.standing_line_items.filter (sli) ->
sli.variant_id == $scope.newItem.variant_id
return matching[0] if matching.length > 0
null
$scope.estimatedSubtotal = ->
$scope.standingOrder.standing_line_items.reduce (subtotal, item) ->
$scope.subscription.standing_line_items.reduce (subtotal, item) ->
return subtotal if item._destroy
subtotal += item.price_estimate * item.quantity
, 0

View File

@@ -1,27 +1,27 @@
angular.module("admin.standingOrders").controller "StandingOrderController", ($scope, StandingOrder, StandingOrderForm, customers, schedules, paymentMethods, shippingMethods) ->
$scope.standingOrder = new StandingOrder()
angular.module("admin.subscriptions").controller "SubscriptionController", ($scope, Subscription, SubscriptionForm, customers, schedules, paymentMethods, shippingMethods) ->
$scope.subscription = new Subscription()
$scope.errors = null
$scope.save = null
$scope.customers = customers
$scope.schedules = schedules
$scope.paymentMethods = paymentMethods
$scope.shippingMethods = shippingMethods
$scope.distributor_id = $scope.standingOrder.shop_id # variant selector requires distributor_id
$scope.view = if $scope.standingOrder.id? then 'review' else 'details'
$scope.distributor_id = $scope.subscription.shop_id # variant selector requires distributor_id
$scope.view = if $scope.subscription.id? then 'review' else 'details'
$scope.nextCallbacks = {}
$scope.backCallbacks = {}
$scope.creditCards = []
$scope.setView = (view) -> $scope.view = view
$scope.stepTitleFor = (step) -> t("admin.standing_orders.steps.#{step}")
$scope.stepTitleFor = (step) -> t("admin.subscriptions.steps.#{step}")
$scope.registerNextCallback = (view, callback) => $scope.nextCallbacks[view] = callback
$scope.registerBackCallback = (view, callback) => $scope.backCallbacks[view] = callback
$scope.next = -> $scope.nextCallbacks[$scope.view]()
$scope.back = -> $scope.backCallbacks[$scope.view]()
$scope.shipAddressFromBilling = =>
angular.extend($scope.standingOrder.ship_address, $scope.standingOrder.bill_address)
angular.extend($scope.subscription.ship_address, $scope.subscription.bill_address)
$scope.$watch 'standing_order_form', ->
form = new StandingOrderForm($scope.standing_order_form, $scope.standingOrder)
$scope.$watch 'subscription_form', ->
form = new SubscriptionForm($scope.subscription_form, $scope.subscription)
$scope.errors = form.errors
$scope.save = form.save

View File

@@ -1,4 +1,4 @@
angular.module("admin.standingOrders").controller "StandingOrdersController", ($scope, StandingOrders, Columns, RequestMonitor, shops, ShippingMethods, PaymentMethods) ->
angular.module("admin.subscriptions").controller "SubscriptionsController", ($scope, Subscriptions, Columns, RequestMonitor, shops, ShippingMethods, PaymentMethods) ->
$scope.columns = Columns.columns
$scope.shops = shops
$scope.shop_id = if shops.length == 1 then shops[0].id else null
@@ -9,10 +9,10 @@ angular.module("admin.standingOrders").controller "StandingOrdersController", ($
$scope.$watch "shop_id", ->
if $scope.shop_id?
$scope.standingOrders = StandingOrders.index("q[shop_id_eq]": $scope.shop_id, "q[canceled_at_null]": true)
$scope.subscriptions = Subscriptions.index("q[shop_id_eq]": $scope.shop_id, "q[canceled_at_null]": true)
$scope.itemCount = (standingOrder) ->
standingOrder.standing_line_items.reduce (sum, sli) ->
$scope.itemCount = (subscription) ->
subscription.standing_line_items.reduce (sum, sli) ->
return sum + sli.quantity
, 0

View File

@@ -1,9 +1,9 @@
# Used to display a message before redirecting to a link
angular.module("admin.standingOrders").directive "confirmOrderEdit", (ConfirmDialog, $window) ->
angular.module("admin.subscriptions").directive "confirmOrderEdit", (ConfirmDialog, $window) ->
restrict: "A"
link: (scope, element, attrs) ->
element.bind "click", (event) ->
unless scope.proxyOrder.order_id?
event.preventDefault()
ConfirmDialog.open('error', t('admin.standing_orders.orders.confirm_edit'), {confirm: t('yes_i_am_sure')}).then ->
ConfirmDialog.open('error', t('admin.subscriptions.orders.confirm_edit'), {confirm: t('yes_i_am_sure')}).then ->
$window.open(attrs.href)

View File

@@ -1,4 +1,4 @@
angular.module("admin.standingOrders").directive 'newStandingOrderDialog', ($compile, $window, $templateCache, DialogDefaults, shops) ->
angular.module("admin.subscriptions").directive 'newSubscriptionDialog', ($compile, $window, $templateCache, DialogDefaults, shops) ->
restrict: 'A'
scope: true
link: (scope, element, attr) ->
@@ -6,15 +6,15 @@ angular.module("admin.standingOrders").directive 'newStandingOrderDialog', ($com
scope.shops = shops
scope.shop_id = null
scope.newStandingOrder = ->
scope.new_standing_order_form.$setPristine()
scope.newSubscription = ->
scope.new_subscription_form.$setPristine()
scope.submitted = true
if scope.shop_id?
$window.location.href = "/admin/standing_orders/new?standing_order[shop_id]=#{scope.shop_id}"
$window.location.href = "/admin/subscriptions/new?subscription[shop_id]=#{scope.shop_id}"
return
# Compile modal template
template = $compile($templateCache.get('admin/new_standing_order_dialog.html'))(scope)
template = $compile($templateCache.get('admin/new_subscription_dialog.html'))(scope)
# Set Dialog options
template.dialog(DialogDefaults)
@@ -23,6 +23,6 @@ angular.module("admin.standingOrders").directive 'newStandingOrderDialog', ($com
element.bind 'click', (e) ->
if shops.length == 1
scope.shop_id = shops[0].id
scope.newStandingOrder()
scope.newSubscription()
else
template.dialog('open')

View File

@@ -1,4 +1,4 @@
angular.module("admin.standingOrders").factory 'CreditCardResource', ($resource) ->
angular.module("admin.subscriptions").factory 'CreditCardResource', ($resource) ->
resource = $resource '/admin/customers/:customer_id/cards.json', {},
'index':
method: 'GET'

View File

@@ -1,6 +1,6 @@
angular.module("admin.standingOrders").factory "StandingOrder", ($injector, StandingOrderResource) ->
class StandingOrder extends StandingOrderResource
angular.module("admin.subscriptions").factory "Subscription", ($injector, SubscriptionResource) ->
class Subscription extends SubscriptionResource
constructor: ->
if $injector.has('standingOrder')
angular.extend(@, $injector.get('standingOrder'))
if $injector.has('subscription')
angular.extend(@, $injector.get('subscription'))

View File

@@ -1,26 +1,26 @@
angular.module("admin.standingOrders").factory 'StandingOrderForm', ($window, StatusMessage) ->
class StandingOrderForm
angular.module("admin.subscriptions").factory 'SubscriptionForm', ($window, StatusMessage) ->
class SubscriptionForm
form: null
standingOrder: null
subscription: null
errors: {}
constructor: (form, standingOrder) ->
constructor: (form, subscription) ->
@form = form
@standingOrder = standingOrder
@subscription = subscription
save: =>
return @formInvalid() unless @form.$valid
delete @errors[k] for k, v of @errors
@form.$setPristine()
StatusMessage.display 'progress', 'Saving...'
if @standingOrder.id?
@standingOrder.update().then @successCallback, @errorCallback
if @subscription.id?
@subscription.update().then @successCallback, @errorCallback
else
@standingOrder.create().then @successCallback, @errorCallback
@subscription.create().then @successCallback, @errorCallback
successCallback: (response) =>
StatusMessage.display 'success', 'Saved. Redirecting...'
$window.location.href = "/admin/standing_orders"
$window.location.href = "/admin/subscriptions"
errorCallback: (response) =>
if response.data?.errors?
@@ -32,4 +32,4 @@ angular.module("admin.standingOrders").factory 'StandingOrderForm', ($window, St
# We save the SO, but open a dialog, so want to stay on the page
StatusMessage.display 'success', 'Saved'
formInvalid: -> StatusMessage.display 'failure', t('admin.standing_orders.details.invalid_error')
formInvalid: -> StatusMessage.display 'failure', t('admin.subscriptions.details.invalid_error')

View File

@@ -1,4 +1,4 @@
angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, $injector, $q, InfoDialog, ConfirmDialog) ->
angular.module("admin.subscriptions").factory 'SubscriptionPrototype', ($http, $injector, $q, InfoDialog, ConfirmDialog) ->
buildItem: (item) ->
return false unless item.variant_id > 0
return false unless item.quantity > 0
@@ -13,13 +13,13 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
create: ->
@$save().then (response) =>
$injector.get('StandingOrders').afterCreate(@id) if $injector.has('StandingOrders')
$injector.get('Subscriptions').afterCreate(@id) if $injector.has('Subscriptions')
$q.resolve(response)
, (response) => $q.reject(response)
update: ->
@$update().then (response) =>
$injector.get('StandingOrders').afterUpdate(@id) if $injector.has('StandingOrders')
$injector.get('Subscriptions').afterUpdate(@id) if $injector.has('Subscriptions')
orders_with_issues = @not_closed_proxy_orders.filter((po) -> po.update_issues.length > 0)
if orders_with_issues.length > 0
InfoDialog.open('error', null, 'admin/order_update_issues_dialog.html', { proxyOrders: orders_with_issues})
@@ -28,32 +28,32 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
, (response) => $q.reject(response)
cancel: ->
ConfirmDialog.open('error', t('admin.standing_orders.confirm_cancel_msg'), {cancel: t('back'), confirm: t('admin.standing_orders.yes_i_am_sure')})
ConfirmDialog.open('error', t('admin.subscriptions.confirm_cancel_msg'), {cancel: t('back'), confirm: t('admin.subscriptions.yes_i_am_sure')})
.then =>
@$cancel().then angular.noop, (response) =>
if response.data?.errors?.open_orders?
options = {cancel: t('admin.standing_orders.no_keep_them'), confirm: t('admin.standing_orders.yes_cancel_them')}
options = {cancel: t('admin.subscriptions.no_keep_them'), confirm: t('admin.subscriptions.yes_cancel_them')}
ConfirmDialog.open('error', response.data.errors.open_orders, options)
.then (=> @$cancel(open_orders: 'cancel')), (=> @$cancel(open_orders: 'keep'))
else
InfoDialog.open 'error', t('admin.standing_orders.cancel_failure_msg')
InfoDialog.open 'error', t('admin.subscriptions.cancel_failure_msg')
pause: ->
ConfirmDialog.open('error', t('admin.standing_orders.confirm_pause_msg'), {confirm: t('admin.standing_orders.yes_i_am_sure')})
ConfirmDialog.open('error', t('admin.subscriptions.confirm_pause_msg'), {confirm: t('admin.subscriptions.yes_i_am_sure')})
.then =>
@$pause().then angular.noop, (response) =>
if response.data?.errors?.open_orders?
options = {cancel: t('admin.standing_orders.no_keep_them'), confirm: t('admin.standing_orders.yes_cancel_them')}
options = {cancel: t('admin.subscriptions.no_keep_them'), confirm: t('admin.subscriptions.yes_cancel_them')}
ConfirmDialog.open('error', response.data.errors.open_orders, options)
.then (=> @$pause(open_orders: 'cancel')), (=> @$pause(open_orders: 'keep'))
else
InfoDialog.open 'error', t('admin.standing_orders.pause_failure_msg')
InfoDialog.open 'error', t('admin.subscriptions.pause_failure_msg')
unpause: ->
ConfirmDialog.open('error', t('admin.standing_orders.confirm_unpause_msg'), {confirm: t('admin.standing_orders.yes_i_am_sure')})
ConfirmDialog.open('error', t('admin.subscriptions.confirm_unpause_msg'), {confirm: t('admin.subscriptions.yes_i_am_sure')})
.then =>
@$unpause().then angular.noop, ->
InfoDialog.open 'error', t('admin.standing_orders.unpause_failure_msg')
InfoDialog.open 'error', t('admin.subscriptions.unpause_failure_msg')
cancelOrder: (order) ->
if order.id?

View File

@@ -1,5 +1,5 @@
angular.module("admin.standingOrders").factory 'StandingOrderResource', ($resource, StandingOrderPrototype) ->
resource = $resource('/admin/standing_orders/:id/:action.json', {}, {
angular.module("admin.subscriptions").factory 'SubscriptionResource', ($resource, SubscriptionPrototype) ->
resource = $resource('/admin/subscriptions/:id/:action.json', {}, {
'index':
method: 'GET'
isArray: true
@@ -26,6 +26,6 @@ angular.module("admin.standingOrders").factory 'StandingOrderResource', ($resour
action: 'unpause'
})
angular.extend(resource.prototype, StandingOrderPrototype)
angular.extend(resource.prototype, SubscriptionPrototype)
resource

View File

@@ -1,17 +1,17 @@
angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOrderResource, StandingOrder, RequestMonitor) ->
new class StandingOrders
angular.module("admin.subscriptions").factory 'Subscriptions', ($q, SubscriptionResource, Subscription, RequestMonitor) ->
new class Subscriptions
byID: {}
pristineByID: {}
index: (params={}, callback=null) ->
request = StandingOrderResource.index params, (data) => @load(data)
request = SubscriptionResource.index params, (data) => @load(data)
RequestMonitor.load(request.$promise)
request
load: (standingOrders) ->
for standingOrder in standingOrders
@byID[standingOrder.id] = standingOrder
@pristineByID[standingOrder.id] = angular.copy(standingOrder)
load: (subscriptions) ->
for subscription in subscriptions
@byID[subscription.id] = subscription
@pristineByID[subscription.id] = angular.copy(subscription)
afterCreate: (id) ->
return unless @byID[id]?

View File

@@ -1 +1 @@
angular.module("admin.standingOrders", ['ngResource','admin.indexUtils','admin.dropdown'])
angular.module("admin.subscriptions", ['ngResource','admin.indexUtils','admin.dropdown'])