{"size": 5314, "ext": "js", "max_stars_repo_path": "app/assets/js/area/acquisition_only.js", "max_stars_repo_name": "theoboldt/juvem", "max_stars_repo_stars_event_min_datetime": "2017-02-05T20:39:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T13:24:56.000Z", "max_issues_repo_path": "app/assets/js/area/acquisition_only.js", "max_issues_repo_name": "theoboldt/juvem", "max_issues_repo_issues_event_min_datetime": "2018-06-05T16:02:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T02:04:18.000Z", "max_forks_repo_path": "app/assets/js/area/acquisition_only.js", "max_forks_repo_name": "theoboldt/juvem", "max_forks_repo_forks_event_min_datetime": "2018-06-08T08:50:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-08T08:50:46.000Z"}
{"max_stars_count": 5, "max_issues_count": 10, "max_forks_count": 1, "avg_line_length": 41.842519685, "max_line_length": 191, "alphanum_fraction": 0.4958599925}
$(function () {
    var elementType = '*#acquisition_fieldType',
        updateType;

    /**
     * ACQUISITION: When selection is changed
     */
    updateType = function () {
        var el = $(elementType),
            val = el ? el.val() : null;
        if (el
            && (val === "Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType"
                || val === "AppBundle\\Form\\GroupType")
        ) {
            $('.form-group-choice').css('display', 'block');
        } else {
            $('.form-group-choice').css('display', 'none');
        }

        var elMultiple = $('.form-group-choice-multiple');
        if (el && val === "AppBundle\\Form\\GroupType") {
            elMultiple.css('display', 'none');
            elMultiple.find('select').val(0);
        } else {
            elMultiple.css('display', 'block');
        }

    };
    updateType();
    $(elementType).change(updateType);

    /**
     * ACQUISITION: Price formula enable/disable
     */
    var isPriceFormulaEnabledEl = $('#acquisition_isPriceFormulaEnabled'),
        updateFormulaInputDisplay = function () {
            var checked = isPriceFormulaEnabledEl.prop('checked');
            if (checked) {
                $('.form-input-formula').css('display', 'block');
            } else {
                $('.form-input-formula').css('display', 'none');
            }
        };
    updateFormulaInputDisplay();
    isPriceFormulaEnabledEl.change(updateFormulaInputDisplay);
    $('.form-acquisition-option-add').on('click', function () {
        console.log(1);
        updateFormulaInputDisplay();
    });

    $('#dialogModalRelateParticipant').on('show.bs.modal', function (event) {
        var buttonEl = $(event.relatedTarget),
            modalEl = $(this),
            title = buttonEl.data('title'),
            description = buttonEl.data('description'),
            firstName = buttonEl.data('first-name'),
            lastName = buttonEl.data('last-name'),
            tbodyEl = modalEl.find('table tbody');

        modalEl.find('.modal-title span').text(title);
        modalEl.find('.modal-body p.description').text(description);
        modalEl.find('.modal-body .first-name').text(firstName);
        modalEl.find('.modal-body .last-name').text(lastName);
        modalEl.find('#participation_assign_related_participant_oid').val(buttonEl.data('oid'));
        modalEl.find('#participation_assign_related_participant_related').val(buttonEl.data('aid'));

        tbodyEl.html('<tr><td colspan="4" class="text-center loading">(Wird geladen)</td></tr>');

        $.get({
            url: '../participant_proposal/' + buttonEl.data('oid'),
            success: function (response) {
                if (response && response.rows && response.rows.length) {
                    var tableBody = '';
                    jQuery.each(response.rows, function (key, row) {

                        tableBody += '<tr>' +
                            '<td>' + row.firstName + '</td>' +
                            '<td>' + row.lastName + '</td>' +
                            '<td>' + row.age + '</td>' +
                            '<td>' + row.status + '</td>' +
                            '<td class="text-right">' +
                            ' <div data-aid="' + row.aid + '" class="btn btn-' + (row.selected ? 'default' : 'primary') + ' btn-xs ' + (row.selected && !row.system ? 'disabled' : '') + '">' +
                            '  <span class="glyphicon glyphicon-link" aria-hidden="true"></span> ' +
                            (row.system ? '<span class="glyphicon glyphicon-flash" "="" aria-hidden="true" title="automatisch"></span>' : '') +
                            (row.selected ? 'verknüpft' : 'verknüpfen') +
                            ' </div>' +
                            '</td>' +
                            '</tr>';
                    });

                    tbodyEl.html(tableBody);
                    $('#dialogModalRelateParticipant table .btn').on('click', function (e) {
                        console.log(e);
                        e.preventDefault();
                        var aidButtonEl = $(this);
                        if (aidButtonEl.hasClass('disabled')) {
                            return;
                        }
                        modalEl.find('#participation_assign_related_participant_related').val(aidButtonEl.data('aid'));
                        $('#dialogModalRelateParticipant form').submit();
                    });
                } else {
                    tbodyEl.html('<td colspan="5" class="text-center">(Keine passenden Teilnehmer:innen gefunden)</td>');
                }

            },
            error: function () {
                tbodyEl.html('<td colspan="5" class="text-center">(Fehler beim laden der Vorschläge)</td>');
            },
        });
    });


    /**
     * ACQUISITION: Formula editor
     */
    var inputFormulaEl = $('.input-formula');
    $('.btn-formula-variable').on('click', function () {
        var cursorPos = inputFormulaEl.prop('selectionStart'),
            v = inputFormulaEl.val(),
            textBefore = v.substring(0, cursorPos),
            textAfter = v.substring(cursorPos, v.length);

        inputFormulaEl.val(textBefore + $(this).data('variable') + textAfter);
    });
});
