Feature: Keyboard navigation in Accounts, Employees and Product List. Chore: Removing unused JavasScript variables in function for JSHint
138 lines
4.6 KiB
JavaScript
138 lines
4.6 KiB
JavaScript
'use strict';
|
|
|
|
var AccountListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'accounts', function ($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': 'CostCenter', 'Comparator': 'text'}
|
|
},
|
|
def: 'n',
|
|
sorter: {
|
|
'n': 'Name',
|
|
't': 'Type',
|
|
'a': 'IsActive',
|
|
'r': 'IsReconcilable',
|
|
'c': 'CostCenter'
|
|
}
|
|
};
|
|
$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();
|
|
}
|
|
}
|
|
};
|
|
}];
|
|
AccountListCtrl.resolve = {
|
|
accounts: ['Account', function (Account) {
|
|
return Account.query({}).$promise;
|
|
}]
|
|
};
|
|
|
|
var AccountCtrl = ['$scope', '$location', '$modal', 'account', 'accountTypes', 'costCenters', function ($scope, $location, $modal, account, accountTypes, costCenters) {
|
|
$scope.account = account;
|
|
|
|
$scope.accountTypes = accountTypes;
|
|
$scope.costCenters = costCenters;
|
|
|
|
$scope.save = function () {
|
|
$scope.account.$save(function () {
|
|
$scope.toasts.push({Type: 'Success', Message: ''});
|
|
$location.path('/Accounts');
|
|
}, function (data) {
|
|
$scope.toasts.push({Type: 'Danger', Message: data.data});
|
|
});
|
|
};
|
|
|
|
$scope.delete = function () {
|
|
$scope.account.$delete(function () {
|
|
$scope.toasts.push({Type: 'Success', Message: ''});
|
|
$location.path('/Accounts');
|
|
}, function (data) {
|
|
$scope.toasts.push({Type: 'Danger', Message: data.data});
|
|
});
|
|
};
|
|
|
|
$scope.confirm = function () {
|
|
var modalInstance = $modal.open({
|
|
backdrop: true,
|
|
templateUrl: '/template/modal/confirm.html',
|
|
controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
|
|
$scope.title = "Delete Account";
|
|
$scope.body = "Are you sure? This cannot be undone.";
|
|
$scope.isDelete = true;
|
|
$scope.ok = function () {
|
|
$modalInstance.close();
|
|
};
|
|
$scope.cancel = function () {
|
|
$modalInstance.dismiss('cancel');
|
|
};
|
|
}]
|
|
});
|
|
modalInstance.result.then(function () {
|
|
$scope.delete();
|
|
});
|
|
};
|
|
$('#txtName').focus();
|
|
}];
|
|
|
|
AccountCtrl.resolve = {
|
|
account: ['$route', 'Account', function ($route, Account) {
|
|
var id = $route.current.params.id;
|
|
return Account.get({id: id}).$promise;
|
|
}],
|
|
accountTypes: ['AccountType', function (AccountType) {
|
|
return AccountType.query({}).$promise;
|
|
}],
|
|
costCenters: ['CostCenter', function (CostCenter) {
|
|
return CostCenter.query({}).$promise;
|
|
}]
|
|
};
|