Files
openfoodnetwork/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee
Rob Harrington 564c1a3650 Improvements to customers page
Create customer from dialog

Limiting the number of products shown as once

Adding SaveBar and StatusMessage
2016-05-25 08:10:20 +10:00

29 lines
1.1 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.setColumns
email: { name: "Email", visible: true }
code: { name: "Code", visible: true }
tags: { name: "Tags", visible: true }
$scope.$watch "CurrentShop.shop", ->
if $scope.CurrentShop.shop.id?
Customers.index({enterprise_id: $scope.CurrentShop.shop.id}).then (data) ->
$scope.customers = data
$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