'use strict';
angular.module('app')
.controller('MyAccountController', function ($scope, $timeout, $stateParams, $window, $http, $noty, $state, $q, $i18next) {
if (Storages.sessionStorage.isEmpty('profile')) {
$http.get('/api/profile').then(function (res) {
Storages.sessionStorage.set('profile', res.data.data);
$scope.data = res.data.data;
}, function () {
$noty({
layout: 'bottom',
type: 'error',
timeout: 5000,
maxVisible: 1,
killer: true,
text: $i18next.t('angularjs.myprofile.loadError')
});
});
} else {
$scope.data = Storages.sessionStorage.get('profile');
}
$scope.save = function () {
$scope.isHttp = true;
$http.post('/api/profile', {profile: $scope.data}).then(function (res) {
if (window.config.app.debug) console.log(res);
Storages.sessionStorage.set('profile', $scope.data);
$noty({
layout: 'bottom',
type: 'success',
timeout: 5000,
maxVisible: 1,
killer: true,
text: $i18next.t('angularjs.myprofile.updatedError')
});
$scope.isHttp = false;
}, function () {
$noty({
layout: 'bottom',
type: 'error',
timeout: 5000,
maxVisible: 1,
killer: true,
text: $i18next.t('angularjs.myprofile.loadError')
});
$scope.isHttp = false;
});
};
});
Setting Storage session
—————————
Storages.sessionStorage.set(‘profile’, res.data.data);
$scope.data = Storages.sessionStorage.get(‘profile’);