(function () { "use strict"; var streamApp = angular.module('streamApp'); streamApp.directive('promptsDirective', ['userService', 'timelineService', PromptsDirective]); function PromptsDirective(userService, timelineService) { return { restrict: 'E', scope: { callback: '=', cta: '@', ask: '@', timelineId: '=', short: '@', asked: '@', }, templateUrl: '/App/Directives/prompts/promptsDirective/promptsDirective.html?v=6.0.0c', link: function (scope, element, attrs, tabsCtrl) { scope.prompts = { show: false, index: 0, showLeft: false, showRight: true, prompts: [] }; let getPrompts; if (!scope.asked) { getPrompts = scope.ask ? userService.getPromptsAll(!!scope.short) : scope.timelineId ? timelineService.getAvailablePrompts(scope.timelineId) : userService.getPrompts(); } else { getPrompts = userService.getPromptsAllToAnswer(); } getPrompts.then((prompts) => { scope.prompts.prompts = prompts; scope.prompts.show = !!prompts.length; updateArrows(scope.prompts); }); function updateArrows(prompts) { prompts.showLeft = prompts.index ? true : false; prompts.showRight = prompts.index + 1 === prompts.prompts.length ? false : true; } updateArrows(scope.prompts); scope.setIndex = function (index) { if (index < 0 || index >= scope.prompts.prompts.length) return; scope.prompts.index = index; updateArrows(scope.prompts); }; } }; } }());