
app.controller("importarFotosController", function ($scope, $upload) {

        $scope.processoConcluido = false;
        $scope.uploadprogress = 0;
        $scope.files = [];
        $scope.resultados = [];
        $scope.emExecucao = false;

        $scope.preparadoEnviar = $scope.files.length > 0;

        $scope.droped = function () {
            $scope.emExecucao = true;
        }

        $scope.onFileSelect = function ($files, $event) {
            $scope.emExecucao = true;
            $scope.resultados = [];
            $scope.processoConcluido = false;
            $scope.files = $files;

            $scope.preparadoEnviar = $scope.files.length > 0;
            $scope.emExecucao = false;
        };

        $scope.iniciarValores = function () {
            $scope.uploadprogress = 0;
            $scope.files = [];

            $scope.preparadoEnviar = $scope.files.length > 0;
        };

        $scope.processar = function () {
            $scope.processoConcluido = false;
            $scope.emExecucao = true;
            $scope.resultados = [];

            $scope.upload = $upload.upload({
                url: '../api/importarImagensInv',
                //data: {myObj: $scope.myModelObj},
                file: $scope.files
            }).progress(function (evt) {
                
                $scope.uploadprogress = parseInt(100.0 * evt.loaded / evt.total);
                
            }).success(function (data, status, headers, config) {
                //console.log('file ' + config.file.name + 'is uploaded successfully. Response: ' + data);
                console.log(data);
                $scope.resultados = data;
                $scope.emExecucao = false;
                $scope.processoConcluido = true;
                $scope.iniciarValores();
            }).error(function (data, status, headers, config) {
                $scope.processoConcluido = true;
                $scope.iniciarValores();
                $scope.emExecucao = false;
            });
        };
    });