Building params for adding new customer in the dialog directive, rather than generic Customers service

This commit is contained in:
Rob Harrington
2016-11-25 15:50:05 +11:00
parent dc2551d881
commit e8ee1dad04
3 changed files with 10 additions and 11 deletions

View File

@@ -12,7 +12,10 @@ angular.module("admin.customers").directive 'newCustomerDialog', ($compile, $tem
scope.submitted = true
scope.errors = []
if scope.new_customer_form.$valid
Customers.add(scope.email).$promise.then (data) ->
params =
enterprise_id: CurrentShop.shop.id
email: scope.email
Customers.add(params).$promise.then (data) ->
if data.id
scope.email = ""
scope.submitted = false

View File

@@ -1,13 +1,10 @@
angular.module("admin.resources").factory "Customers", ($q, InfoDialog, RequestMonitor, CustomerResource, CurrentShop) ->
angular.module("admin.resources").factory "Customers", ($q, InfoDialog, RequestMonitor, CustomerResource) ->
new class Customers
all: []
byID: {}
pristineByID: {}
add: (email) ->
params =
enterprise_id: CurrentShop.shop.id
email: email
add: (params) ->
CustomerResource.create params, (customer) =>
if customer.id
@all.unshift customer