app.controller('modalController', function ($scope, $modalInstance, items) {
   
    $scope.items = items;
    $scope.selected = {
        item: $scope.items
    };

    $scope.itemCopy = {};

    angular.copy($scope.items, $scope.itemCopy);
    
    $scope.ok = function () {
        
        $modalInstance.close($scope.selected.item);
    };

    $scope.cancel = function (v) {
        angular.copy($scope.itemCopy, $scope.items);
        if (v!=null)
            $modalInstance.dismiss(v);
        else
            $modalInstance.dismiss('cancel');
    };

    $scope.fechaRetornaDados = function (dados) {
        
        $modalInstance.close(dados);
    };

    $scope.validaDadosFecha = function (validaCallback,args) {
        var valido = validaCallback.apply(this, args); //validaCallback();
        if (!valido)
            return false;

        $modalInstance.close($scope.selected.item);
        return true;
    };



});