65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
angular
|
|
.module('overlord')
|
|
.controller('AccountController', AccountController);
|
|
|
|
AccountController.$inject = ['$scope', '$location', '$uibModal', 'account', 'accountTypes', 'costCentres'];
|
|
function AccountController($scope, $location, $modal, account, accountTypes, costCentres) {
|
|
$scope.account = account;
|
|
|
|
$scope.accountTypes = accountTypes;
|
|
$scope.costCentres = costCentres;
|
|
|
|
$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', '$uibModalInstance', 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();
|
|
});
|
|
};
|
|
$scope.foName = true;
|
|
};
|
|
|
|
AccountController.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;
|
|
}],
|
|
costCentres: ['CostCentre', function (CostCentre) {
|
|
return CostCentre.query({}).$promise;
|
|
}]
|
|
};
|