'use strict';

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

GroupListCtrl.resolve = {
    groups: ['Group', function (Group) {
        return Group.query({}).$promise;
    }]
};

var GroupCtrl = ['$scope', '$location', 'group', function ($scope, $location, group) {
    $scope.group = group;

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

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

GroupCtrl.resolve = {
    group: ['$route', 'Group', function ($route, Group) {
        var id = $route.current.params.id;
        return Group.get({id: id}).$promise;
    }]
};
