(function () { 'use strict'; angular .module('app') .controller('AdminProfileController', adminProfile); function adminProfile($scope, $state, $rootScope, adminRepository, errorHandler, uiNotifications, $translate, localizationHelper) { var vm = this; vm.translationObject = {}; vm.loadTranslation = function(){ $translate(['Info', 'AdminUpdated', 'YourPersonalInfoUpdated']).then(function (tr) { vm.translationObject = tr; }); }; vm.unsubscribe = localizationHelper.eventEmitter.subscribe('onLanguageChangedEvent', function (lang) { vm.loadTranslation(); }); vm.loadTranslation(); // Variables. vm.profile = { "FirstName": null, "LastName": null, "Email": null, "PhoneNumber": null }; vm.currentProfileId = $state.params.id; //Methods. vm.updateProfile = function(){ adminRepository.update(vm.profile, vm.currentProfileId != "" && vm.currentProfileId).success(function(response, status, headers, config){ if (errorHandler.check(response, status, config) == errorHandler.STATUS.SUCCESS) { if (vm.currentProfileId != "") { uiNotifications.inform(vm.translationObject["AdminUpdated"], 'info'); } else { uiNotifications.inform(vm.translationObject["YourPersonalInfoUpdated"], 'info'); } } }); }; vm.getAdminByToken = function(){ adminRepository.get().success(function(response, status, headers, config){ if (errorHandler.check(response, status, config) == errorHandler.STATUS.SUCCESS) { adminRepository.updateObjectKeys(vm.profile, response.data); } }); }; vm.getAdminById = function(id){ adminRepository.get(id).success(function(response, status, headers, config){ if (errorHandler.check(response, status, config) == errorHandler.STATUS.SUCCESS) { adminRepository.updateObjectKeys(vm.profile, response.data); } }); }; // Get profile data when controller was loaded. vm.currentProfileId == "" ? vm.getAdminByToken() : vm.getAdminById(vm.currentProfileId); $scope.$on("$destroy", function(){ vm.unsubscribe(); }); } // IoC container. adminProfile.$inject = [ "$scope", '$state', '$rootScope', "repository.admin", "appUtils.errorHandler", "appUtils.uiNotifications", "$translate", "helpers.localization" ]; })();