<commit_before>/**
 * Copyright (c) 2010-present Abixen Systems. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

(function () {

    'use strict';

    angular
        .module('platformUserModule')
        .controller('UserDetailsController', UserDetailsController);

    UserDetailsController.$inject = [
        '$scope',
        '$state',
        '$stateParams',
        '$log',
        'User',
        'responseHandler'
    ];

    function UserDetailsController($scope, $state, $stateParams, $log, User, responseHandler) {
        $log.log('UserDetailController');

        var userDetails = this;

        new AbstractDetailsController(userDetails, User, responseHandler, $scope,
            {
                entityId: $stateParams.id,
                getValidators: getValidators,
                onSuccessSaveForm: onSuccessSaveForm
            }
        );

        userDetails.languageTypes = [
            {key: 'ENGLISH'},
            {key: 'POLISH'},
            {key: 'RUSSIAN'},
            {key: 'SPANISH'},
            {key: 'UKRAINIAN'}
        ];
        userDetails.genderTypes = [{key: 'MALE'}, {key: 'FEMALE'}];
        userDetails.userBaseUrl = "/api/application/users/";
        userDetails.avatarUrl = '';

        userDetails.today = today;
        userDetails.clear = clear;

        getUserAvatarUrl($stateParams.id);

        function clear() {
            $scope.entity.birthday = null;
        }

        function today() {
            $scope.entity.birthday = new Date();
        }

        function onSuccessSaveForm() {
            $state.go('application.users.list');
        }

        function getUserAvatarUrl(id) {
            if (userDetails.avatarUrl === '') {
                if (id) {
                    User.get({id: id}, function (data) {
                        userDetails.avatarUrl = userDetails.userBaseUrl + id + '/avatar/' + data.avatarFileName;
                    });
                } else {
                    userDetails.avatarUrl = '';
                }
            }
        }

        function getValidators() {
            var validators = [];

            validators['screenName'] =
                [
                    new NotNull(),
                    new Length(3, 32)
                ];

            validators['username'] =
                [
                    new NotNull(),
                    new Length(3, 32),
                    new Email()
                ];

            validators['firstName'] =
                [
                    new NotNull(),
                    new Length(2, 64)
                ];

            validators['middleName'] =
                [<commit_msg>Double get call in user edit.. Fixed #871<commit_after>/**
 * Copyright (c) 2010-present Abixen Systems. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

(function () {

    'use strict';

    angular
        .module('platformUserModule')
        .controller('UserDetailsController', UserDetailsController);

    UserDetailsController.$inject = [
        '$scope',
        '$state',
        '$stateParams',
        '$log',
        'User',
        'responseHandler'
    ];

    function UserDetailsController($scope, $state, $stateParams, $log, User, responseHandler) {
        $log.log('UserDetailController');

        var userDetails = this;

        new AbstractDetailsController(userDetails, User, responseHandler, $scope,
            {
                entityId: $stateParams.id,
                getValidators: getValidators,
                onSuccessSaveForm: onSuccessSaveForm,
                onSuccessGetEntity: onSuccessGetEntity
            }
        );

        userDetails.languageTypes = [
            {key: 'ENGLISH'},
            {key: 'POLISH'},
            {key: 'RUSSIAN'},
            {key: 'SPANISH'},
            {key: 'UKRAINIAN'}
        ];
        userDetails.genderTypes = [{key: 'MALE'}, {key: 'FEMALE'}];
        userDetails.userBaseUrl = "/api/application/users/";
        userDetails.avatarUrl = userDetails.userBaseUrl + ' ';

        userDetails.today = today;
        userDetails.clear = clear;


        function clear() {
            $scope.entity.birthday = null;
        }

        function today() {
            $scope.entity.birthday = new Date();
        }

        function onSuccessSaveForm() {
            $state.go('application.users.list');
        }

        function onSuccessGetEntity() {
            userDetails.avatarUrl = userDetails.userBaseUrl + userDetails.entity.id + '/avatar/' + userDetails.entity.avatarFileName
        }

        function getValidators() {
            var validators = [];

            validators['screenName'] =
                [
                    new NotNull(),
                    new Length(3, 32)
                ];

            validators['username'] =
                [
                    new NotNull(),
                    new Length(3, 32),
                    new Email()
                ];

            validators['firstName'] =
                [
                    new NotNull(),
                    new Length(2, 64)
                ];

            validators['middleName'] =
                [
{'fraction_non_alphanumeric': 0.10449951092272579, 'fraction_numerical': 0.005379850016302576, 'mean_word_length': 1.6398450946643717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837248', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1494, 'n_words': 407}