'use strict';

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

FoodTableListCtrl.resolve = {
    food_tables: ['FoodTable', function (FoodTable) {
        return FoodTable.query({}).$promise;
    }]
};

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

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

FoodTableCtrl.resolve = {
    food_table: ['$route', 'FoodTable', function ($route, FoodTable) {
        var id = $route.current.params.id;
        return FoodTable.get({id: id}).$promise;
    }]
};
