(function () { "use strict"; var streamApp = angular.module('streamApp'); streamApp.directive('sharingSuggestionDirective', ['sharingService', 'groupsService', '$location', SharingSuggestionDirective]); function SharingSuggestionDirective(sharingService, groupsService, $location) { return { restrict: 'E', scope: { showSuggestions: '@', suggestions: '=' }, templateUrl: '/App/Directives/sharingSuggestionDirective/sharingSuggestionDirective.html?v=6.0.0c', link: function (scope, element, attrs, tabsCtrl) { scope.view = function () { scope.showSuggestions = !scope.showSuggestions; }; scope.loadSuggestions = function () { groupsService.getGroupsEditable().then(function (data) { var tags = sortName(data.data.activeTags); sharingService.getSuggestions().then(function (data) { scope.suggestions = data; if (scope.suggestions && scope.suggestions.length) { scope.suggestions.forEach((suggestion, i) => { suggestion.tags = tags.map(x => deepCopy(x)); }); } }); }); }; scope.loadSuggestions(); scope.ignoreSuggestion = function (suggestion) { var index = scope.suggestions.findIndex(x => x.Id === suggestion.Id); scope.suggestions.splice(index, 1); sharingService.ignoreSuggestion(suggestion.Id); }; scope.request = function (suggestion) { suggestion.requested = true; }; scope.addTag = function (tag, suggestion) { // do nothing }; scope.cancelRequest = function (suggestion) { suggestion.requested = false; }; scope.send = function (suggestion) { $('.upload').show(); var groupIds = suggestion.tags.filter(x => x.selected).map(x => x.tagId); sharingService.addSuggestion(suggestion.Id, groupIds).then(function (data) { suggestion.message = data.message; suggestion.finished = true; $('.upload').hide(); }).catch(() => $('.upload').hide()); }; } }; } }());