diff --git a/modules/torrents/client/directives/torrent-file-link.client.directive.js b/modules/torrents/client/directives/torrent-file-link.client.directive.js new file mode 100644 index 00000000..70bf872b --- /dev/null +++ b/modules/torrents/client/directives/torrent-file-link.client.directive.js @@ -0,0 +1,54 @@ +(function () { + 'use strict'; + + angular.module('users') + .directive('torrentFileLink', torrentFileLink); + + torrentFileLink.$inject = ['$compile', '$translate', 'MeanTorrentConfig']; + + function torrentFileLink($compile, $translate, MeanTorrentConfig) { + var appConfig = MeanTorrentConfig.meanTorrentConfig.app; + + var directive = { + restrict: 'A', + link: link + }; + + return directive; + + function link(scope, element, attrs) { + scope.$watch(attrs.torrentFileLink, function (s) { + if (s) { + var torrent = s; + var user = scope.$eval(attrs.torrentUser); + + console.log(user); + + if (user && torrent) { + var link = makeTorrentFileLink(torrent, user); + var title = $translate.instant('COPY_LINK_TO_CLIPBOARD'); + var cls = attrs.infoClass; + var e = angular.element(''); + + if (e) { + e.addClass(cls ? cls : ''); + e.attr('title', title); + + element.html(e); + $compile(element.contents())(scope); + } + } + } + }); + } + + function makeTorrentFileLink(t, u) { + var link = appConfig.domain; + link += '/api/torrents/download'; + link += '/' + t._id; + link += '/' + u.passkey; + + return link; + } + } +}());