(function () { 'use strict'; var streamApp = angular.module('streamApp'); streamApp.directive('albumDirective', ['albumsService', 'timelineService', AlbumDirective]); function AlbumDirective(albumsService, timelineService) { return { restrict: 'E', transclude: true, scope: { momentId: '=', hasAlbum: '=', }, templateUrl: '/App/Directives/albumDirective/albumDirective.html?v=6.0.0c', link: function (scope, element, attrs, tabsCtrl) { scope.requested = false; scope.errors = ['You can only remove a memory from a timeline if you added it to the timeline.']; function refreshAlbums(momentId) { albumsService.getAlbumsForMoment(momentId) .then(albums => { scope.albums = albums; scope.requestedAlbums = true; }); } scope.viewAlbums = function (momentId) { scope.viewMomentAlbums = !scope.viewMomentAlbums; if (scope.viewMomentAlbums) { scope.viewMomentTimelines = false; refreshAlbums(momentId); } }; scope.addAlbum = function (album) { if (album.selected) { albumsService.addMoment(album.albumId, scope.momentId); } else { albumsService.removeMoment(album.albumId, scope.momentId); } scope.hasAlbum = scope.albums.some(x => x.selected); }; function refreshTimelines(momentId) { timelineService.getTimelineForMoment(momentId) .then(timeines => { scope.timelines = timeines; scope.requestedTimelines = true; }); } scope.viewTimelines = function (momentId) { scope.viewMomentTimelines = !scope.viewMomentTimelines; if (scope.viewMomentTimelines) { scope.viewMomentAlbums = false; refreshTimelines(momentId); } }; scope.addTimeline = function (timeline) { if (timeline.selected) { timelineService.addDropToTimeline(timeline.id, scope.momentId) .catch(() => timeline.selected = false); } else { timelineService.removeDropFromTimeline(timeline.id, scope.momentId) .catch(() => { timeline.selected = true; scope.hasError = true; }); } }; } }; }; })();