related-widget-wrapper.js 993 B

12345678910111213141516171819202122232425
  1. django.jQuery(document).ready(function() {
  2. jet.jQuery(function($){
  3. function updateLinks() {
  4. var $this = $(this);
  5. var siblings = $this.nextAll('.change-related, .delete-related');
  6. if (!siblings.length) return;
  7. var value = $this.val();
  8. if (value) {
  9. siblings.each(function(){
  10. var elm = $(this);
  11. elm.attr('href', elm.attr('data-href-template').replace('__fk__', value));
  12. });
  13. } else siblings.removeAttr('href');
  14. }
  15. var container = $(document);
  16. container.on('change', '.related-widget-wrapper select', updateLinks);
  17. container.find('.related-widget-wrapper select').each(updateLinks);
  18. container.on('click', '.related-widget-wrapper-link', function(event){
  19. if (this.href) {
  20. showRelatedObjectPopup(this);
  21. }
  22. event.preventDefault();
  23. });
  24. });
  25. });