Code

Ticket #2569: adminforeign.diff

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

diff file for the patch

Line 
1Index: django/contrib/admin/media/js/admin/RelatedObjectLookups.js
2===================================================================
3--- django/contrib/admin/media/js/admin/RelatedObjectLookups.js (revision 3426)
4+++ django/contrib/admin/media/js/admin/RelatedObjectLookups.js (working copy)
5@@ -36,6 +36,7 @@
6 }
7 
8 function dismissAddAnotherPopup(win, newId, newRepr) {
9+    alert(win.name);
10     var name = win.name.replace(/___/g, '.');
11     var elem = document.getElementById(name);
12     if (elem) {
13@@ -55,3 +56,29 @@
14     }
15     win.close();
16 }
17+
18+function showEditPopup(triggeringLink) {
19+    var name = triggeringLink.id.replace(/^edit_/,'');
20+    name = name.replace(/\./g,'___');
21+    var elem = document.getElementById(name);
22+    if (elem) {
23+        if (elem.nodeName == 'SELECT') {
24+            var id = elem.options[elem.selectedIndex].value
25+            var win = window.open(triggeringLink.href + id + '?_popup=1',name, 'height=500,width=800,resizable=yes,scrollbars=yes');
26+        }
27+    }
28+    return false;
29+}
30+
31+function dismissEditPopup(win, newId, newRepr) {
32+    var name = win.name.replace(/___/g, '.');
33+    var elem = document.getElementById(name);
34+    if(elem) {
35+        if( elem.nodeName == 'SELECT') {
36+            var o = new Option(newRepr, newId);
37+            elem.options[elem.selectedIndex] = o;
38+            o.selected = true;
39+        }
40+    }
41+    win.close();
42+}
43Index: django/contrib/admin/views/main.py
44===================================================================
45--- django/contrib/admin/views/main.py  (revision 3426)
46+++ django/contrib/admin/views/main.py  (working copy)
47@@ -341,6 +341,10 @@
48             LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), CHANGE, change_message)
49 
50             msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object}
51+            if request.REQUEST.has_key("_popup"):
52+                http_response = '<script type="text/javascript">opener.dismissEditPopup(window, %s, "%s");</script>' % \
53+                    (pk_value, str(new_object).replace('"', '\\"'))
54+                return HttpResponse(http_response)
55             if request.POST.has_key("_continue"):
56                 request.user.message_set.create(message=msg + ' ' + _("You may edit it again below."))
57                 if request.REQUEST.has_key('_popup'):
58Index: django/contrib/admin/templates/widget/one_to_one.html
59===================================================================
60--- django/contrib/admin/templates/widget/one_to_one.html       (revision 3426)
61+++ django/contrib/admin/templates/widget/one_to_one.html       (working copy)
62@@ -1,2 +1,4 @@
63+{% load admin_modify adminmedia %}
64 {% if add %}{% include "widget/foreign.html" %}{% endif %}
65-{% if change %}{% if bound_field.existing_display %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong>{% endif %}{% endif %}
66+{% if change %}
67+{% 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 %}
68Index: django/contrib/admin/templates/widget/foreign.html
69===================================================================
70--- django/contrib/admin/templates/widget/foreign.html  (revision 3426)
71+++ django/contrib/admin/templates/widget/foreign.html  (working copy)
72@@ -8,8 +8,11 @@
73     {% endif %}
74 {% else %}
75 {% if bound_field.needs_add_label %}
76-    <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>
77-{% endif %}{% endif %}
78+    <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>
79+    <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>
80+
81+{% endif %}
82+{% endif %}
83 {% if change %}
84     {% if bound_field.field.primary_key %}
85         {{ bound_field.original_value }}