(function(context,$) {


    var restAdmin = context.JK.RestAdmin();

    $(function() {
        // convert mix again links to ajax
        $('a.mix-again').click(function() {
            var $link = $(this);
            restAdmin.tryMixAgain({mix_id: $link.attr('data-mix-id')})
                .done(function(response) {
                    $link.closest('div.mix-again').find('div.mix-again-dialog').html('<div>Mix enqueued</div><a href="' + gon.global.prefix + '/resque">Resque Web</a>').dialog();
                })
                .error(function(jqXHR) {
                    $link.closest('div.mix-again').find('div.mix-again-dialog').html('Mix failed: ' + jqXHR.responseText).dialog();
                })

            return false;
        })

    });
})(window, jQuery);