'use strict';

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

CostCenterListCtrl.resolve = {
    costCenters: ['CostCenter', function (CostCenter) {
        return CostCenter.query({}).$promise;
    }]
};

var CostCenterCtrl = ['$scope', '$routeParams', '$location', 'costCenter', function ($scope, $routeParams, $location, costCenter) {
    $scope.costCenter = costCenter;

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

    $scope.delete = function () {
        $scope.costCenter.$delete(function (u, putResponseHeaders) {
            $scope.toasts.push({Type: 'Success', Message: ''});
            $location.path('/CostCenters')
        }, function (data, status) {
            $scope.toasts.push({Type: 'Danger', Message: data.data});
        });
    };
    $('#txtName').focus();
}];

CostCenterCtrl.resolve = {
    costCenter: ['$route', 'CostCenter', function ($route, CostCenter) {
        var id = $route.current.params.id;
        return CostCenter.get({id: id}).$promise;
    }]
};
