'use strict';

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

ModifierListCtrl.resolve = {
    modifiers: ['Modifier', function (Modifier) {
        return Modifier.query({}).$promise;
    }]
};

var ModifierCtrl = ['$scope', '$routeParams', '$location', 'modifier', function ($scope, $routeParams, $location, modifier) {
    $scope.item = modifier;

    $scope.selectAll = function () {
        _.forEach($scope.item.Groups, function (item) {
            item.Enabled = $scope.item.AllGroups;
        })
    };
    $scope.selectOne = function () {
        $scope.item.AllGroups = false;
    };
    $scope.save = function () {
        $scope.item.$save(function (u, putResponseHeaders) {
            $scope.$emit('notification',{Type: 'Success', Message: ''});
            $location.path('/Modifiers')
        }, function (data, status) {
            $scope.$emit('notification',{Type: 'Danger', Message: data.data});
        });
    };

    $scope.delete = function () {
        $scope.item.$delete(function (u, putResponseHeaders) {
            $scope.$emit('notification',{Type: 'Success', Message: ''});
            $location.path('/Modifiers')
        }, function (data, status) {
            $scope.$emit('notification',{Type: 'Danger', Message: data.data});
        });
    };
    $('#txtName').focus();
}];

ModifierCtrl.resolve = {
    modifier: ['$route', 'Modifier', function ($route, Modifier) {
        var id = $route.current.params.id;
        return Modifier.get({id: id}).$promise;
    }]
};
