(function() { "use strict"; angular.module("raz") .component('resourceCollectionLanguage', { templateUrl: '/js/angular/resource-slider/resource-collection-language.html', controller: 'resourceCollectionLanguage' }) .controller('resourceCollectionLanguage', ['languages', 'whatsNewBookInfo', 'whatsNewCloseReadInfo', 'deliverableService', 'constantValues', function (languages, whatsNewBookInfo, whatsNewCloseReadInfo, deliverableService, constantValues) { var ctrl = this; ctrl.$onInit = function () { ctrl.curLanguageId = 1; //english ctrl.languages = languages; deliverableService.setInitWhatsNew(ctrl.curLanguageId, whatsNewBookInfo, whatsNewCloseReadInfo); ctrl.whatsNewBookInfo = whatsNewBookInfo; ctrl.whatsNewBookCount = whatsNewBookInfo['count']; ctrl.whatsNewBookUpdatedOn = whatsNewBookInfo['latestUpdatedOn']; ctrl.whatsNewBookType = constantValues.TYPE_LEVELED_BOOKS; ctrl.whatsNewCloseReadInfo = whatsNewCloseReadInfo; ctrl.whatsNewCloseReadCount = whatsNewCloseReadInfo['count']; ctrl.whatsNewCloseReadUpdatedOn = whatsNewCloseReadInfo['latestUpdatedOn']; ctrl.whatsNewCloseReadType = constantValues.TYPE_CLOSE_READ_PASSAGES; }; ctrl.openMenu = function () { angular.element("#language-select-nav").toggle(); angular.element("#changeLanguage-" + ctrl.curLanguageId).focus(); }; ctrl.getLanguageName = function (languageId) { for (var i= 0; i <= ctrl.languages.length; ++i) { if (languageId == ctrl.languages[i].id) { return languages[i].name } } return 'English'; }; ctrl.isLanguageActive = function (languageId) { if (ctrl.curLanguageId == languageId) { return ' active'; } else { return ''; } }; ctrl.changeLanguage = function (languageId) { deliverableService.getWhatsNewInfo(languageId) .then(function (data) { ctrl.curLanguageId = languageId; resetResourceInfo(data); }); angular.element(".menu-dropdown-option").removeClass('active'); angular.element('changeLanguage-' + languageId).addClass('active'); angular.element("#current_language").focus(); angular.element('#language-select-nav').hide(); }; ctrl.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 resetResourceInfo = function (data) { var bookData = data['book']; var nonbookData = data['nonbook']; ctrl.whatsNewBookInfo = bookData; ctrl.whatsNewBookCount = bookData.count; ctrl.whatsNewBookUpdatedOn = bookData.latestUpdatedOn; ctrl.whatsNewCloseReadInfo = nonbookData; ctrl.whatsNewCloseReadCount = nonbookData.count; ctrl.whatsNewCloseReadUpdatedOn = nonbookData.latestUpdatedOn; }; }]); })();