Skip to content

Commit

Permalink
- Cadastro e edição de curso e evento
Browse files Browse the repository at this point in the history
  • Loading branch information
FannyVieira authored and FannyVieira committed Sep 29, 2016
1 parent 33a562f commit 31c167d
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 0 deletions.
45 changes: 45 additions & 0 deletions nutrif-web-refactor/js/controllers/cadastrarEventoCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
angular.module('NutrifApp').controller('cadastrarEventoCtrl', function ($scope, $mdToast, $state,eventoService) {

this.cadastrar = function (evento) {

// Enviar para o serviço de cadastro de Edital.
eventoService.cadastrarEvento(evento)
.success(onSuccessCallback)
.error(onErrorCallback);
}

function onSuccessCallback (data, status) {

$mdToast.show(
$mdToast.simple()
.textContent('Evento cadastrado com sucesso!')
.position('top right')
.action('OK')
.hideDelay(6000)
);

$state.transitionTo('home.listar-eventos');
}

function onErrorCallback (data, status) {
var _message = '';

if (!data) {
_message = 'Ocorreu um erro na comunicação com o servidor, favor chamar o suporte.'
} else {
_message = data.mensagem
}

$mdToast.show(
$mdToast.simple()
.textContent(_message)
.position('top right')
.action('OK')
.hideDelay(6000)
);

$state.transitionTo('home.listar-eventos');
}


});
59 changes: 59 additions & 0 deletions nutrif-web-refactor/js/controllers/editarCursoCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
angular.module('NutrifApp').controller('editarCursoCtrl', function ($scope,
$stateParams, $state, $mdToast, cursoService) {

$scope.atualizar = function (curso) {

cursoService.atualizarCurso(curso)
.success(function (data, status) {

$state.transitionTo('home.listar-cursos', {reload: true});
$mdToast.show(
$mdToast.simple()
.textContent('Curso atualizado com sucesso!')
.position('top right')
.action('OK')
.hideDelay(6000)
);
})
.error(onErrorCallback);
}

function carregamentoInicial() {
var _id = $stateParams.id;

if (_id == 0){
$state.transitionTo('home.listar-cursos', {reload: true});
}

cursoService.getCursoById(_id)
.success(function (data, status) {
$scope.curso = data;
})
.error(onErrorLoadCallback);
}

function onErrorCallback(data, status) {
var _message = '';

if (!data) {
_message = 'Ocorreu um erro na comunicação com o servidor, favor chamar o suporte.'
} else {
_message = data.mensagem
}

$mdToast.show(
$mdToast.simple()
.textContent(_message)
.position('top right')
.action('OK')
.hideDelay(6000)
);
}

function onErrorLoadCallback(data, status) {
onErrorCallback(data, status);
$state.transitionTo('home.listar-cursos', {reload: true});
}

carregamentoInicial();
});
59 changes: 59 additions & 0 deletions nutrif-web-refactor/js/controllers/editarEventoCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
angular.module('NutrifApp').controller('editarEventoCtrl', function ($scope,
$stateParams, $state, $mdToast, eventoService) {

$scope.atualizar = function (evento) {

eventoService.atualizarEvento(evento)
.success(function (data, status) {

$state.transitionTo('home.listar-eventos', {reload: true});
$mdToast.show(
$mdToast.simple()
.textContent('Evento atualizado com sucesso!')
.position('top right')
.action('OK')
.hideDelay(6000)
);
})
.error(onErrorCallback);
}

function carregamentoInicial() {
var _id = $stateParams.id;

if (_id == 0){
$state.transitionTo('home.listar-eventos', {reload: true});
}

eventoService.getEventoById(_id)
.success(function (data, status) {
$scope.evento = data;
})
.error(onErrorLoadCallback);
}

function onErrorCallback(data, status) {
var _message = '';

if (!data) {
_message = 'Ocorreu um erro na comunicação com o servidor, favor chamar o suporte.'
} else {
_message = data.mensagem
}

$mdToast.show(
$mdToast.simple()
.textContent(_message)
.position('top right')
.action('OK')
.hideDelay(6000)
);
}

function onErrorLoadCallback(data, status) {
onErrorCallback(data, status);
$state.transitionTo('home.listar-eventos', {reload: true});
}

carregamentoInicial();
});
31 changes: 31 additions & 0 deletions nutrif-web-refactor/view/manager/admin/editar-curso.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<md-card>
<md-card-header>

<md-card-avatar>
<md-icon class="md-avatar-icon" md-svg-icon="img/icon/create-new-pencil-button.svg"></md-icon>
</md-card-avatar>

<md-card-header-text>
<span class="md-title">Editar informações do Curso</span>
<span class="md-subhead">Clique em salvar para alterar as informações</span>
</md-card-header-text>

<!-- Salvar alterações -->
<md-card-icon-actions>
<md-button class="md-icon-button" aria-label="Salvar alterações" ng-click="atualizar(curso)">
<md-tooltip md-direction="bottom">Salvar Alterações</md-tooltip>
<md-icon md-svg-icon="img/icon/save-button.svg"></md-icon>
</md-button>
</md-card-icon-actions>

</md-card-header>
<md-card-content layout="column">

<!-- Nome -->
<md-input-container class="md-icon-float md-block">
<label>Nome</label>
<input ng-model="curso.nome" type="text">
</md-input-container>

</md-card-content>
</md-card>

0 comments on commit 31c167d

Please sign in to comment.