(function() { 'use strict'; angular.module('shared') .component('resourceActionList', { templateUrl: '/shared/js/angular/non-book/resource-action-list.html', controller: 'ResourceActionListController', bindings: { item: '<', resourceId: '<', languageId: '<', worksheetType: '<', worksheetSubtypeId: '<', type: '@', page: '@', requiredSiteAbbrev: '@?' }, transclude: true }) .controller('ResourceActionListController', ResourceActionListController); ResourceActionListController.$inject = ['lazAccessRestrictionService', '_', 'SubscriptionHelper', 'subscriptionRequiredService', 'SiteHelper', 'SITE_ID']; function ResourceActionListController (lazAccessRestrictionService, _, SubscriptionHelper, subscriptionRequiredService, SiteHelper, SITE_ID) { var ctrl = this; ctrl.isRazOrRazPlus = parseInt(SITE_ID) === SiteHelper.RAZ_SITE_ID || parseInt(SITE_ID) === SiteHelper.RAZ_PLUS_SITE_ID; ctrl.$onInit = function() { lazAccessRestrictionService.setPageAfterLogin(ctrl.page); ctrl.hasRequiredSubscription = ctrl.requiredSiteAbbrev ? SubscriptionHelper.hasSubscription(ctrl.requiredSiteAbbrev) : true; }; ctrl.checkAuthorization = function (event, pageAfterLogin, downloadPath) { if (ctrl.isRazOrRazPlus) { // Raz/Raz-Plus does not use downloadPath, all paths go through pageAfterLogin pageAfterLogin = downloadPath; downloadPath = null; } if (!lazAccessRestrictionService.isAuthorized()) { event.preventDefault(); event.stopPropagation(); lazAccessRestrictionService.loginIfNotAuthorized(pageAfterLogin, downloadPath); } else if(!ctrl.hasRequiredSubscription && ctrl.requiredSiteAbbrev) { event.preventDefault(); event.stopPropagation(); subscriptionRequiredService.show(SiteHelper.siteAbbrevSiteIdMap[ctrl.requiredSiteAbbrev]); } }; ctrl.isAuthorized = function() { return lazAccessRestrictionService.isAuthorized(); }; ctrl.hasAccess = function() { return ctrl.hasRequiredSubscription && ctrl.isAuthorized(); }; ctrl.getHref = function(link) { return lazAccessRestrictionService.isAuthorized() && ctrl.hasRequiredSubscription ? link : '#'; }; } })();