/**
* @ngdoc controllers
* @name Categoria
* @module s4c.components.admin.controllers.Categorias
*
* @description
* `CategoriaCtrl` Controller da tela de Categoria do módulo de administração
*
*
*/
(function () {
'use strict';
function CategoriaCtrl($scope, $stateParams, $mdDialog, $state, Acervo, Categoria, $rootScope, Base) {
$scope.res = $rootScope.res;
var id = parseInt($stateParams.id, 10);
Acervo.query()
.$promise
.then(function (acervos) {
$scope.acervos = acervos;
});
Base.obter('categoriaCluster').then(function (result) {
$scope.clusters = result;
});
Categoria.get({ id: id })
.$promise
.then(function (categoria) {
$scope.categoria = categoria;
Base.obter('representacoes').then(function (reps) {
$scope.representacoes = reps;
_.each($scope.representacoes, function (rep) {
if (rep.id == $scope.categoria.representacaoId) {
$scope.representacaoSelecionada = rep.id;
}
});
});
});
$scope.representacaoSelecionada;
/**
* @method selecionarRepresentacao
* @param {*} representacaoSelecionada
*/
function selecionarRepresentacao(representacaoSelecionada) {
$scope.categoria.representacaoId = representacaoSelecionada;
$scope.representacaoSelecionada = representacaoSelecionada;
}
/**
* @method salvarCategoria
*/
function salvarCategoria() {
if ($scope.categoria.monitorar == null) {
$scope.categoria.monitorar = false;
}
$scope.categoria
.$save()
.then(function () {
$state.go('admin.camadas');
});
}
/**
* @method excluirCategoria
*/
function excluirCategoria() {
var confirm = $mdDialog.confirm()
.title($scope.res('PERGUNTA_DELETAR_CATEGORIA'))
.content($scope.res('COMUM_MENSAGEM_ACAOIRREVERSIVEL'))
.ok($scope.res('COMUM_SIM'))
.cancel($scope.res('COMUM_CANCELAR'));
$mdDialog.show(confirm)
.then(function () {
$scope.categoria
.$delete()
.then(function () {
$state.go('admin.camadas');
});
});
}
angular.extend($scope, {
salvarCategoria: salvarCategoria,
excluirCategoria: excluirCategoria,
selecionarRepresentacao: selecionarRepresentacao,
representacoes: $scope.representacoes
});
}
angular.module('s4c.controllers.CategoriaCtrl', [
'ngMaterial',
's4c.services.Acervo',
's4c.services.Categoria'
])
.controller('CategoriaCtrl', CategoriaCtrl);
CategoriaCtrl.$inject = ['$scope', '$stateParams', '$mdDialog', '$state', 'Acervo', 'Categoria', '$rootScope', 'Base'];
}());