(function() { "use strict"; angular.module("raz") .component('resourceCollectionLanguage', { templateUrl: '/js/angular/resource-slider/resource-collection-language.html', controller: 'resourceCollectionLanguage' }) .controller('resourceCollectionLanguage', ['$scope', 'languages', 'whatsNewResources', 'resourceCollectionService', 'constantValues', function($scope, languages, whatsNewResources, resourceCollectionService, constantValues) { var ctrl = this; ctrl.$onInit = function() { ctrl.languages = languages; setResourceInfo(whatsNewResources); resourceCollectionService.setInitWhatsNew(ctrl.curLanguageId, whatsNewResources); }; $scope.$watch(function() { return resourceCollectionService.getCurWhatsNewInfo(); }, function(newVal, oldVal, scope) { if (newVal !== oldVal) { setResourceInfo(newVal); } }, true); var getLanguageName = function(id) { for (var i= 0; i <= ctrl.languages.length; ++i) { if (id == ctrl.languages[i].id) { return ctrl.languages[i].name } } return 'English'; }; var constructResourceDescription = function(resource) { return resource.count + " new " + getLanguageName(ctrl.curLanguageId) + " " + pluralizeTitle(resource.count, resource.resourceType) + " added in " + resource.latestUpdatedOn; }; var pluralizeTitle = function(resourceCount, resourceType) { var displayTitle = ''; if (resourceType == constantValues.TYPE_LEVELED_BOOKS) { displayTitle = 'Leveled Book'; } else { displayTitle = 'Close Read Passage'; } if (resourceCount != 1) { displayTitle += 's'; } return displayTitle; }; var setResourceInfo = function(data) { var bookData = data['book']; var nonbookData = data['nonbook']; ctrl.curLanguageId = data['languageId']; ctrl.whatsNewBookInfo = bookData; ctrl.whatsNewBookDescription = constructResourceDescription(ctrl.whatsNewBookInfo); ctrl.whatsNewCloseReadInfo = nonbookData; ctrl.whatsNewCloseReadDescription = constructResourceDescription(ctrl.whatsNewCloseReadInfo); }; }]); })();