(function () { 'use strict'; angular .module('app') .controller('CareProviderProfileLicenseController', CareProviderProfileLicenseController); function CareProviderProfileLicenseController($scope, $state, careProviderRepository, errorHandler, uiNotifications, $translate, localizationHelper) { /* jshint validthis:true */ var vm = this; vm.translationObject = {}; vm.loadTranslation = function(){ $translate(['Info', 'Success', 'Error', 'CareProviderLicenseActivated', 'CareProviderLicenseDeactivated', 'CareProviderLicenseDeactivatedByAdmin']).then(function (tr) { vm.translationObject = tr; }); }; vm.unsubscribe = localizationHelper.eventEmitter.subscribe('onLanguageChangedEvent', function (lang) { vm.loadTranslation(); }); vm.loadTranslation(); // Variables. vm.currentProfileId = $state.params.id; vm.isLoaded = false; vm.response = null; // Methods. vm.updateLicense = function(action){ var informType = action == "activate" ? 'info' : 'success' ; var method = action + "License"; careProviderRepository[method](vm.currentProfileId, {text:vm.translationObject['CareProviderLicenseDeactivatedByAdmin']}).success(function(response, status, headers, config){ if (errorHandler.check(response, status, config) == errorHandler.STATUS.SUCCESS) { var message = action == "activate" ? vm.translationObject['CareProviderLicenseActivated'] : vm.translationObject['CareProviderLicenseDeactivated']; uiNotifications.inform(message, informType); $state.reload(); } else if (response && !response.success) { uiNotifications.popup(response.message); } }); }; // Main. careProviderRepository.getById(vm.currentProfileId).success(function(response, status, headers, config){ if (errorHandler.check(response, status, config) == errorHandler.STATUS.SUCCESS) { vm.response = response.data; vm.isLoaded = true; } }); $scope.$on("$destroy", function(){ vm.unsubscribe(); }); window.CARE_PROVIDER_LICENSES = vm; } // IoC container. CareProviderProfileLicenseController.$inject = [ "$scope", '$state', "repository.careProvider", "appUtils.errorHandler", "appUtils.uiNotifications", '$translate', "helpers.localization" ]; })();