app.controller("novoSimplController", function ($scope, $modal, $rootScope, httpRequestFactory,cadastroFactory, notificationFactory, ngProgress) {

    $scope.lstClassif = [];
    $scope.selectedClassif = null;
    $scope.lstLocais = [];
    $scope.selectedLocal = null;
       

    $scope.carregaClassificacoes = function () {

        var getSuccessCallback = function (data, status) {
            $scope.lstClassif = data;
            
            $scope.carregaLocais();
        };

        var errorCallback = function (data, status, headers, config) {
            notificationFactory.error(data);
        };

        cadastroFactory.getClassificacoes().success(getSuccessCallback).error(errorCallback);
    };
       

    $scope.carregaLocais = function () {
        var getSuccessCallback = function (data, status) {
            $scope.lstLocais = data;
            ngProgress.complete();
            
        };
        
        var errorCallback = function (data, status, headers, config) {
            ngProgress.reset();
        };

        httpRequestFactory.getData('../api/locais/listagem').success(getSuccessCallback).error(errorCallback);
        ngProgress.start();
    };

    $scope.aplicarAlteracoes = function (item) {
        if ($scope.selectedClassif == null) {
            notificationFactory.error("Indique a classificação");
            return;
        }
        if ($scope.selectedLocal == null) {
            notificationFactory.error("Indique o local");
            return;
        }
        if ($scope.selectedClassif.originalObject == null) {
            notificationFactory.error("Indique a classificação");
            return;
        }
        if ($scope.selectedLocal.originalObject == null)
        {
            notificationFactory.error("Indique o local");
            return ;
        }
        
        //console.log($scope.selectedLocal.originalObject);

        item.FkClassificacao = $scope.selectedClassif.originalObject.Pk_ClassificacaoInventario;
        item.FkEntidade = $scope.selectedLocal.originalObject.FkEntidade;
        item.FkEdificio = $scope.selectedLocal.originalObject.FkEdificio;
        item.FkPiso = $scope.selectedLocal.originalObject.FkPiso;
        item.FkSala = $scope.selectedLocal.originalObject.FkSala;
        $scope.$parent.ok();
        
    };


});