forked from Coded/SIPRP
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							139 lines
						
					
					
						
							3.5 KiB
						
					
					
				
			
		
		
	
	
							139 lines
						
					
					
						
							3.5 KiB
						
					
					
				evoapp.controller('DocumentsController', function($rootScope, $scope, $timeout, $compile, $injector, $filter, globals) 
 | 
						|
{
 | 
						|
    $scope.globals = globals;
 | 
						|
 | 
						|
    $scope.showList = true;
 | 
						|
    $scope.showEdit = false; 
 | 
						|
 | 
						|
    $scope.storeDocuments = new globals.dataService.store({
 | 
						|
        model: null,
 | 
						|
        serviceBase: window.evoapp.DOCPATH,
 | 
						|
        actions: {
 | 
						|
            get: 'documentosList',
 | 
						|
            upsert: 'documento',
 | 
						|
            destroy: 'removerDocumento'
 | 
						|
        }
 | 
						|
    });
 | 
						|
    
 | 
						|
    $scope.btnValue = "Cancelar";
 | 
						|
    $scope.isSaved = false;
 | 
						|
 | 
						|
    $scope.list = function(){
 | 
						|
 | 
						|
        $scope.storeDocuments.extraParams = {
 | 
						|
          trabalhadorID: $scope.selectedTrabalhador.trabalhador_id
 | 
						|
        };
 | 
						|
 | 
						|
        $scope.storeDocuments.get( function(response, status, headers, config, items){
 | 
						|
          
 | 
						|
        });
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.add = function(){
 | 
						|
        
 | 
						|
        $scope.editForm.$reset();
 | 
						|
 | 
						|
        $scope.selected = {};
 | 
						|
 | 
						|
        $scope.editing = {
 | 
						|
            nome: ''
 | 
						|
        };
 | 
						|
 | 
						|
        $scope.showList = false;
 | 
						|
        $scope.showEdit = true;
 | 
						|
        
 | 
						|
        $scope.btnValue = "Cancelar";
 | 
						|
        $scope.isSaved = false;
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.edit = function(selected){
 | 
						|
        
 | 
						|
        $scope.editForm.$reset();
 | 
						|
 | 
						|
        $scope.selected = selected;
 | 
						|
 | 
						|
        $scope.editing = angular.copy(selected);
 | 
						|
 | 
						|
        $scope.showList = false;
 | 
						|
        $scope.showEdit = true;
 | 
						|
 | 
						|
        if($scope.fileInputDocument)
 | 
						|
        {
 | 
						|
            $scope.fileInputDocument.reset();
 | 
						|
        }
 | 
						|
        
 | 
						|
        $scope.btnValue = "Cancelar";
 | 
						|
        $scope.isSaved = false;
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.save = function(){
 | 
						|
 | 
						|
        var isValid = $scope.editForm.$isValid();
 | 
						|
 | 
						|
        if(isValid)
 | 
						|
        {
 | 
						|
            $scope.uploadDocument();
 | 
						|
        }
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.destroy = function(){
 | 
						|
 | 
						|
        globals.message.confirm({
 | 
						|
            question: 'Tem a certeza que deseja continuar?',
 | 
						|
            answer: function(result){
 | 
						|
                if(result)
 | 
						|
                {
 | 
						|
                  $scope.storeDocuments.extraParams = {
 | 
						|
                    documentoID: $scope.editing.id
 | 
						|
                  };
 | 
						|
 | 
						|
                  $scope.storeDocuments.destroy( function(response, status, headers, config, items){
 | 
						|
                    $scope.list();
 | 
						|
                  });
 | 
						|
                }
 | 
						|
            }
 | 
						|
        });
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.cancel = function(){
 | 
						|
        
 | 
						|
        if($scope.isNewRecord)
 | 
						|
        {
 | 
						|
            $scope.isNewRecord = false;
 | 
						|
            $scope.list();
 | 
						|
        }
 | 
						|
 | 
						|
        $scope.showList = true;
 | 
						|
        $scope.showEdit = false;
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.download = function(item){
 | 
						|
      window.location.assign( window.evoapp.DOCPATH + "documento?documentoID=" + encodeURIComponent( item.id ) );
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.uploadDocument = function(){
 | 
						|
 | 
						|
        if($scope.fileInputDocument)
 | 
						|
        {
 | 
						|
            $scope.editing.trabalhador_id = $scope.selectedTrabalhador.trabalhador_id;
 | 
						|
            $scope.fileInputDocument.upload($scope.editing, function(result, textStatus, jqXHR){
 | 
						|
                       
 | 
						|
                var data = result.data[0];
 | 
						|
 | 
						|
                //$scope.editing.Picture = data.Picture;
 | 
						|
                //$scope.selected.Picture = data.Picture;
 | 
						|
 | 
						|
                //$scope.userPicture.update($scope.editing);
 | 
						|
                
 | 
						|
                $scope.list();
 | 
						|
                $rootScope.$emit('ondocumentsave');
 | 
						|
                $scope.btnValue = "Voltar";
 | 
						|
                $scope.isSaved = true;
 | 
						|
            });
 | 
						|
        }
 | 
						|
    };
 | 
						|
 | 
						|
    $scope.$on('afterrender', function(event, args){
 | 
						|
    });
 | 
						|
});
 |