Fixed #5704 - Admin popup windows won't close when using application/xhtml as default content type

Thanks to Rob van der Linde for the report, and to mb0, dArignac and claudep
for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17065 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Luke Plant 2011-11-01 21:50:17 +00:00
parent a97ecfdea8
commit 6d39cb4119
2 changed files with 6 additions and 3 deletions

View File

@ -779,7 +779,9 @@ class ModelAdmin(BaseModelAdmin):
return HttpResponseRedirect(post_url_continue % pk_value) return HttpResponseRedirect(post_url_continue % pk_value)
if "_popup" in request.POST: if "_popup" in request.POST:
return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \ return HttpResponse(
'<!DOCTYPE html><html><head><title></title></head><body>'
'<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script></body></html>' % \
# escape() calls force_unicode. # escape() calls force_unicode.
(escape(pk_value), escapejs(obj))) (escape(pk_value), escapejs(obj)))
elif "_addanother" in request.POST: elif "_addanother" in request.POST:

View File

@ -74,11 +74,12 @@ function dismissAddAnotherPopup(win, newId, newRepr) {
var name = windowname_to_id(win.name); var name = windowname_to_id(win.name);
var elem = document.getElementById(name); var elem = document.getElementById(name);
if (elem) { if (elem) {
if (elem.nodeName == 'SELECT') { var elemName = elem.nodeName.toUpperCase();
if (elemName == 'SELECT') {
var o = new Option(newRepr, newId); var o = new Option(newRepr, newId);
elem.options[elem.options.length] = o; elem.options[elem.options.length] = o;
o.selected = true; o.selected = true;
} else if (elem.nodeName == 'INPUT') { } else if (elemName == 'INPUT') {
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
elem.value += ',' + newId; elem.value += ',' + newId;
} else { } else {