<commit_before>const localize    = require('../../base/localize').localize;
const FormManager = require('../../common_functions/form_manager');

const AccountTransfer = (() => {
    'use strict';

    const form_id = '#frm_account_transfer';
    const hidden_class = 'invisible';

    let accounts,
        $transfer;

    const populateAccounts = (response) => {
        accounts = response.accounts;
        const $form = $(form_id);
        $transfer = $form.find('#transfer');
        let text,
            from_loginid,
            to_loginid;

        accounts.forEach((account, idx) => {
            if (+account.balance) {
                from_loginid = accounts[idx].loginid;
                to_loginid = accounts[1 - idx].loginid;
                text = localize('from [_1] to [_2]', [from_loginid, to_loginid]);
                $transfer.append($('<option/>', {
                    text           : text,
                    'data-from'    : from_loginid,
                    'data-to'      : to_loginid,
                    'data-currency': accounts[idx].currency,
                    'data-balance' : accounts[idx].balance,
                }));
            }
        });

        if (from_loginid) {
            showForm($form);
        } else {
            $('#client_message').removeClass(hidden_class);
        }
    };

    const showForm = ($form) => {
        const $currency = $form.find('#currency');
        $transfer.on('change', function() {
            updateCurrency($currency, $(this));
            bindValidation();
        });
        updateCurrency($currency);
        $form.removeClass(hidden_class);
        bindValidation();
        FormManager.handleSubmit({
            form_selector       : form_id,
            fnc_response_handler: responseHandler,
        });
    };

    const updateCurrency = ($currency) => { $currency.text(getTransferAttr('data-currency')); };

    const getTransferAttr = attribute => $transfer.find('option:selected').attr(attribute);

    const bindValidation = () => {
        FormManager.init(form_id, [
            { selector: '#amount', validations: ['req', ['number', { type: 'float', decimals: '1, 2', min: 0.1, max: getTransferAttr('data-balance') }]] },
<commit_msg>show client's loginid option on top<commit_after>const Client      = require('../../base/client').Client;
const localize    = require('../../base/localize').localize;
const FormManager = require('../../common_functions/form_manager');

const AccountTransfer = (() => {
    'use strict';

    const form_id = '#frm_account_transfer';
    const hidden_class = 'invisible';

    let accounts,
        $transfer;

    const populateAccounts = (response) => {
        accounts = response.accounts;
        const $form = $(form_id);
        $transfer = $form.find('#transfer');
        let text,
            from_loginid,
            to_loginid;

        accounts.forEach((account, idx) => {
            if (+account.balance) {
                from_loginid = accounts[idx].loginid;
                to_loginid = accounts[1 - idx].loginid;
                text = localize('from [_1] to [_2]', [from_loginid, to_loginid]);
                $transfer.append($('<option/>', {
                    text           : text,
                    'data-from'    : from_loginid,
                    'data-to'      : to_loginid,
                    'data-currency': accounts[idx].currency,
                    'data-balance' : accounts[idx].balance,
                }));
            }
        });

        // show client's login id on top
        const $client_option = $transfer.find('option[data-from="' + Client.get('loginid') + '"]');
        if ($client_option.length !== 0) {
            $client_option.insertBefore($transfer.find('option:eq(0)')).attr('selected', 'selected');
        }

        if (from_loginid) {
            showForm($form);
        } else {
            $('#client_message').removeClass(hidden_class);
        }
    };

    const showForm = ($form) => {
        const $currency = $form.find('#currency');
        $transfer.on('change', function() {
            updateCurrency($currency, $(this));
            bindValidation();
        });
        updateCurrency($currency);
        $form.removeClass(hidden_class);
        bindValidation();
        FormManager.handleSubmit({
            form_selector       : form_id,
            fnc_response_handler: responseHandler,
        });
    };

    const updateCurrency = ($currency) => { $currency.text(getTransferAttr('data-currency')); };

    const getTransferAttr = attribute => $transfer.find('option:selected').attr(attribute);

    const bindValidation = () => {
        FormManager.init(form_id, [
            { selector: '#amount', validations: ['req', ['number', { type: 'float', decimals: '1, 2', min: 0.1, max: getTransferAttr('data-balance') }]] },

{'fraction_non_alphanumeric': 0.15278350515463918, 'fraction_numerical': 0.0032989690721649486, 'mean_word_length': 2.0167910447761193, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '257772', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1305, 'n_words': 241}