{% load i18n%}

$('.repo-transfer-btn').click(function(){
    var btn_ct = $(this).parents('td'),
        repo_id = btn_ct.data('id'),
        repo_name = btn_ct.attr('data-name'),
        form = $('#repo-transfer-form');

    form.modal({appendTo:'#main'});
    $('#simplemodal-container').css({'width':'auto', 'height':'auto'});

    var detail = $('.detail', form);
    detail.html(detail.html().replace('%(lib_name)s', '<span class="op-target">' + HTMLescape(repo_name) + '</span>'));

    $('[name="email"]', form).select2($.extend({
        width: '268px',
        maximumSelectionSize: 1,
        placeholder: "{% trans "Search user or enter email and press Enter" %}",
        formatInputTooShort: "{% trans "Please enter 1 or more character" %}",
        formatNoMatches: "{% trans "No matches" %}",
        formatSearching: "{% trans "Searching..." %}",
        formatAjaxError: "{% trans "Loading failed" %}",
        formatSelectionTooBig: "{% trans "You cannot select any more choices" %}"
    }, userInputOPtionsForSelect2('{% url 'search-user' %}')));

    $('input[name="repo_id"]', form).val(repo_id);
    return false;
});

$('#repo-transfer-form').submit(function() {
    var form = $(this),
        form_id = form.attr('id'),
        email = $.trim(form.children('[name="email"]').val());

    if (!email) {
        return false;
    }
});

$('#main-panel').removeClass('ovhd');

addConfirmTo($('.repo-delete-btn'), {
    'title': "{% trans "Delete Library" %}",
    'con': "{% trans "Are you sure you want to delete %s ?" %}",
    'post': true
});
