Source: directives/imagem/imagem.js

/**
 * @ngdoc directives
 * @name imagem
 * @module s4c.directives.imagem.imagem
 *
 * @description Componente para controle do módulo de imagens
 *
 *
 */
(function () {
    'use strict';

    imagemController.$inject = [
        '$scope',
        'Preset',
        '$sce',
        'FileService'
    ];

    function imagemController(
        $scope,
        Preset,
        $sce,
        FileService) {

        $scope.res = $scope.$root.res;
        $scope.link;

        var modulos = Preset.obter().PresetModulos;
        $scope.presetId = Preset.obter().id;

        for (var index in modulos) {
            if ((modulos[index].template == 'app/components/modulos/modulo-imagem.html' ||
                (modulos[index].Face && modulos[index].Face.template == 'app/components/modulos/modulo-imagem.html')) && !modulos[index].usado) {

                modulos[index].usado = true;
                $scope.modulo = modulos[index];

                FileService.downloadFile(modulos[index].Face.extras[0].fileId).then(function (data) {

                    var file = new Blob([data], { type: 'application/octet-stream' });
                    var fileURL = URL.createObjectURL(file);
                    $scope.link = $sce.trustAsResourceUrl(fileURL);

                });

                break;
            }
        }

        angular.extend($scope, {
        });
    }

    function s4cImagem() {
        return {
            restrict: 'EA',
            templateUrl: 'app/directives/imagem/imagem.html',
            scope: {},
            controller: imagemController
        };
    }

    angular.module('s4c.components.imagem', [])
        .directive('s4cImagem', s4cImagem);
})();