- Author:
- nasp
- Posted:
- October 7, 2011
- Language:
- JavaScript
- Version:
- 1.3
- Score:
- 0 (after 0 ratings)
Here's the python code to produce an admin related widget with the edit and delete link also.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | function dismissEditRelatedPopup(win, objId, newRepr) {
objId = html_unescape(objId);
newRepr = html_unescape(newRepr);
var name = windowname_to_id(win.name).replace(/^edit_/, '');;
var elem = document.getElementById(name);
if (elem) {
var opts = elem.options,
l = opts.length;
for (var i = 0; i < l; i++) {
if (opts[i] && opts[i].value == objId) {
opts[i].innerHTML = newRepr;
}
}
}
win.close();
};
if (!dismissAddAnotherPopup.original) {
var originalDismissAddAnotherPopup = dismissAddAnotherPopup;
dismissAddAnotherPopup = function(win, newId, newRepr) {
originalDismissAddAnotherPopup(win, newId, newRepr);
newId = html_unescape(newId);
newRepr = html_unescape(newRepr);
var id = windowname_to_id(win.name);
$('#' + id).trigger('change');
};
dismissAddAnotherPopup.original = originalDismissAddAnotherPopup;
}
django.jQuery(document).ready(function() {
var $ = $ || jQuery || django.jQuery,
relatedWidgetCSSSelector = '.related-widget-wrapper-change-link, .related-widget-wrapper-delete-link',
hrefTemplateAttr = 'data-href-template';
$('.related-widget-wrapper').live('change', function(){
var siblings = $(this).nextAll(relatedWidgetCSSSelector);
if (!siblings.length) return;
if (this.value) {
var val = this.value;
siblings.each(function(){
var elm = $(this);
elm.attr('href', interpolate(elm.attr(hrefTemplateAttr), [val]));
});
} else siblings.removeAttr('href');
});
$('.related-widget-wrapper-link').live('click', function(){
if (this.href) {
return showAddAnotherPopup(this);
} else return false;
});
});
|
More like this
- Django Collapsed Stacked Inlines by applecat 1 year, 7 months ago
- Django Collapsed Stacked Inlines by mkarajohn 3 years, 9 months ago
- Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 5 months ago
- Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 6 months ago
- Django admin inline ordering - javascript only implementation by ojhilt 11 years, 10 months ago
Comments
Please login first before commenting.