Files
openfoodnetwork/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee
Maikel Linke ad1ef877c0 Warn about duplicate customer codes
The admin customer page displays a warning you change a code to an
existing one.
2016-06-10 09:09:56 +10:00

37 lines
1.2 KiB
CoffeeScript

angular.module("admin.customers").controller "customersCtrl", ($scope, $q, Customers, TagRuleResource, CurrentShop, RequestMonitor, Columns, pendingChanges, shops) ->
$scope.shops = shops
$scope.CurrentShop = CurrentShop
$scope.RequestMonitor = RequestMonitor
$scope.submitAll = pendingChanges.submitAll
$scope.add = Customers.add
$scope.deleteCustomer = Customers.remove
$scope.customerLimit = 20
$scope.columns = Columns.columns
$scope.$watch "CurrentShop.shop", ->
if $scope.CurrentShop.shop.id?
Customers.index({enterprise_id: $scope.CurrentShop.shop.id}).then (data) ->
$scope.customers = data
$scope.checkForDuplicateCodes = ->
customers = $scope.findByCode(this.customer.code)
if (customers.length > 1)
this.duplicate = true
else
this.duplicate = false
$scope.findByCode = (code) ->
if $scope.customers
$scope.customers.filter (customer) ->
customer.code == code
$scope.findTags = (query) ->
defer = $q.defer()
params =
enterprise_id: $scope.CurrentShop.shop.id
TagRuleResource.mapByTag params, (data) =>
filtered = data.filter (tag) ->
tag.text.toLowerCase().indexOf(query.toLowerCase()) != -1
defer.resolve filtered
defer.promise