Ticket #7028: improved-raw-id-admin-feedback.diff

File improved-raw-id-admin-feedback.diff, 3.1 KB (added by Marcob <marcoberi@…>, 17 years ago)

immediate raw-id-fields selection feedback

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

     
    2626    return false;
    2727}
    2828
    29 function dismissRelatedLookupPopup(win, chosenId) {
     29function dismissRelatedLookupPopup(win, chosenId, chosenName) {
    3030    var name = win.name.replace(/___/g, '.');
    3131    var elem = document.getElementById(name);
     32    var nameElem = document.getElementById("view_lookup_" + name);
    3233    if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
    3334        elem.value += ',' + chosenId;
    3435    } else {
    3536        document.getElementById(name).value = chosenId;
    3637    }
     38    if(nameElem) {
     39      nameElem.innerHTML = chosenName;
     40    }
    3741    win.close();
    3842}
    3943
  • contrib/admin/templatetags/admin_list.py

     
    196196            # Convert the pk to something that can be used in Javascript.
    197197            # Problem cases are long ints (23L) and non-ASCII strings.
    198198            result_id = repr(force_unicode(getattr(result, pk)))[1:]
     199            result_name = str(result)
    199200            yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \
    200                 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag))
     201                (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s, %r); return false;"' % (result_id or '', result_name)), conditional_escape(result_repr), table_tag))
    201202        else:
    202203            yield mark_safe(u'<td%s>%s</td>' % (row_class, conditional_escape(result_repr)))
    203204
  • contrib/admin/widgets.py

     
    102102            (related_url, url, name))
    103103        output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>' % settings.ADMIN_MEDIA_PREFIX)
    104104        if value:
    105             output.append(self.label_for_value(value))
     105            # TODO: "id_" is hard-coded here. This should instead use the correct
     106            # API to determine the ID dynamically.
     107            output.append(self.label_for_value(value, "id_%s" % name))
    106108        return mark_safe(u''.join(output))
    107109   
    108     def label_for_value(self, value):
    109         return '&nbsp;<strong>%s</strong>' % \
    110             truncate_words(self.rel.to.objects.get(pk=value), 14)
     110    def label_for_value(self, value, name):
     111        return '&nbsp;<strong id="view_lookup_%s">%s</strong>' % \
     112            (name, truncate_words(self.rel.to.objects.get(pk=value), 14))
    111113           
    112114class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
    113115    """
Back to Top