(function(){ 'use strict'; angular.module('raz') .component('lcmGrade', { templateUrl: '/js/angular/literacy-curriculum-map/routes/grade.html', controller: 'lcmGradeController', bindings: { gradeId: "<" } }) .controller('lcmGradeController', lcmGradeController); lcmGradeController.$inject = ['lcmGradeFolderIds', 'lcmGradeService', 'lazAccordionService']; function lcmGradeController(lcmGradeFolderIds, lcmGradeService, lazAccordionService) { var ctrl = this; ctrl.isPending = false; ctrl.gradeIndex = null; ctrl.gradFolder = null; ctrl.$onInit = function() { handleCookie(); lcmGradeService.setCurrentGradeId(ctrl.gradeId); ctrl.gradeFolderId = lcmGradeFolderIds['grade_' + ctrl.gradeId]['folder_id']; ctrl.gradeIndex = lcmGradeFolderIds['grade_' + ctrl.gradeId]['grade_index']; setGradeFolder(); }; ctrl.isLoading = function() { return ctrl.isPending; }; function handleCookie() { var cookieName = 'lcm_grade'; var cookieValue = clg.commonUtils.getCookie(cookieName); if (cookieValue) { if (cookieValue !== ctrl.gradeId) { clg.commonUtils.deleteCookie(cookieName); lazAccordionService.clearCookies(); } } clg.commonUtils.setCookie(cookieName, ctrl.gradeId, 1); } function setGradeFolder() { ctrl.isPending = true; lcmGradeService.getLCMFolderTreeById(ctrl.gradeFolderId) .then(function(response) { ctrl.gradeFolder = response }) .finally(function() { ctrl.isPending = false; }); } } })();