Ticket #2569: adminforeign.diff

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

diff file for the patch

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

     
    3636}
    3737
    3838function dismissAddAnotherPopup(win, newId, newRepr) {
     39    alert(win.name);
    3940    var name = win.name.replace(/___/g, '.');
    4041    var elem = document.getElementById(name);
    4142    if (elem) {
     
    5556    }
    5657    win.close();
    5758}
     59
     60function showEditPopup(triggeringLink) {
     61    var name = triggeringLink.id.replace(/^edit_/,'');
     62    name = name.replace(/\./g,'___');
     63    var elem = document.getElementById(name);
     64    if (elem) {
     65        if (elem.nodeName == 'SELECT') {
     66            var id = elem.options[elem.selectedIndex].value
     67            var win = window.open(triggeringLink.href + id + '?_popup=1',name, 'height=500,width=800,resizable=yes,scrollbars=yes');
     68        }
     69    }
     70    return false;
     71}
     72
     73function dismissEditPopup(win, newId, newRepr) {
     74    var name = win.name.replace(/___/g, '.');
     75    var elem = document.getElementById(name);
     76    if(elem) {
     77        if( elem.nodeName == 'SELECT') {
     78            var o = new Option(newRepr, newId);
     79            elem.options[elem.selectedIndex] = o;
     80            o.selected = true;
     81        }
     82    }
     83    win.close();
     84}
  • 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