Source: directives/rdp/rdp.js

/**
 * @ngdoc directives
 * @name RDP
 * @module s4c.directives.rdp.RDP
 *
 * @description
 * `RDP` Controller da funcionalidade de RDP 
 * 
 * 
 */
(function () {
    'use strict';

    rdpController.$inject = [
        '$scope',
        '$timeout',
        'Preset',
        '$q',
        '$sce'
    ];

    function rdpController(
        $scope,
        $timeout,
        Preset,
        $q,
        $sce) {

        $scope.res = $scope.$root.res;
        $scope.link;
        $scope.randomNumber = Math.floor(Math.random() * 1000);

        /**
         * @method updateLink
         * @param {*} link 
         */
        function updateLink(link) {

            if (link.indexOf('http://') == -1 && link.indexOf('https://') == -1) {
                link = 'http://' + link;
            }

            $scope.modulo.extras = { url: link };
            $scope.link = $sce.trustAsResourceUrl(link);
            Preset.salvar();
        }

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

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

                    modulos[index].usado = true;
                    $scope.modulo = modulos[index];
                    modulos[index].index = 2;
                    updateLink(modulos[index].Face.endereco);
                    break;
                }
            }
        }, 300);

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

    function s4cRdp() {
        return {
            restrict: 'EA',
            templateUrl: 'app/directives/rdp/rdp.html',
            scope: {},
            controller: rdpController
        };
    }

    angular.module('s4c.components.rdp', [])
        .directive('s4cRdp', s4cRdp);
})();