Source: components/admin/controllers/editar_grupo.controller.js

/**
 * @ngdoc controllers
 * @name editarGrupo
 * @module s4c.components.admin.controllers.editarGrupo
 *
 * @description
 * `GrupoCtrl` Controller da tela de Grupos do módulo de administração
 * 
 * 
 */
(function () {
    'use strict';

    function GrupoCtrl($scope, $stateParams, $mdDialog, $state, Acervo, Grupo, $rootScope) {

        var id = parseInt($stateParams.id, 10);
        $scope.res = $rootScope.res;

        Grupo.get({ id: id })
            .$promise
            .then(function (grupo) {
                $scope.grupo = grupo;
            });

        /**
         * @method salvarGrupo
         */
        function salvarGrupo() {
            console.log('Salvando grupo: ', $scope.grupo);
            var confirm = $mdDialog.confirm()
                .title($scope.res('PERGUNTA_SALVAR_GRUPO'))
                .content($scope.res('MENSAGEM_MUDANCAS_IRREVERSIVEIS'))
                .ariaLabel($scope.res('COMUM_SALVAR_GRUPO'))
                .ok($scope.res('COMUM_SIM'))
                .cancel($scope.res('COMUM_CANCELAR'));

            $mdDialog.show(confirm)
                .then(function () {
                    $scope.grupo
                        .$save()
                        .then(function () {
                            console.log('ok');
                        });
                }, function () {
                    console.log('cancel');
                });
        }

        /**
         * @method excluirGrupo
         */
        function excluirGrupo() {
            var confirm = $mdDialog.confirm()
                .title($scope.res('PERGUNTA_DELETAR_GRUPO'))
                .content($scope.res('COMUM_MENSAGEM_ACAOIRREVERSIVEL'))
                .ariaLabel($scope.res('COMUM_DELETAR_GRUPO'))
                .ok($scope.res('COMUM_SIM'))
                .cancel($scope.res('COMUM_CANCELAR'));

            $mdDialog.show(confirm)
                .then(function () {
                    $scope.grupo
                        .$delete()
                        .then(function () {
                            $state.go('admin.camadas');
                        });
                }, function () {
                    console.log('cancel');
                });
        }

        angular.extend($scope, {
            salvarGrupo: salvarGrupo,
            excluirGrupo: excluirGrupo
        });
    }

    angular.module('s4c.controllers.GrupoCtrl', [
        'ngMaterial',
        's4c.services.Acervo',
        's4c.services.Grupo'
    ])
        .controller('GrupoCtrl', GrupoCtrl);

    GrupoCtrl.$inject = ['$scope', '$stateParams', '$mdDialog', '$state', 'Acervo', 'Grupo', '$rootScope'];
}());