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.
156 lines
3.7 KiB
156 lines
3.7 KiB
evoapp.controller('DocumentsController', function($rootScope, $scope, $timeout, $compile, $injector, $filter, globals)
|
|
{
|
|
$scope.globals = globals;
|
|
|
|
$scope.globals = globals;
|
|
|
|
$scope.showList = true;
|
|
$scope.showEdit = false;
|
|
|
|
var documentos = [
|
|
{
|
|
id: 1,
|
|
nome: 'documento 1'
|
|
},
|
|
{
|
|
id: 2,
|
|
nome: 'documento 2'
|
|
},
|
|
{
|
|
id: 3,
|
|
nome: 'documento 3'
|
|
},
|
|
{
|
|
id: 4,
|
|
nome: 'documento 4'
|
|
},
|
|
{
|
|
id: 5,
|
|
nome: 'documento 5'
|
|
},
|
|
{
|
|
id: 6,
|
|
nome: 'documento 6'
|
|
}
|
|
];
|
|
|
|
$scope.storeDocuments = new globals.dataService.store({
|
|
model: null,
|
|
serviceBase: window.evoapp.DOCPATH,
|
|
actions: {
|
|
get: 'documentosList',
|
|
upsert: 'documento',
|
|
destroy: 'removerDocumento'
|
|
}
|
|
});
|
|
|
|
$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.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.save = function(){
|
|
|
|
var isValid = $scope.editForm.$isValid();
|
|
|
|
if(isValid)
|
|
{
|
|
//TODO: store upsert
|
|
$scope.uploadDocument();
|
|
$scope.list();
|
|
}
|
|
};
|
|
|
|
$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 + "documentos/getDocumento?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.$on('afterrender', function(event, args){
|
|
});
|
|
});
|