'use strict';

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

ProductGroupListController.resolve = {
    productGroups: ['ProductGroup', function (ProductGroup) {
        return ProductGroup.query({}).$promise;
    }]
};

var ProductGroupController = ['$scope', '$location', 'productGroup', function ($scope, $location, productGroup) {
    $scope.productGroup = productGroup;

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

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

ProductGroupController.resolve = {
    productGroup: ['$route', 'ProductGroup', function ($route, ProductGroup) {
        var id = $route.current.params.id;
        return ProductGroup.get({id: id}).$promise;
    }]
};
