"use strict"; angular.module("vocabulary") .service("premadeService", ["$q", "premadeApi", "categoryApi", "messageHandler", "topicService", "lessonTypeService", function ($q, premadeApi, categoryApi, messageHandler, topicService, lessonTypeService){ var razLeveledBookLessonList = []; var razFictionSeriesLessonList = []; var razNonFictionSeriesLessonList = []; function getPremadeTypesWithResourceWords() { return [lessonTypeService.RAZ_PREMADE, lessonTypeService.SAZ_PREMADE, lessonTypeService.TOPIC]; } function getCMSPremadeTypes() { return [lessonTypeService.RAZ_PREMADE]; } function getPremadeCategoryLessonsList(categoryId){ return premadeApi.premadeCategoryLessons(categoryId); } function getPremadeRazLeveledLessonList(){ if(razLeveledBookLessonList.length === 0) { return premadeApi.premadeRazLeveledLessonList().then(function (premadeReadingData) { razLeveledBookLessonList = premadeReadingData; return razLeveledBookLessonList; }).catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }) } else{ return $q.resolve(razLeveledBookLessonList); } } function getPremadeRazFictionSeriesList(){ if(razFictionSeriesLessonList.length === 0) { return premadeApi.premadeRazFictionSeriesList().then(function (premadeSeriesData) { razFictionSeriesLessonList = premadeSeriesData; return razFictionSeriesLessonList; }).catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }) } else{ return $q.resolve(razFictionSeriesLessonList); } } function getPremadeRazNonFictionSeriesList(){ if(razNonFictionSeriesLessonList.length === 0) { return premadeApi.premadeRazNonFictionSeriesList().then(function (premadeSeriesData) { razNonFictionSeriesLessonList = premadeSeriesData; return razNonFictionSeriesLessonList; }).catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }) } else{ return $q.resolve(razNonFictionSeriesLessonList); } } function getPremadeLessonData(lessonId, resourceType){ if(resourceType === lessonTypeService.RAZ_PREMADE){ return premadeApi.premadeRazLessonData(lessonId); } else{ return premadeApi.premadeNonRazLessonData(lessonId); } } function getPremadeResourceSummary(resourceId, resourceType){ if(resourceType === lessonTypeService.RAZ_PREMADE) { return premadeApi.premadeBookSummary(resourceId) .catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }); } else if(resourceType === lessonTypeService.SAZ_PREMADE){ return premadeApi.premadeScienceSummary(resourceId) .catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }); } else{ return $q.resolve([]); } } function getPremadeRazTopicWords(topicId){ return premadeApi.premadeRazLessonTopicWordsByPurpose(topicId) .catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }); } function getPremadeRazLessonListForBookTopic(topicId){ return premadeApi.premadeRazLessonListForBookTopic(topicId) .catch(function(reason){ messageHandler.publishError("There was a problem processing your request"); return []; }); } function getPremadeRazLessonListForTopic(topicId){ return premadeApi.premadeRazLessonListForTopic(topicId) .catch(function (reason) { messageHandler.publishError("There was a problem processing your request"); return []; }); } function getPremadeLessonForRazBook(razBookId) { return premadeApi.getPremadeLessonForRazBook(razBookId); } return{ getPremadeRazLeveledLessonList: getPremadeRazLeveledLessonList, getPremadeLessonData:getPremadeLessonData, getPremadeResourceSummary: getPremadeResourceSummary, getPremadeRazTopicWords: getPremadeRazTopicWords, getPremadeRazFictionSeriesList: getPremadeRazFictionSeriesList, getPremadeRazNonFictionSeriesList: getPremadeRazNonFictionSeriesList, getPremadeRazLessonListForTopic: getPremadeRazLessonListForTopic, getPremadeRazLessonListForBookTopic: getPremadeRazLessonListForBookTopic, getPremadeLessonForRazBook: getPremadeLessonForRazBook, getPremadeCategoryLessonsList: getPremadeCategoryLessonsList, getPremadeTypesWithResourceWords: getPremadeTypesWithResourceWords, getCMSPremadeTypes: getCMSPremadeTypes }; }]);