{$hide_disabled_users = ConfigHelper::checkConfig('rt.hide_disabled_users', ConfigHelper::checkConfig('phpui.helpdesk_hide_disabled_users')) scope=global}
{$hide_deleted_users = ConfigHelper::checkConfig('rt.hide_deleted_users', ConfigHelper::checkConfig('phpui.helpdesk_hide_deleted_users')) scope=global}
{$reset_ticket_state = ConfigHelper::checkConfig('rt.ticket_queue_change_resets_ticket_state') scope=global}

<script>

$(function() {
    var assignToMeElem = $("#assign-to-me");
    var ownerElem = $("#owner");
    var stateElem = $("#state");

    $("#resolve").change(function() {
        if ($(this).prop("checked")) {
            stateElem.attr("prev-state", stateElem.val()).val({$smarty.const.RT_RESOLVED});
            ownerElem.attr("prev-state", ownerElem.val()).val({$layout.logid});
        } else {
            var state_prev_state = stateElem.attr("prev-state");
            if (state_prev_state) {
                stateElem.val(state_prev_state);
            }
            var owner_prev_state = ownerElem.attr("prev-state");
            if (owner_prev_state) {
                ownerElem.val(owner_prev_state);
            }
        }
        updateAdvancedSelectsTest(stateElem);
        updateAdvancedSelectsTest(ownerElem);
    });

    $("#queue-selection").change(function() {
        {if !empty($reset_ticket_state)}
            $('#state option:eq("{$smarty.const.RT_NEW}")').prop("selected", true);
            updateAdvancedSelectsTest(stateElem);
            $("#resolve").prop("checked", false);
        {/if}
        xajax_queue_changed($(this).val(), $("#rtverifiers select").val());
    });

    $("#state").change(function() {
        $('#resolve').prop('checked', $(this).val() == {$smarty.const.RT_RESOLVED});
    });

    ownerElem.change(function() {
        assignToMeElem.prop('checked', $(this).val() == assignToMeElem.attr('data-userid'));
    });

    assignToMeElem.change(function() {
        if ($(this).prop('checked')) {
            ownerElem.val($(this).attr('data-old-userid', ownerElem.val()).attr('data-userid'));
        } else {
            ownerElem.val($(this).attr('data-old-userid'));
        }
        updateAdvancedSelectsTest(ownerElem);
    });
});

</script>
