"use strict"; angular.module("vocabulary") .service("premadeNavigationService", ["lessonTypeService", "$q", "premadeApi", "categoryApi", "messageHandler", "accessRestriction", "FeatureCheck", function(lessonTypeService, $q, premadeApi, categoryApi, messageHandler, accessRestriction, FeatureCheck){ var selectedPremadeCategory = { 'parentCategoryId': null, 'subCategoryId': null, 'parentCategoryName': null, 'subCategoryName' : null, 'disclaimer': "" }; var razReadingLevelFilters = []; var currentRazReadingLevel = null; var selectedPremadeLessonId = null; var premadeCategoriesTree = []; var scienceDisplayNames = {}; var razDisplayNames = {}; var basalCategoryDisplayNames = {}; var basalDisclaimers = {}; var RAZ_CATEGORY_ID = 3; var RAZ_NON_LEVELED_BOOK_IDS = [1081, 2199, 2089]; var RAZ_VOCAB_CATEGORY_ID = 1081; var RAZ_MATH_CATEGORY_ID = 2199; var RAZ_SHARED_READING_CATEGORY_ID = 1584; var RAZ_GRAPHIC_BOOK_CATEGORY_ID = 3437; var ELL_CATEGORY_ID = 1639; var RAZ_ELL_POWER_PACK_CATEGORY_ID = 2752; var RAZ_ELL_VOCAB_BOOK_CATEGORY_ID = 2089; var SAZ_CATEGORY_ID = 416; var BASAL_CATEGORY_IDS = [781, 1453, 964, 6022, 17442, 27702, 27940 ]; function initService(){ if(!FeatureCheck.isFeatureEnabled('VAZ_TOPIC_LESSON_NAMES')){ initalizeNamesFromClient(); } if(!FeatureCheck.isFeatureEnabled('VAZ_TOPIC_DESCRIPTIONS')){ initializeDisclaimersFromClient(); } } function initializeDisclaimersFromClient(){ basalDisclaimers = { // Macmillan Treasures 1453 : ' Please be advised that Vocabulary A-Z only uses the actual vocabulary words contained in Macmillan\'s texts. These words exist in our database, which selects the order that the words appear on the screen. Macmillan Treasures® is a registered trademark of Macmillan/McGraw Hill. Vocabulary A-Z is not affiliated, endorsed, connected or sponsored in any way by Macmillan/McGraw Hill.', // Scott Foresman Reading Street 964 : ' Please be advised that Vocabulary A-Z only uses the actual vocabulary words contained in Scott Foresman\'s texts. These words are in our database, which selects the order that the words appear on the screen. Reading Street® is a registered trademark of Scott Foresman. Vocabulary A-Z is not affiliated, endorsed, connected, or sponsored in any way by Scott Foresman.', // McGraw Hill Wonders 2014 17442 : 'Please be advised that Vocabulary A-Z only uses the actual vocabulary words contained in McGraw Hill texts. These words exist in our database, which selects the order that the words appear on the screen. Wonders® is a registered trademark of McGraw Hill. Vocabulary A-Z is not affiliated, endorsed, connected or sponsored in any way by McGraw Hill.', // McGraw Hill Wonders 2017 27702 : 'Please be advised that Vocabulary A-Z only uses the actual vocabulary words contained in McGraw Hill texts. These words exist in our database, which selects the order that the words appear on the screen. Wonders® is a registered trademark of McGraw Hill. Vocabulary A-Z is not affiliated, endorsed, connected or sponsored in any way by McGraw Hill.', // Houghton Mifflin Harcourt Trophies 781 : 'Please be advised that Vocabulary A-Z only uses the actual vocabulary words contained in Houghton Mifflin Harcourt\'s texts. These words exist in our database, which selects the order that the words appear on the screen. Harcourt Trophies® is a registered trademark of Houghton Mifflin Harcourt. Vocabulary A-Z is not affiliated, endorsed, connected or sponsored in any way by Houghton Mifflin Harcourt.', // Houghton Mifflin Harcourt Journeys 6022 : 'Please be advised that Vocabulary A-Z only uses the actual vocabulary words contained in Houghton Mifflin Harcourt\'s texts. These words exist in our database, which selects the order that the words appear on the screen. Journeys® is a registered trademark of Houghton Mifflin Harcourt. Vocabulary A-Z is not affiliated, endorsed, connected or sponsored in any way by Houghton Mifflin Harcourt.', // Houghton Mifflin Harcourt Journeys 27940 : 'Please be advised that Vocabulary A-Z only uses the actual vocabulary words contained in Houghton Mifflin Harcourt\'s texts. These words exist in our database, which selects the order that the words appear on the screen. Journeys® is a registered trademark of Houghton Mifflin Harcourt. Vocabulary A-Z is not affiliated, endorsed, connected or sponsored in any way by Houghton Mifflin Harcourt.' }; } function initalizeNamesFromClient(){ scienceDisplayNames = { 417 : 'Earth & Space', 425 : 'Physical', 421 : 'Life', 429: 'Process' }; razDisplayNames = { 0 : 'Leveled Books', 2199 : 'Math Books', 1081: 'Vocabulary Books', 1307: 'Fiction Series', 1308: 'Nonfiction Series', 1584: 'Shared Reading', 3437: 'Graphic Books' }; basalCategoryDisplayNames = { 781 : 'Harcourt Trophies 2005', 1453 : 'Macmillan Treasures 2007', 964 : 'Scott Foresman Reading Street Pre-2012', 6022 : 'Houghton Mifflin Harcourt Journeys 2011/2012' }; } function getPremadeCategoryTree(){ if(premadeCategoriesTree.length === 0) { return categoryApi.getPremadeCategoryTree().then(function (categoryTree) { if (categoryTree.length === 0) { messageHandler.publishError("There was a problem processing your request"); } premadeCategoriesTree = categoryTree; if(!FeatureCheck.isFeatureEnabled('VAZ_TOPIC_LESSON_NAMES')) { setCategoryNavigationDisplayNames(); } return premadeCategoriesTree; }).catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }); } else{ return $q.resolve(premadeCategoriesTree); } } function getRazReadingLevels(){ if(razReadingLevelFilters.length === 0) { return premadeApi.premadeRazReadingLevels().then(function (levels) { razReadingLevelFilters = levels; return razReadingLevelFilters; }).catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }) } else{ return $q.resolve(razReadingLevelFilters); } } function getRazFictionSeriesCategories(){ return premadeApi.premadeRazFictionSeriesCategories().then(function (levels) { return levels; }).catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }) } function getRazNonFictionSeriesCategories(){ return premadeApi.premadeRazNonFictionSeriesCategories().then(function (levels) { return levels; }).catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }) } function setSelectedPremadeLessonId(lessonId){ selectedPremadeLessonId = lessonId; } function getSelectedPremadeLessonId(){ return selectedPremadeLessonId; } function getCurrentRazReadingLevel() { return currentRazReadingLevel; } function setCurrentRazReadingLevel(razReadingLevel) { currentRazReadingLevel = razReadingLevel; } function setCurrentRazReadingLevelByID(razReadingLevelID) { getRazReadingLevels().then(function (levels) { currentRazReadingLevel = levels.find(function (level) { return level.levelId === razReadingLevelID; }); }); } function isRazSelectedCategory(){ return selectedPremadeCategory['parentCategoryId'] == RAZ_CATEGORY_ID; } function isRazLeveledBooksSelectedCategory(){ return isRazSelectedCategory() && !isRazNonLeveledBookSelectedCategory(); } function isRazVocabSelectedCategory(){ return isRazSelectedCategory() && selectedPremadeCategory['subCategoryId'] == RAZ_VOCAB_CATEGORY_ID; } function isRazMathSelectedCategory(){ return isRazSelectedCategory() && selectedPremadeCategory['subCategoryId'] == RAZ_MATH_CATEGORY_ID; } function isRazNonLeveledBookSelectedCategory(){ return RAZ_NON_LEVELED_BOOK_IDS.indexOf(parseInt(selectedPremadeCategory['subCategoryId'])) >= 0; } function isRazEllSelectedCategory(){ return selectedPremadeCategory['parentCategoryId'] == ELL_CATEGORY_ID; } function isRazEllLanguagePackSelectedCategory(){ return isRazEllSelectedCategory() && !isRazEllVocabBookSelectedCategory() && !isRazEllPowerPackSelectedCategory(); } function isRazEllPowerPackSelectedCategory(){ return isRazEllSelectedCategory() && selectedPremadeCategory['subCategoryId'] == RAZ_ELL_POWER_PACK_CATEGORY_ID; } function isRazGraphicSelectedCategory(){ return isRazSelectedCategory() && selectedPremadeCategory['subCategoryId'] == RAZ_GRAPHIC_BOOK_CATEGORY_ID; } function isRazSharedReadingSelectedCategory(){ return isRazSelectedCategory() && selectedPremadeCategory['subCategoryId'] == RAZ_SHARED_READING_CATEGORY_ID; } function isRazEllVocabBookSelectedCategory(){ return isRazEllSelectedCategory() && selectedPremadeCategory['subCategoryId'] == RAZ_ELL_VOCAB_BOOK_CATEGORY_ID; } function isSazSelectedCategory(){ return selectedPremadeCategory['parentCategoryId'] == SAZ_CATEGORY_ID; } function isBasalSelectedCategory(){ return !(isRazSelectedCategory() || isRazEllSelectedCategory() || isSazSelectedCategory()); } // todo - this belongs in a service. I don't think premadeService is the proper location function getLessonTypeBasedOnSelectedCategory() { if(isBasalSelectedCategory()) { return lessonTypeService.OTHER_PREMADE; } else if(isSazSelectedCategory()) { return lessonTypeService.SAZ_PREMADE; } else if(isRazSelectedCategory() || isRazEllSelectedCategory()) { return lessonTypeService.RAZ_PREMADE; } } function isTeacherAuthorized() { return accessRestriction.getTeacherAuthData() .then(doTeacherAuthCheck); } function doTeacherAuthCheck(teacherAuthorization){ if (isBasalSelectedCategory()) { return true; } else if (isSazSelectedCategory()) { return teacherAuthorization['has_saz_license']; } else if (isRazMathSelectedCategory() || isRazVocabSelectedCategory() || isRazGraphicSelectedCategory() || isRazSharedReadingSelectedCategory()) { return teacherAuthorization['has_raz_license']; } else if (isRazLeveledBooksSelectedCategory()) { return teacherAuthorization['has_raz_license'] || teacherAuthorization['has_rk_license']; } else if (isRazEllSelectedCategory()) { return teacherAuthorization['has_raz_ell_license']; } } function getAssignmentAreaNameForReading(){ return accessRestriction.getTeacherAuthData() .then(getAssignmentAreaName); } function getAssignmentAreaName(teacherAuthorization) { if (isRazSelectedCategory() && teacherAuthorization['has_rk_sub'] && teacherAuthorization['has_rk_license']){ return "Reading"; } else { return "Vocabulary"; } } function getRequiredSubscriptionName(){ return selectedPremadeCategory.parentCategoryName; } function setSelectedPremadeCategory(parent, sub){ if(FeatureCheck.isFeatureEnabled('VAZ_PREMADE_NAV_REDESIGN')){ // this wonky stuff causes getParentCategoryName() and getSubCategoryName() to do what we want in the case of reading series var temp = premadeCategoriesTree; var readingSeries = getReadingSeries(); if(readingSeries) { var readingSeriesSubcategories = readingSeries.subcategories; var readingSeriesSubcategoryIds = readingSeriesSubcategories.map(function (subcategory) { return subcategory.categoryId; }); if (readingSeriesSubcategoryIds.indexOf(parseInt(parent)) > -1) { premadeCategoriesTree = readingSeriesSubcategories; } } } selectedPremadeCategory.parentCategoryId = parent; selectedPremadeCategory.subCategoryId = sub; selectedPremadeCategory.parentCategoryName = getParentCategoryName(parent); selectedPremadeCategory.subCategoryName = getSubCategoryName(parent,sub); if(!FeatureCheck.isFeatureEnabled('VAZ_TOPIC_DESCRIPTIONS')) { selectedPremadeCategory.disclaimer = getDisclaimer(parent); } if(FeatureCheck.isFeatureEnabled('VAZ_PREMADE_NAV_REDESIGN')){ premadeCategoriesTree = temp; } } function getReadingSeries() { return pluckReadingSeries(premadeCategoriesTree); } function pluckReadingSeries(categories) { return categories.filter(function (category) { return category.categoryName == "Reading Series"; // todo - name match is awful, consider alternatives }).pop(); } function getSelectedPremadeCategory(){ return selectedPremadeCategory; } function getDisclaimer(parent){ var disclaimer = ""; if( BASAL_CATEGORY_IDS.indexOf(parseInt(parent)) >= 0){ disclaimer = basalDisclaimers[parseInt(parent)]; if(disclaimer === undefined){ disclaimer = ""; } } return disclaimer; } function getParentCategoryName(parent) { var categoryName = ""; for (var i = 0; i < premadeCategoriesTree.length; i++) { if(premadeCategoriesTree[i]['categoryId'] == parent){ categoryName = premadeCategoriesTree[i]['categoryName']; break; } } return categoryName; } function getSubCategoryName(parent,sub){ var subCategoryName = ""; for(var i = 0; i < premadeCategoriesTree.length; i++){ if(premadeCategoriesTree[i]['categoryId'] == parent) { var subcategories = premadeCategoriesTree[i]['subcategories']; for (var j = 0; j < subcategories.length; j++) { if (subcategories[j]['categoryId'] == sub) { subCategoryName = subcategories[j]['categoryName']; break; } } } if (subCategoryName.length > 0){ break; } } return subCategoryName } function setCategoryNavigationDisplayNames(){ for (var i = 0; i < premadeCategoriesTree.length; i++) { var currentCategory = premadeCategoriesTree[i]; var currentSubCategory = null; var subCatName = null; if (currentCategory['categoryId'] === SAZ_CATEGORY_ID) { currentCategory['categoryName'] = 'Science A-Z'; for (var j = 0; j < currentCategory['subcategories'].length; j++) { currentSubCategory = currentCategory['subcategories'][j]; currentSubCategory['categoryName'] = scienceDisplayNames[parseInt(currentSubCategory['categoryId'])]; currentSubCategory['parentCategoryName'] = currentCategory['categoryName']; currentCategory.subcategories[j] = currentSubCategory; } premadeCategoriesTree[i] = currentCategory; } else if(currentCategory['categoryId'] === RAZ_CATEGORY_ID){ for(var k = 0; k < currentCategory['subcategories'].length; k++){ currentSubCategory = currentCategory['subcategories'][k]; subCatName = currentSubCategory['categoryName']; currentSubCategory['categoryName'] = razDisplayNames[parseInt(currentSubCategory['categoryId'])]; currentSubCategory['parentCategoryName'] = currentCategory['categoryName']; currentCategory.subcategories[k] = currentSubCategory; } premadeCategoriesTree[i] = currentCategory; } else if(BASAL_CATEGORY_IDS.indexOf(parseInt(currentCategory['categoryId'])) >= 0){ if(basalCategoryDisplayNames[parseInt(currentCategory['categoryId'])]){ currentCategory['categoryName'] = basalCategoryDisplayNames[parseInt(currentCategory['categoryId'])]; } premadeCategoriesTree[i] = currentCategory; } } } return{ initService: initService, getPremadeCategoryTree: getPremadeCategoryTree, getRazReadingLevels: getRazReadingLevels, getRazFictionSeriesCategories: getRazFictionSeriesCategories, getRazNonFictionSeriesCategories: getRazNonFictionSeriesCategories, getReadingSeries: getReadingSeries, setSelectedPremadeCategory:setSelectedPremadeCategory, getSelectedPremadeCategory: getSelectedPremadeCategory, setSelectedPremadeLessonId: setSelectedPremadeLessonId, getSelectedPremadeLessonId: getSelectedPremadeLessonId, getCurrentRazReadingLevel: getCurrentRazReadingLevel, setCurrentRazReadingLevel: setCurrentRazReadingLevel, setCurrentRazReadingLevelByID: setCurrentRazReadingLevelByID, isTeacherAuthorized: isTeacherAuthorized, getRequiredSubscriptionName: getRequiredSubscriptionName, getAssignmentAreaNameForReading: getAssignmentAreaNameForReading, getLessonTypeBasedOnSelectedCategory: getLessonTypeBasedOnSelectedCategory, isRazSelectedCategory: isRazSelectedCategory, isRazLeveledBooksSelectedCategory: isRazLeveledBooksSelectedCategory, isRazVocabSelectedCategory: isRazVocabSelectedCategory, isRazMathSelectedCategory: isRazMathSelectedCategory, isRazNonLeveledBookSelectedCategory: isRazNonLeveledBookSelectedCategory, isRazEllSelectedCategory: isRazEllSelectedCategory, isRazEllVocabBookSelectedCategory: isRazEllVocabBookSelectedCategory, isRazEllLanguagePackSelectedCategory: isRazEllLanguagePackSelectedCategory, isRazEllPowerPackSelectedCategory: isRazEllPowerPackSelectedCategory, isRazGraphicSelectedCategory: isRazGraphicSelectedCategory, isRazSharedReadingSelectedCategory: isRazSharedReadingSelectedCategory, isSazSelectedCategory: isSazSelectedCategory, isBasalSelectedCategory: isBasalSelectedCategory, }; }]);