$(document).on('turbolinks:load', function() {
    if ($('body.admins-job-authentications-index-page').length > 0) {
        $(".admins-job-authentications-index-page").on("click", ".reject", function() {
            var self = this;
            bootbox.prompt({
                title: "确认拒绝",
                required: true,
                placeholder: '请输入合适拒绝理由',
                buttons: {
                    confirm: {
                        label: '确定',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: '取消',
                        className: 'btn-danger'
                    }
                },
                callback: function(result) {
                    if (result === null) {
                      return true;
                    }
                    var id = $(self).attr("id");
                    $.ajax({
                        method: 'post',
                        dataType: 'script',
                        data: { reason: result },
                        url: "/admins/job_authentications/" + id + "/refuse?element=.job-authentication-" + id + "&=refresh_url=" + "/admins/job_authentications/" + id,
                    })
                }
            })
        })
    }

    var $searchFrom = $('.job-authentication-list-form');
    $searchFrom.find('select[name="status"]').val('pending');

    $searchFrom.on('click', '.search-form-tab', function() {
        var $link = $(this);

        $searchFrom.find('input[name="keyword"]').val('');
        $searchFrom.find('select[name="status"]').val('processed');

        if ($link.data('value') === 'processed') {
            $searchFrom.find('.status-filter').show();
        } else {
            $searchFrom.find('.status-filter').hide();
            $searchFrom.find('select[name="status"]').val('pending');
        }
    });
});