(function(){
'use strict';
angular.module('raz')
.component('lcmBlockResources', {
templateUrl: '/js/angular/literacy-curriculum-map/components/lcm-block-resources.html',
controller: 'LCMBlockResourcesController',
bindings: {
folderId: '<',
folderName: '<',
resources: '<',
blockId: '<',
lessons: '<'
}
})
.controller('LCMBlockResourcesController', LCMBlockResourcesController);
LCMBlockResourcesController.$inject = ['SITE_ID', 'SiteHelper', 'lazAccessRestrictionService', '_', '$sce'];
function LCMBlockResourcesController (SITE_ID, SiteHelper, lazAccessRestrictionService, _, $sce) {
var ctrl = this;
ctrl.BLOCKS = {
SHARED : 1,
READ : 2,
PA : 3,
PHONICS : 4,
GRAMMAR : 5,
WRITING : 6,
SMALL : 7,
CENTERS : 8,
STATIONS : 9
}
ctrl.$onInit = function() {
ctrl.page = '/literacy-curriculum-map/';
ctrl.isRazPlus = parseInt(SITE_ID) === SiteHelper.RAZ_PLUS_SITE_ID;
ctrl.showAssignButton = checkIsAssignable();
if (parseInt(ctrl.blockId) === ctrl.BLOCKS.PHONICS) {
var lessons = [];
_.each(ctrl.lessons, function(element){
var folderName = element['name'];
if (folderName.indexOf('Lesson') > -1) {
lessons.push(element);
}
});
ctrl.lessons = lessons.length > 0 ? lessons : null;
} else {
ctrl.lessons = null;
}
}
ctrl.getResourceName = function(resource) {
var title = resource['title'];
var level = resource['level'];
var category = resource['category'];
var parentCategory = resource['parent_category'];
if (level) {
title += ' - Level ' + level;
}
if (parseInt(ctrl.blockId) !== ctrl.BLOCKS.GRAMMAR) {
if (parseInt(ctrl.blockId) !== ctrl.BLOCKS.PHONICS && parseInt(ctrl.blockId) !== ctrl.BLOCKS.PA) {
if (category && parentCategory && parentCategory.length > 0) {
category += ', ' + parentCategory;
}
}
if (!category && parentCategory) {
category = parentCategory;
}
if (category) {
title += '
' + category + '';
}
}
return title;
}
ctrl.trustAsHtml = function(html) {
return $sce.trustAsHtml(html);
};
ctrl.isAuthorized = function() {
return lazAccessRestrictionService.isAuthorized();
};
ctrl.showResourcesHeading = function() {
if (ctrl.resources) {
for (var i = 0; i < ctrl.resources.length; ++i) {
if (ctrl.resources[i]) {
return true;
}
}
}
if (ctrl.lessons) {
for (var j = 0; j < ctrl.lessons.length; ++j) {
if (ctrl.lessons[j]) {
return true;
}
}
}
return false;
}
function checkIsAssignable() {
var isAssignable = function (resource) {
return resource.is_assignable;
};
return ctrl.isRazPlus && ctrl.isAuthorized() && _.some(ctrl.resources, isAssignable);
}
}
})();