81 lines
2.7 KiB
JavaScript
81 lines
2.7 KiB
JavaScript
angular
|
|
.module('overlord')
|
|
.controller('AccountListController', AccountListController);
|
|
|
|
AccountListController.$inject = ['$scope', '$location', '$routeParams', 'Tokenizer', 'accounts'];
|
|
function AccountListController($scope, $location, $routeParams, Tokenizer, accounts) {
|
|
$scope.search = $routeParams.q || '';
|
|
$scope.info = accounts;
|
|
|
|
$scope.$watch('search', function (value) {
|
|
$scope.filterAccounts(value);
|
|
}, true);
|
|
|
|
$scope.$on('$destroy', function () {
|
|
Tokenizer.doFilter.cache = {};
|
|
});
|
|
|
|
$scope.searchInfo = {
|
|
comparator: {
|
|
'n': {'Col': 'Name', 'Comparator': 'text'},
|
|
't': {'Col': 'Type', 'Comparator': 'text'},
|
|
'a': {'Col': 'IsActive', 'Comparator': 'boolean'},
|
|
'r': {'Col': 'IsReconcilable', 'Comparator': 'boolean'},
|
|
'c': {'Col': 'CostCentre', 'Comparator': 'text'}
|
|
},
|
|
def: 'n',
|
|
sorter: {
|
|
'n': 'Name',
|
|
't': 'Type',
|
|
'a': 'IsActive',
|
|
'r': 'IsReconcilable',
|
|
'c': 'CostCentre'
|
|
}
|
|
};
|
|
$scope.filterAccounts = _.debounce(function (q) {
|
|
if (q !== $scope._search) {
|
|
$scope._search = q;
|
|
if (angular.isUndefined(q) || q === '') {
|
|
$location.path('/Accounts').search('q', null).replace();
|
|
} else {
|
|
$location.path('/Accounts').search({'q': q}).replace();
|
|
}
|
|
$scope.$apply(function () {
|
|
var matches = Tokenizer.parseFilterString(q, $scope.searchInfo);
|
|
$scope.accounts = Tokenizer.doFilter(q, $scope.info, matches);
|
|
|
|
});
|
|
}
|
|
}, 350);
|
|
|
|
$scope.selected = -1;
|
|
$scope.setSelected = function (index) {
|
|
$scope.selected = Math.min(Math.max(0, index), $scope.accounts.length - 1);
|
|
};
|
|
$scope.shortcuts = {
|
|
'up': function (e) {
|
|
if ($scope.selected > 0) {
|
|
$scope.$apply(function () {
|
|
$scope.selected = Math.min(Math.max(0, $scope.selected - 1), $scope.accounts.length - 1);
|
|
});
|
|
$("#" + $scope.selected).scrollintoview();
|
|
e.preventDefault();
|
|
}
|
|
},
|
|
'down': function (e) {
|
|
if ($scope.selected < $scope.accounts.length - 1) {
|
|
$scope.$apply(function () {
|
|
$scope.selected = Math.min(Math.max(0, $scope.selected + 1), $scope.accounts.length - 1);
|
|
});
|
|
$("#" + $scope.selected).scrollintoview();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
AccountListResolver.$inject = ['Account'];
|
|
function AccountListResolver(Account) {
|
|
return Account.query({}).$promise;
|
|
}
|