Ticket #14193: 0001-Fix-for-14193-respect-given-order-when-creating-prep.patch

File 0001-Fix-for-14193-respect-given-order-when-creating-prep.patch, 5.7 KB (added by bmihelac, 14 years ago)
  • django/contrib/admin/media/js/prepopulate.js

    From 7c04f8e200043384bf0c3ed07e6caf7b5c3324d4 Mon Sep 17 00:00:00 2001
    From: Bojan Mihelac <bmihelac@mihelac.org>
    Date: Mon, 30 Aug 2010 16:25:34 +0200
    Subject: [PATCH] Fix for #14193, respect given order when creating prepopulated_fields
    
    ---
     django/contrib/admin/media/js/prepopulate.js       |   14 +++++++-------
     django/contrib/admin/media/js/prepopulate.min.js   |    2 +-
     .../admin/templates/admin/edit_inline/stacked.html |    5 ++++-
     .../admin/templates/admin/edit_inline/tabular.html |    5 ++++-
     .../templates/admin/prepopulated_fields_js.html    |    2 +-
     5 files changed, 17 insertions(+), 11 deletions(-)
    
    diff --git a/django/contrib/admin/media/js/prepopulate.js b/django/contrib/admin/media/js/prepopulate.js
    index 09483bb..24f24f9 100644
    a b  
    44            Depends on urlify.js
    55            Populates a selected field with the values of the dependent fields,
    66            URLifies and shortens the string.
    7             dependencies - selected jQuery object of dependent fields
     7            dependencies - array of dependent fields id's
    88            maxLength - maximum length of the URLify'd string
    99        */
    1010        return this.each(function() {
     
    2020                if (field.data('_changed') == true) return;
    2121 
    2222                var values = [];
    23                 dependencies.each(function() {
    24                     if ($(this).val().length > 0) {
    25                         values.push($(this).val());
    26                     }
    27                 });
     23                $.each(dependencies, function(i, field) {
     24                  if ($(field).val().length > 0) {
     25                      values.push($(field).val());
     26                  }
     27                })
    2828                field.val(URLify(values.join(' '), maxLength));
    2929            };
    3030
    31             dependencies.keyup(populate).change(populate).focus(populate);
     31            $(dependencies.join(',')).keyup(populate).change(populate).focus(populate);
    3232        });
    3333    };
    3434})(django.jQuery);
  • django/contrib/admin/media/js/prepopulate.min.js

    diff --git a/django/contrib/admin/media/js/prepopulate.min.js b/django/contrib/admin/media/js/prepopulate.min.js
    index f1ca297..98fdc93 100644
    a b  
    1 (function(b){b.fn.prepopulate=function(d,f){return this.each(function(){var a=b(this);a.data("_changed",false);a.change(function(){a.data("_changed",true)});var c=function(){if(a.data("_changed")!=true){var e=[];d.each(function(){b(this).val().length>0&&e.push(b(this).val())});a.val(URLify(e.join(" "),f))}};d.keyup(c).change(c).focus(c)})}})(django.jQuery);
     1(function(a){a.fn.prepopulate=function(d,g){return this.each(function(){var b=a(this);b.data("_changed",false);b.change(function(){b.data("_changed",true)});var c=function(){if(b.data("_changed")!=true){var e=[];a.each(d,function(h,f){a(f).val().length>0&&e.push(a(f).val())});b.val(URLify(e.join(" "),g))}};a(d.join(",")).keyup(c).change(c).focus(c)})}})(django.jQuery);
     2 No newline at end of file
  • django/contrib/admin/templates/admin/edit_inline/stacked.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html
    index 1ecb790..f1e338f 100644
    a b  
    5353                var field = $(this);
    5454                var input = field.find('input, select, textarea');
    5555                var dependency_list = input.data('dependency_list') || [];
    56                 var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea');
     56                var dependencies = [];
     57                $.each(dependency_list, function(i, field_name) {
     58                  dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id'));
     59                });
    5760                if (dependencies.length) {
    5861                    input.prepopulate(dependencies, input.attr('maxlength'));
    5962                }
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
    index 35dea39..a5b1a89 100644
    a b  
    9999                var field = $(this);
    100100                var input = field.find('input, select, textarea');
    101101                var dependency_list = input.data('dependency_list') || [];
    102                 var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea');
     102                var dependencies = [];
     103                $.each(dependency_list, function(i, field_name) {
     104                  dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id'));
     105                });
    103106                if (dependencies.length) {
    104107                    input.prepopulate(dependencies, input.attr('maxlength'));
    105108                }
  • django/contrib/admin/templates/admin/prepopulated_fields_js.html

    diff --git a/django/contrib/admin/templates/admin/prepopulated_fields_js.html b/django/contrib/admin/templates/admin/prepopulated_fields_js.html
    index 4aa6380..43ef5ba 100644
    a b  
    1717
    1818    $('.empty-form .{{ field.field.name }}').addClass('prepopulated_field');
    1919    $(field.id).data('dependency_list', field['dependency_list'])
    20                .prepopulate($(field['dependency_ids'].join(',')), field.maxLength);
     20               .prepopulate(field['dependency_ids'], field.maxLength);
    2121{% endfor %}
    2222})(django.jQuery);
    2323</script>
Back to Top