{"permission": true,
"title": "ALUNO: aDSadaD",
"question": "Deseja ativar este Aluno?",
"usuario": {
"id": "42247",
"usuario": "alunoguten3360",
"role": "student",
"role_formatted": "Aluno",
"nome": "aDSadaD",
"options_roles": [
{
"value": "student",
"title": "Aluno"
},
{
"value": "teacher",
"title": "Professor"
},
{
"value": "coordinator",
"title": "Coordenador"
}
],
"public_password": "kk8744",
"user_type": "student",
"status": 1,
"coordinators": [],
"turmas": [
{
"turma": "Year 4 A",
"value": "131"
}
],
"$$hashKey": "object:393"
},
"id": "42247",
"role": "student",
"status": true,
"new_status": 1,
"message": "Usuário desativado com sucesso."
}
However, when I make a console.log () on the object in question, it does complete what should come in stringify :
"error_message: You have arrived ..."
Here is the method that calls Modal Control:
$scope.editarStatusUsuario = function (size) {
$scope.hideTooltip();
if (isPermission()) {
if(size == 'desativar') {
$scope.statusUsuario = {
permission: isPermission(),
title: this.usuario.role_formatted.toUpperCase() + ': ' + this.usuario.nome,
question: 'Deseja desativar este ' + this.usuario.role_formatted + '?',
usuario: this.usuario,
id: this.usuario.id,
role: this.usuario.role,
status: false,
new_status:2,
message: 'Usuário ativado com sucesso.'
}
} else {
$scope.statusUsuario = {
permission: isPermission(),
title: this.usuario.role_formatted.toUpperCase() + ': ' + this.usuario.nome,
question: 'Deseja ativar este ' + this.usuario.role_formatted + '?',
usuario: this.usuario,
id: this.usuario.id,
role: this.usuario.role,
status: false,
new_status:1,
message:'Usuário desativado com sucesso.',
}
}
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'statusUsuario.html',
controller: 'ModalController',
size: size,
resolve: {
validate: function () {
return 'status-usuario';
},
dados: function () {
return $scope.statusUsuario;
},
statusModal: function () {
return ' modal-open';
}
}
});
modalInstance.result.then(function (selectedItemResult) {
$scope.hideTooltip();
if (selectedItemResult.status == true) {
var indexUser = $filter('FilterData')(selectedItemResult.id, $scope.dataUsuarios, 'id');
if (angular.isDefined($scope.dataUsuarios)) {
$scope.dataUsuarios[indexUser].status = selectedItemResult.new_status;
$scope.classMessages = 'show';
console.log(selectedItemResult);
console.log(JSON.stringify(selectedItemResult, null, ' '));
if (selectedItemResult.result == false) {
$scope.messageError = AlertMessagesService.getMessages([selectedItemResult.message], 'danger', '');
} else {
$scope.messageError = AlertMessagesService.getMessages([selectedItemResult.message], 'success', '');
}
}
} else {
$scope.classMessages = 'show';
$scope.messageError = AlertMessagesService.getMessages(['O status não foi alterado.'], 'danger', '');
loadingOff('');
}
//caso ok, faz...
// $scope.deletedTurma = selectedItem.data_result;
//$log.info(selectedItem)
$scope.blurClassElement = '';
}, function () {
//console.log(cancel);
$scope.blurClassElement = '';
//$log.info('Modal dismissed at: ' + new Date());
});
$scope.blurClassElement = 'is-blured-content';
} else {
$scope.classMessages = 'show';
$scope.messageError = AlertMessagesService.getMessages(['Você não tem permissão para desativar usuários.'],'danger', 'Ocorreu um problema de permissão');
}
And this is the modal control:
.controller("ModalController",
function($scope, $sce, $rootScope, $filter, $uibModalInstance, $uibModal, $log, $timeout, $window, dados, validate, ModalService, AlertMessagesService, statusModal) {
'use strict';
$scope.submitForm = function() {
$scope.statusUsuario = [];
var validateForm = { status:true, messages:null };
if (validate == 'status-usuario') {
validateForm = ValidateFilter.validateForm($scope, validate);
if (validateForm.status == true) {
ModalService.status(dados, validate)
.then(function (rtn) {
if (rtn.status == true) {
loadingOff('Status alterado!');
$scope.statusUsuario = rtn.data;
dados.result = rtn.data;
dados.message = 'OK';
} else {
loadingOff('');
dados.status = false;
dados.message = rtn.error;
}
});
} else {
$scope.messages = validateForm.messages;
}
}
$scope.ok = function() {
$scope.submitForm();
if ($scope.selected.dados.status == true) {
$uibModalInstance.close($scope.selected.dados);
$scope.messageError = null;
} else {
$scope.classMessages = 'show';
$scope.messageError = AlertMessagesService
.getMessages($scope.messages, 'danger', 'Corrija os erros abaixo');
return;
}
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
});