'use strict';

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

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

var ProductGroupCtrl = ['$scope', '$location', 'product_group', function ($scope, $location, product_group) {
    $scope.product_group = product_group;

    $scope.save = function () {
        $scope.product_group.$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.product_group.$delete(function (u, putResponseHeaders) {
            $scope.toasts.push({Type: 'Success', Message: ''});
            $location.path('/ProductGroups')
        }, function (data, status) {
            $scope.toasts.push({Type: 'Danger', Message: data.data});
        });
    };
    $('#txtName').focus();
}];

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