Ticket #2569: adminforeign.2.diff

File adminforeign.2.diff, 4.2 KB (added by joelh-django@…, 18 years ago)

diff file for the patch

  • django/contrib/admin/media/js/admin/RelatedObjectLookups.js

     
    5555    }
    5656    win.close();
    5757}
     58
     59function showEditPopup(triggeringLink) {
     60    var name = triggeringLink.id.replace(/^edit_/,'');
     61    name = name.replace(/\./g,'___');
     62    var elem = document.getElementById(name);
     63    if (elem) {
     64        if (elem.nodeName == 'SELECT') {
     65            var id = elem.options[elem.selectedIndex].value
     66            var win = window.open(triggeringLink.href + id + '?_popup=1',name, 'height=500,width=800,resizable=yes,scrollbars=yes');
     67        }
     68    }
     69    return false;
     70}
     71
     72function dismissEditPopup(win, newId, newRepr) {
     73    var name = win.name.replace(/___/g, '.');
     74    var elem = document.getElementById(name);
     75    if(elem) {
     76        if( elem.nodeName == 'SELECT') {
     77            var o = new Option(newRepr, newId);
     78            elem.options[elem.selectedIndex] = o;
     79            o.selected = true;
     80        }
     81    }
     82    win.close();
     83}
  • django/contrib/admin/views/main.py

     
    341341            LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), CHANGE, change_message)
    342342
    343343            msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object}
     344            if request.REQUEST.has_key("_popup"):
     345                http_response = '<script type="text/javascript">opener.dismissEditPopup(window, %s, "%s");</script>' % \
     346                    (pk_value, str(new_object).replace('"', '\\"'))
     347                return HttpResponse(http_response)
    344348            if request.POST.has_key("_continue"):
    345349                request.user.message_set.create(message=msg + ' ' + _("You may edit it again below."))
    346350                if request.REQUEST.has_key('_popup'):
  • django/contrib/admin/templates/widget/one_to_one.html

     
     1{% load admin_modify adminmedia %}
    12{% if add %}{% include "widget/foreign.html" %}{% endif %}
    2 {% if change %}{% if bound_field.existing_display %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong>{% endif %}{% endif %}
     3{% if change %}
     4{% if bound_field.existing_display %}&nbsp;<a href="{{ bound_field.related_url }}{{ bound_field.existing_display}}"><strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong></a>{% endif %}{% endif %}
  • django/contrib/admin/templates/widget/foreign.html

     
    88    {% endif %}
    99{% else %}
    1010{% if bound_field.needs_add_label %}
    11     <a href="{{ bound_field.related_url }}add/" class="add-another" id="add_{{ bound_field.element_id }}" onclick="return showAddAnotherPopup(this);"> <img src="{% admin_media_prefix %}img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>
    12 {% endif %}{% endif %}
     11    <a href="{{ bound_field.related_url }}add/" class="add-another" id="add_{{ bound_field.element_id }}" onclick="return showAddAnotherPopup(this);"> <img src="{% admin_media_prefix %}img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>
     12    <a href="{{ bound_field.related_url }}" class="related-lookup" id="edit_{{ bound_field.element_id }}" onclick="return showEditPopup(this);"> <img src="{% admin_media_prefix %}img/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>
     13 
     14{% endif %}
     15{% endif %}
    1316{% if change %}
    1417    {% if bound_field.field.primary_key %}
    1518        {{ bound_field.original_value }}
Back to Top