'use strict';

var CostCentreListController = ['$scope', 'costCentres', function ($scope, costCentres) {
    $scope.info = costCentres;
}];

CostCentreListController.resolve = {
    costCentres: ['CostCentre', function (CostCentre) {
        return CostCentre.query({}).$promise;
    }]
};

var CostCentreController = ['$scope', '$routeParams', '$location', 'costCentre', function ($scope, $routeParams, $location, costCentre) {
    $scope.costCentre = costCentre;

    $scope.save = function () {
        $scope.costCentre.$save(function (u, putResponseHeaders) {
            $scope.toasts.push({Type: 'Success', Message: ''});
            $location.path('/CostCentres')
        }, function (data, status) {
            $scope.toasts.push({Type: 'Danger', Message: data.data});
        });
    };

    $scope.delete = function () {
        $scope.costCentre.$delete(function (u, putResponseHeaders) {
            $scope.toasts.push({Type: 'Success', Message: ''});
            $location.path('/CostCentres')
        }, function (data, status) {
            $scope.toasts.push({Type: 'Danger', Message: data.data});
        });
    };
    $scope.foName = true;
}];

CostCentreController.resolve = {
    costCentre: ['$route', 'CostCentre', function ($route, CostCentre) {
        var id = $route.current.params.id;
        return CostCentre.get({id: id}).$promise;
    }]
};
