%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/news/public/scripts/controllers/
Upload File :
Create Path :
Current File : /var/www/html/news/public/scripts/controllers/menu.controller.js

'use strict';

angular.module('controllers').controller('menuController', function (modalService, $scope, auth, $state, $rootScope, localStorageService) {

    $rootScope.isOpen = localStorageService.get('menuPosition');

    $scope.login = function () {
        auth.login($scope.itemSource).then(function (res) {
            auth.setToken(res.data.token);
            auth.updateUserData(true).then(function (response) {
                auth.setUserData(response.data);
                $rootScope.updateShowingInformation();
                $state.go('users');
            });
        }, function (error) {
            $scope.errorMessage = true;
        });
    };

    $scope.logout = function () {
        $rootScope.loggedUser = {};
        auth.logout();
    };

    $rootScope.isAuth = function () {
        return auth.isLoggedIn();
    };

    $scope.toggleSide = function () {
        $rootScope.isOpen = !$rootScope.isOpen;
        localStorageService.set('menuPosition', $rootScope.isOpen);
    };

    $rootScope.updateShowingInformation = function () {
        try {
            var created_at = auth.getUserInfo().created_at;
            var month = moment(created_at).format('MMMM');
            var year = moment(created_at).year();

            $rootScope.loggedUser = {
                fullname: auth.getUserInfo().fullname,
                role: auth.getUserInfo().roles[0].description,
                memberSince: 'Member since ' + month + ' ' + year,
                profile_picture: auth.getUserInfo().profile_picture
            };
        } catch (e) {
            $rootScope.loggedUser = {};
        }
    };

    $rootScope.updateShowingInformation();

});

Zerion Mini Shell 1.0