(function() { "use strict"; angular.module('shared') .component('standards', { templateUrl: '/shared/js/angular/file-cabinet/standards.html', controller: 'StandardsCtrl', bindings: { folder: '<' } }) .controller('StandardsCtrl', ['folderService', '$scope', 'messageHandler', 'standardsService', 'FeatureCheck','currentSubFolders','folders', function StateStandardsCtrl(folderService, $scope, messageHandler, standardsService, FeatureCheck,currentSubFolders,folders) { var ctrl = this; ctrl.isCustomStandardEnabled = FeatureCheck.isFeatureEnabled('FILE_CABINET_CUSTOM_STANDARDS') && !currentSubFolders.getAreFoldersForEveryone(); ctrl.$onInit = function() { folderService.registerOnFolderUpdated($scope, updateFolder); if (ctrl.isCustomStandardEnabled) { standardsService.registerOnCustomStandardsUpdate($scope, updateCustomStandards); } }; ctrl.showNotReadyForProd = function(data) { return currentSubFolders.getAreFoldersForEveryone() && folders.getIsLiteracyEditor() && data['ready_for_prod'] && data['ready_for_prod'] == 'n'; }; ctrl.$onChanges = function() { if (ctrl.folder && parseInt(ctrl.folder.id) > 0) { if (!ctrl.folder.standards) { getStandardsForFolder(); getLastStrand(); } else { standardsService.setFolderStandards(ctrl.folder.standards); standardsService.setLastStrand(ctrl.folder.lastStrand); } if (ctrl.isCustomStandardEnabled) { getCustomStandardsForFolder().then(function() { standardsService.setFolderCustomStandards(ctrl.folder.customStandards); }) } } }; ctrl.hasStandards = function() { if (ctrl.isCustomStandardEnabled) { return ctrl.folder && ((ctrl.folder.standards && ctrl.folder.standards.length > 0) || (ctrl.folder.customStandards && ctrl.folder.customStandards.length > 0)); } return ctrl.folder && (ctrl.folder.standards && ctrl.folder.standards.length > 0); }; function updateFolder() { getStandardsForFolder(); getLastStrand(); if (ctrl.isCustomStandardEnabled) { getCustomStandardsForFolder().then(function() { standardsService.setFolderCustomStandards(ctrl.folder.customStandards); }) } } function updateCustomStandards() { getCustomStandardsForFolder(); } function getStandardsForFolder() { folderService.getStandardsForFolder(ctrl.folder.id,currentSubFolders.getAreFoldersForEveryone()).then( function(response) { ctrl.folder.standards = response.data; standardsService.setFolderStandards(ctrl.folder.standards); }, function(reason) { console.debug(reason); messageHandler.publishError("There was a problem getting the list of standards for this folder."); } ); } function getCustomStandardsForFolder() { return folderService.getCustomStandardsForFolder(ctrl.folder.id,currentSubFolders.getAreFoldersForEveryone()).then( function(response) { ctrl.folder.customStandards = response.data; }, function(reason) { console.debug(reason); messageHandler.publishError("There was a problem getting the list of custom standards for this folder."); } ) } function getLastStrand() { folderService.getLastStrand(ctrl.folder.id).then( function(response) { ctrl.folder.lastStrand = response.data; standardsService.setLastStrand(ctrl.folder.lastStrand); }, function(reason) { console.debug(reason); messageHandler.publishError("There was a problem processing your request."); } ) } } ]); }());