{% load i18n %}

var cur_tab = $('.ui-tabs-selected .a');
if (cur_tab.attr('id') == 'user-tab') {
    var is_user_tab = new Boolean(true);
} else {
    var is_user_tab = new Boolean(false);
}
$('#user-tab').click(function() {
    is_user_tab = new Boolean(true);
});
$('#group-tab').click(function() {
    is_user_tab = new Boolean(false);
});

$('.perm-item').on({
    mouseenter: function() {
        var perm_item = $(this);
        perm_item.find('.perm-edit-icon').removeClass('vh');
        perm_item.find('.perm-delete-btn').removeClass('vh');
    },
    mouseleave: function() {
        var perm_item = $(this);
        perm_item.find('.perm-edit-icon').addClass('vh');
        perm_item.find('.perm-delete-btn').addClass('vh');
    }
});
$('.perm-edit-icon').on('click', function() {
    $(this).parent().addClass('hide')
           .next().removeClass('hide');
});

function perm_toggle(select, data, url) {
    $.ajax({
        url: url,
        type: 'POST',
        dataType: 'json',
        cache: false,
        beforeSend: prepareCSRFToken,
        data: data,
        success: function(data) {
            select.addClass('hide')
                  .prev().removeClass('hide')
                         .children('span')
                         .html(select.children('option[value="' + select.val() + '"]').text());
            feedback("{% trans "Success" %}", 'success');
        },
        error: ajaxErrorHandler
    });
}

$(document).on('click', function(e) {
    var target = e.target || event.srcElement;
    if (!$('.perm-edit-icon, .perm-toggle-select').is(target)) {
        $('.perm-change').removeClass('hide');
        $('.perm-toggle-select').addClass('hide');
    }
});
