(function(){ 'use strict'; angular.module('raz') .component('lcmUnit', { templateUrl: '/js/angular/literacy-curriculum-map/components/lcm-unit.html', controller: 'LCMUnitController', require: { parentLazAccordion: '^^lazAccordion' }, bindings: { unitFolder: '<', gradeId: '<' } }) .controller('LCMUnitController', LCMUnitController); LCMUnitController.$inject = ['coreSkills', 'lcmObjectiveStandardsService', 'lcmStateSelectorService', 'lcmStandardsCheckboxService', 'lazAccessRestrictionService', '$sce', 'lcmGradeService', 'IS_FOUNDATIONAL_SKILLS', 'lcmGradeFolderIds']; function LCMUnitController(coreSkills, lcmObjectiveStandardsService, lcmStateSelectorService, lcmStandardsCheckboxService, lazAccessRestrictionService, $sce, lcmGradeService, IS_FOUNDATIONAL_SKILLS, lcmGradeFolderIds) { var ctrl = this; ctrl.coreSkillNames = coreSkills.CORE_SKILL_NAMES; ctrl.coreSkillsOrder = coreSkills.CORE_SKILL_ORDER; ctrl.coreSkillsColumnOrder = coreSkills.CORE_SKILL_COLUMN_ORDER; ctrl.isPending = true; ctrl.$onInit = function () { ctrl.page = IS_FOUNDATIONAL_SKILLS ? '/foundational-skills/' : '/literacy-curriculum-map/'; lazAccessRestrictionService.setPageAfterLogin(ctrl.page); }; ctrl.isLoading = function () { return ctrl.isPending; }; ctrl.isFoundationalSkills = function () { return IS_FOUNDATIONAL_SKILLS; }; ctrl.openSequenceStandards = function () { ctrl.isPending = true; if (ctrl.isFoundationalSkills()) { lcmGradeService.getFSSSWeeksTreeById(lcmGradeFolderIds['grade_' + ctrl.gradeId]['folder_id']) .then(function (response) { ctrl.units = response; ctrl.objectivesForSkillInWeekMap = ctrl.units.objectivesForSkillInWeekMap; }) .finally(function () { ctrl.isPending = false; }); } else { lcmGradeService.getLCMSSUnitTree(ctrl.unitFolder) .then(function (response) { ctrl.unit = response; ctrl.unitWeeks = ctrl.unit.unitWeeks; ctrl.coreSkillsFound = ctrl.unit.coreSkillsFound; ctrl.objectivesForSkillInWeekMap = ctrl.unit.objectivesForSkillInWeekMap; setCoreSkillsForUnit(); }) .finally(function () { ctrl.isPending = false; }); } ctrl.currentState = lcmStateSelectorService.getSelectedState(); lcmStateSelectorService.onUpdate(stateSelectorHasChanged); ctrl.showObjectiveStandards = lcmStandardsCheckboxService.getShowStandards(); lcmStandardsCheckboxService.onUpdate(toggleShowStandards); }; ctrl.getWeeklyQuestion = function (question) { if (question) { return question.substring(17); } return ''; }; ctrl.getObjectivesForSkillInWeek = function (week, skillId) { return ctrl.objectivesForSkillInWeekMap[week.id][skillId]; }; ctrl.getObjectiveStandards = function (coreSkillObjectiveMapId) { return lcmObjectiveStandardsService.getObjectiveStandards(coreSkillObjectiveMapId, ctrl.currentState.state_id); }; ctrl.getObjectiveStandardsCodes = function (coreSkillObjectiveMapId) { return lcmObjectiveStandardsService.getObjectiveStandardsCodes(coreSkillObjectiveMapId, ctrl.currentState.state_id); }; ctrl.getObjectiveName = function (objective, skillId) { if (skillId == 'hf_words') { return objective['target_skill_text']; } var name = objective['objective_name']; var target = objective['target_skill_text']; if (target) { name += ': ' + target; } return name; }; ctrl.checkAuthorization = function (event, pageAfterLogin, downloadPath) { if (!lazAccessRestrictionService.isAuthorized()) { event.preventDefault(); event.stopPropagation(); lazAccessRestrictionService.loginIfNotAuthorized(pageAfterLogin, downloadPath); } }; ctrl.isAuthorized = function () { return lazAccessRestrictionService.isAuthorized(); }; ctrl.trustAsHtml = function (html) { return $sce.trustAsHtml(html); }; function stateSelectorHasChanged(newState) { ctrl.currentState = newState; } function toggleShowStandards() { ctrl.showObjectiveStandards = !ctrl.showObjectiveStandards; } function setCoreSkillsForUnit() { ctrl.coreSkills = []; _.each(ctrl.coreSkillsOrder, function (coreSkill) { if (ctrl.coreSkillsFound[coreSkill]) { ctrl.coreSkills.push(coreSkill); } }); } } })();