<commit_before>/**
 * Javascript for object user's view
 */
$(document).ready(function() {
    // unbind all functions, this ensures that they are never bound more
    // than once.  This is a problem when using jquery ajax tabs
    $('#add_user').unbind();
    $('.ajax_form .submit').die();
    $('.user .delete').die();
    $('.group .delete').die();
    $('.permissions').die();
    
    // Add user button
    $('#add_user').click(function(){
        $('.qtip').qtip('destroy');
        $(this).qtip({
            content: {
               url: user_url,
               title: {text:'Add User: ', button:'close'}
            },
            position: {  corner:{target:'center', tooltip:'center'}},
            style: {name: 'dark', border:{radius:5}, width:300, background:'#eeeeee'},
            show: {when:false, ready:true},
            hide: {fixed: true, when:false},
            api:{onShow:function(){
                $(".ajax_form input[type!=hidden], .ajax_form select").first().focus();
            }}
        });
    });
    
    // form submit button
    $(".ajax_form").live("submit", function(){
        $("#errors").empty();
        $(this).ajaxSubmit({success: update});
        return false;
    });
    
    // Delete user button
    $('.user .delete').live("click", function() {
        $('.qtip').qtip('destroy');
        id = this.parentNode.parentNode.id.substring(5);
        data = {user:id, permissions:[]};
        $.post(user_url, data,
            function(code){
                if (code==1) {
                    $("#user_" + id).remove();
                }
            },
            "json");
    });
    
    // Delete group button
    $('.group .delete').live("click", function() {
        $('.qtip').qtip('destroy');
        id = this.parentNode.parentNode.id.substring(6);
        data = {group:id, permissions:[]};
        $.post(user_url, data,
            function(code){
                if (code==1) {
                    $("#group_" + id).remove();
                }
            },
            "json");
    });
    
    // Update Permission Button
    $(".permissions").live("click", function() {
        // destroy old qtip before showing new one
        $('.qtip').qtip('destroy');
        $(this).qtip({
            content: {
               url: this.href,
               title: {text:'Permissions: ', button:'close'}
            },
            position: {corner:{ target:"topMiddle", tooltip:"bottomMiddle"}},
            style: {name: 'dark', border:{radius:5}, width:300, background:'#eeeeee', tip: 'bottomMiddle'},
            show: {when:false, ready:true},
            hide: {fixed: true, when:false},
            api:{onShow:function(){
                $(".ajax_form input[type!=hidden], .ajax_form select").first().focus();
            }}
        });
        return false;
    });
});

function update(responseText, statusText, xhr, $form) {
    if (xhr.getResponseHeader('Content-Type') == 'application/json') {
        if (responseText == 1) {
            // 1 code means success but no more permissions
            $('.qtip').qtip('hide');
            $("#users #" + html.attr('id')).remove();
        } else {
            // parse errors<commit_msg>adding confirmation dialog when deleting users/groups from permission based membership<commit_after>/**
 * Javascript for object user's view
 */
$(document).ready(function() {
    // unbind all functions, this ensures that they are never bound more
    // than once.  This is a problem when using jquery ajax tabs
    $('#add_user').unbind();
    $('.ajax_form .submit').die();
    $('.user .delete').die();
    $('.group .delete').die();
    $('.permissions').die();
    
    // Add user button
    $('#add_user').click(function(){
        $('.qtip').qtip('destroy');
        $(this).qtip({
            content: {
               url: user_url,
               title: {text:'Add User: ', button:'close'}
            },
            position: {  corner:{target:'center', tooltip:'center'}},
            style: {name: 'dark', border:{radius:5}, width:300, background:'#eeeeee'},
            show: {when:false, ready:true},
            hide: {fixed: true, when:false},
            api:{onShow:function(){
                $(".ajax_form input[type!=hidden], .ajax_form select").first().focus();
            }}
        });
    });
    
    // form submit button
    $(".ajax_form").live("submit", function(){
        $("#errors").empty();
        $(this).ajaxSubmit({success: update});
        return false;
    });
    
    // Delete user button
    $('.user .delete').live("click", function() {
        name = $(this).parent().parent().children('.name').html();
        if (confirm("Remove this user: " + name)) {
            $('.qtip').qtip('destroy');
            id = this.parentNode.parentNode.id.substring(5);
            data = {user:id, permissions:[]};
            $.post(user_url, data,
                function(code){
                    if (code==1) {
                        $("#user_" + id).remove();
                    }
                },
                "json");
        }
    });
    
    // Delete group button
    $('.group .delete').live("click", function() {
        name = $(this).parent().parent().children('.name').html();
        if (confirm("Remove this group: "+ name)) {
            id = this.parentNode.parentNode.id.substring(6);
            data = {group:id, permissions:[]};
            $.post(user_url, data,
                function(code){
                    if (code==1) {
                        $("#group_" + id).remove();
                    }
                },
                "json");
        }
    });
    
    // Update Permission Button
    $(".permissions").live("click", function() {
        // destroy old qtip before showing new one
        $('.qtip').qtip('destroy');
        $(this).qtip({
            content: {
               url: this.href,
               title: {text:'Permissions: ', button:'close'}
            },
            position: {corner:{ target:"topMiddle", tooltip:"bottomMiddle"}},
            style: {name: 'dark', border:{radius:5}, width:300, background:'#eeeeee', tip: 'bottomMiddle'},
            show: {when:false, ready:true},
            hide: {fixed: true, when:false},
            api:{onShow:function(){
                $(".ajax_form input[type!=hidden], .ajax_form select").first().focus();
            }}
        });
        return false;
    });
});

function update(responseText, statusText, xhr, $form) {
    if (xhr.getResponseHeader('Content-Type') == 'application/json') {
        if (responseText == 1) {
            // 1 code means success but no more permissions
            $('.qtip').qtip('hide');
            $("#users #" + html.attr('id')).remove();
        } else {
            // parse errors
{'fraction_non_alphanumeric': 0.1862211099661416, 'fraction_numerical': 0.004121890181068747, 'mean_word_length': 1.8109226313611915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3814490', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1840, 'n_words': 405}