<commit_before>// Handles related-objects functionality: lookup link for raw_id_fields
// and Add Another links.

function html_unescape(text) {
    // Unescape a string that was escaped using django.utils.html.escape.
    text = text.replace(/&lt;/g, '<');
    text = text.replace(/&gt;/g, '>');
    text = text.replace(/&quot;/g, '"');
    text = text.replace(/&#39;/g, "'");
    text = text.replace(/&amp;/g, '&');
    return text;
}

function showRelatedObjectLookupPopup(triggeringLink) {
    var name = triggeringLink.id.replace(/^lookup_/, '');
    // IE doesn't like periods in the window name, so convert temporarily.
    name = name.replace(/\./g, '___');
    var href;
    if (triggeringLink.href.search(/\?/) >= 0) {
        href = triggeringLink.href + '&pop=1';
    } else {
        href = triggeringLink.href + '?pop=1';
    }
    var win = window.open(href, name, 'height=600,width=900,resizable=yes,scrollbars=yes');
    win.focus();
    return false;
}

function dismissRelatedLookupPopup(win, chosenId) {
    var name = win.name.replace(/___/g, '.');
    var elem = document.getElementById(name);
    if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
        elem.value += ',' + chosenId;
    } else {
        document.getElementById(name).value = chosenId;
        document.getElementById(name).focus();
    }
    win.close();
}

function showAddAnotherPopup(triggeringLink) {
    var name = triggeringLink.id.replace(/^add_/, '');
    name = name.replace(/\./g, '___');
    href = triggeringLink.href
    if (href.indexOf('?') == -1) {
        href += '?_popup=1';
    } else {
        href  += '&_popup=1';
    }
    var win = window.open(href, name, 'height=600,width=900,resizable=yes,scrollbars=yes');
    win.focus();
    return false;
}

function dismissAddAnotherPopup(win, newId, newRepr) {
    // newId and newRepr are expected to have previously been escaped by
    // django.utils.html.escape.
    newId = html_unescape(newId);
    newRepr = html_unescape(newRepr);
    var name = win.name.replace(/___/g, '.');
    var elem = document.getElementById(name);
    if (elem) {
        if (elem.nodeName == 'SELECT') {
            var o = new Option(newRepr, newId);
            elem.options[elem.options.length] = o;
            o.selected = true;
        } else if (elem.nodeName == 'INPUT') {
            elem.value = newId;
        }
    } else {
        var toId = name + "_to";
        elem = document.getElementById(toId);
        var o = new Option(newRepr, newId);
        SelectBox.add_to_cache(toId, o);
        SelectBox.redisplay(toId);
    }
    win.close();
}

// ADDED: SHOW OBJECT_REPR WHEN FOREIGNKEY CHANGES
var ADMIN_MEDIA_URL = '/admin/media/';
var CHAR_MAX_LENGTH = 30;

function RelatedLookup(obj) {
    link = obj.next();
    text = obj.next().next();
    var app_label = link.attr('href').split('/')[3];
    var model_name= link.attr('href').split('/')[4];
    
    text.text('loading ...');
    
    // get object
    $.get('/grappelli/related_lookup/', {object_id: obj.val(), app_label: app_label, model_name: model_name}, function(data) {
        item = data;
        text.text('');
        if (item) {
            if (item.length > CHAR_MAX_LENGTH) {
                text.text(decodeURI(item.substr(0, CHAR_MAX_LENGTH) + " ..."));
            } else {
                text.text(decodeURI(item));
            }
        }
    });
}

$(document).ready(function(){
    
    $("input.vForeignKeyRawIdAdminField").each(function() {
        // insert empty text-elements after all empty foreignkeys
        if ($(this).val() == "") {
            $(this).next().after('&nbsp;<strong></strong>');
        }
    });
    
    $("input.vForeignKeyRawIdAdminField").bind("change focus", function() {
        RelatedLookup($(this));
    });
});

<commit_msg>resolved error with 2 related-lookups one after another<commit_after>// Handles related-objects functionality: lookup link for raw_id_fields
// and Add Another links.

function html_unescape(text) {
    // Unescape a string that was escaped using django.utils.html.escape.
    text = text.replace(/&lt;/g, '<');
    text = text.replace(/&gt;/g, '>');
    text = text.replace(/&quot;/g, '"');
    text = text.replace(/&#39;/g, "'");
    text = text.replace(/&amp;/g, '&');
    return text;
}

function showRelatedObjectLookupPopup(triggeringLink) {
    var name = triggeringLink.id.replace(/^lookup_/, '');
    // IE doesn't like periods in the window name, so convert temporarily.
    name = name.replace(/\./g, '___');
    var href;
    if (triggeringLink.href.search(/\?/) >= 0) {
        href = triggeringLink.href + '&pop=1';
    } else {
        href = triggeringLink.href + '?pop=1';
    }
    var win = window.open(href, name, 'height=600,width=900,resizable=yes,scrollbars=yes');
    win.focus();
    return false;
}

function dismissRelatedLookupPopup(win, chosenId) {
    var name = win.name.replace(/___/g, '.');
    var elem = document.getElementById(name);
    if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
        elem.value += ',' + chosenId;
    } else {
        document.getElementById(name).value = chosenId;
        document.getElementById(name).focus();
    }
    win.close();
}

function showAddAnotherPopup(triggeringLink) {
    var name = triggeringLink.id.replace(/^add_/, '');
    name = name.replace(/\./g, '___');
    href = triggeringLink.href
    if (href.indexOf('?') == -1) {
        href += '?_popup=1';
    } else {
        href  += '&_popup=1';
    }
    var win = window.open(href, name, 'height=600,width=900,resizable=yes,scrollbars=yes');
    win.focus();
    return false;
}

function dismissAddAnotherPopup(win, newId, newRepr) {
    // newId and newRepr are expected to have previously been escaped by
    // django.utils.html.escape.
    newId = html_unescape(newId);
    newRepr = html_unescape(newRepr);
    var name = win.name.replace(/___/g, '.');
    var elem = document.getElementById(name);
    if (elem) {
        if (elem.nodeName == 'SELECT') {
            var o = new Option(newRepr, newId);
            elem.options[elem.options.length] = o;
            o.selected = true;
        } else if (elem.nodeName == 'INPUT') {
            elem.value = newId;
        }
    } else {
        var toId = name + "_to";
        elem = document.getElementById(toId);
        var o = new Option(newRepr, newId);
        SelectBox.add_to_cache(toId, o);
        SelectBox.redisplay(toId);
    }
    win.close();
}

// ADDED: SHOW OBJECT_REPR WHEN FOREIGNKEY CHANGES
var ADMIN_MEDIA_URL = '/admin/media/';
var CHAR_MAX_LENGTH = 30;

function RelatedLookup(obj) {
    var link = obj.next();
    var text = obj.next().next();
    var app_label = link.attr('href').split('/')[3];
    var model_name= link.attr('href').split('/')[4];
    
    text.text('loading ...');
    
    // get object
    $.get('/grappelli/related_lookup/', {object_id: obj.val(), app_label: app_label, model_name: model_name}, function(data) {
        var item = data;
        text.text('');
        if (item) {
            if (item.length > CHAR_MAX_LENGTH) {
                text.text(decodeURI(item.substr(0, CHAR_MAX_LENGTH) + " ..."));
            } else {
                text.text(decodeURI(item));
            }
        }
    });
}

$(document).ready(function(){
    
    $("input.vForeignKeyRawIdAdminField").each(function() {
        // insert empty text-elements after all empty foreignkeys
        if ($(this).val() == "") {
            $(this).next().after('&nbsp;<strong></strong>');
        }
    });
    
    $("input.vForeignKeyRawIdAdminField").bind("change", function() {
        RelatedLookup($(this));
    });
    $("input.vForeignKeyRawIdAdminField").bind("focus", function() {
        RelatedLookup($(this));
    });
    
});


{'fraction_non_alphanumeric': 0.16922290388548059, 'fraction_numerical': 0.00677402862985685, 'mean_word_length': 2.594395957740009, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '4425611', 'n_tokens_mistral': 2564, 'n_tokens_neox': 2515, 'n_words': 496}