diff --git a/nested_inline/admin.py b/nested_inline/admin.py index 9ec6290..f7c6d37 100644 --- a/nested_inline/admin.py +++ b/nested_inline/admin.py @@ -25,7 +25,7 @@ class Media: css = { "all": ('admin/css/forms-nested.css',) } - js = ('admin/js/inlines-nested.js',) + js = ('admin/js/inlines-nested%s.js' % ('' if settings.DEBUG else '.min'),) def get_inline_instances(self, request, obj=None): inline_instances = [] @@ -245,6 +245,7 @@ def add_view(self, request, form_url='', extra_context=None): 'errors': helpers.AdminErrorList(form, formsets), 'app_label': opts.app_label, } + context.update(self.admin_site.each_context(request)) context.update(extra_context or {}) return self.render_change_form(request, context, form_url=form_url, add=True) @@ -342,6 +343,7 @@ def change_view(self, request, object_id, form_url='', extra_context=None): 'errors': helpers.AdminErrorList(form, formsets), 'app_label': opts.app_label, } + context.update(self.admin_site.each_context(request)) context.update(extra_context or {}) return self.render_change_form(request, context, change=True, obj=obj, form_url=form_url) diff --git a/nested_inline/static/admin/js/inlines-nested.js b/nested_inline/static/admin/js/inlines-nested.js index 1f4a949..6f62766 100644 --- a/nested_inline/static/admin/js/inlines-nested.js +++ b/nested_inline/static/admin/js/inlines-nested.js @@ -42,7 +42,7 @@ var showAddButton = get_max_forms(options.prefix) === '' || (get_max_forms(options.prefix) - get_no_forms(options.prefix)) > 0; if ($this.length && showAddButton) { var addButton; - if ($this.attr("tagName") == "TR") { + if ($this.prop("tagName") == "TR") { // If forms are laid out as table rows, insert the // "add" button in a new table row: var numCols = this.eq(-1).children().length; diff --git a/nested_inline/static/admin/js/inlines-nested.min.js b/nested_inline/static/admin/js/inlines-nested.min.js index bfdd991..fc5c865 100644 --- a/nested_inline/static/admin/js/inlines-nested.min.js +++ b/nested_inline/static/admin/js/inlines-nested.min.js @@ -1 +1 @@ -(function(e){function t(r,i,s,o){var u=e(false);var a=r.replace(/[-][0-9][-]/g,"-0-");var f=e("#"+a+"-group ."+a+"-0-nested-inline").not(".cloned");if(!f.length){f=e("#"+a+"-group ."+a+"-nested-inline").not(".cloned")}f.each(function(f,l){var c=e(this).attr("id").split("-group")[0];var h=c.replace(a+"-0",r+"-"+i);var p=e(l).clone();p.addClass("cloned");if(p.children().first().hasClass("tabular")){p.find(".form-row").not(".empty-form").remove();p.find(".nested-inline-row").remove();template_form=p.find("#"+c+"-empty");new_form=template_form.clone().removeClass(s.emptyCssClass).addClass("dynamic-"+h);new_form.insertBefore(template_form);var d=new_form.find("input");d.each(function(){var t=e(this);if(t.val()){t.removeAttr("value")}});n(p,c,h);p.find("#id_"+h+"-TOTAL_FORMS").val(1);p.find("#id_"+h+"-INITIAL_FORMS").val(0);var v=p.find(".add-row").text();p.find(".add-row").remove();p.find(".tabular.inline-related tbody tr."+h+"-not-nested").tabularFormset({prefix:h,adminStaticPrefix:s.adminStaticPrefix,addText:v,deleteText:s.deleteText});var m=t(h,0,s,false);if(m.length){p.find(".form-row").addClass("no-bottom-border")}m.each(function(){if(!e(this).next()){border_class=""}else{border_class=" no-bottom-border"}p.find("#"+h+"-empty").before(e('').html(e("",{colspan:"100%"}).html(e(this))))})}else{var m=t(h,0,s,true);p.find(".inline-related").not(".empty-form").remove();template_form=p.find("#"+c+"-empty");new_form=template_form.clone().removeClass(s.emptyCssClass).addClass("dynamic-"+h);new_form.insertBefore(template_form);var d=new_form.find("input");d.each(function(){var t=e(this);if(t.val()){t.removeAttr("value")}});new_form.find(".inline_label").text("#1");n(p,c,h);p.find("#id_"+h+"-TOTAL_FORMS").val(1);p.find("#id_"+h+"-INITIAL_FORMS").val(0);var v=p.find(".add-row").text();p.find(".add-row").remove();p.find(".inline-related").stackedFormset({prefix:h,adminStaticPrefix:s.adminStaticPrefix,addText:v,deleteText:s.deleteText});m.each(function(){new_form.append(e(this))})}if(o){p=p.add(e('
'))}if(u.length){u=u.add(p)}else{u=p}});return u}function n(t,n,i){t.attr("id",t.attr("id").replace(n,i));t.find("*").each(function(){if(e(this).attr("for")){e(this).attr("for",e(this).attr("for").replace(n,i))}if(e(this).attr("class")){e(this).attr("class",e(this).attr("class").replace(n,i))}if(this.id){this.id=this.id.replace(n,i)}if(this.name){this.name=this.name.replace(n,i)}});prefix_fix=t.find(".inline-related").first();nextIndex=r(i);if(prefix_fix.hasClass("tabular")){prefix_fix=prefix_fix.find(".form-row").first();prefix_fix.attr("id",prefix_fix.attr("id").replace("-empty","-"+nextIndex))}else{prefix_fix.attr("id",prefix_fix.attr("id").replace("-empty","-"+nextIndex))}prefix_fix.find("*").each(function(){if(e(this).attr("for")){e(this).attr("for",e(this).attr("for").replace("__prefix__","0"))}if(e(this).attr("class")){e(this).attr("class",e(this).attr("class").replace("__prefix__","0"))}if(this.id){this.id=this.id.replace("__prefix__","0")}if(this.name){this.name=this.name.replace("__prefix__","0")}})}function r(t){formset_prop=e("#id_"+t+"-TOTAL_FORMS");if(!formset_prop.length){return 0}return parseInt(formset_prop.attr("autocomplete","off").val())}function i(t,n){var i=r(t);if(n){e("#id_"+t+"-TOTAL_FORMS").attr("autocomplete","off").val(parseInt(i)+1)}else{e("#id_"+t+"-TOTAL_FORMS").attr("autocomplete","off").val(parseInt(i)-1)}}function s(t){var n=e("#id_"+t+"-MAX_NUM_FORMS").attr("autocomplete","off").val();if(typeof n=="undefined"){return""}return parseInt(n)}e.fn.formset=function(n){var o=e.extend({},e.fn.formset.defaults,n);var u=e(this);var a=u.parent();var f=function(t,n,r){var i=new RegExp("("+n+"-(\\d+|__prefix__))");var s=n+"-"+r;if(e(t).attr("for")){e(t).attr("for",e(t).attr("for").replace(i,s))}if(t.id){t.id=t.id.replace(i,s)}if(t.name){t.name=t.name.replace(i,s)}};var l=r(o.prefix);u.each(function(t){e(this).not("."+o.emptyCssClass).addClass(o.formCssClass)});var c=s(o.prefix)===""||s(o.prefix)-r(o.prefix)>0;if(u.length&&c){var h;if(u.attr("tagName")=="TR"){var p=this.eq(-1).children().length;a.append(''+o.addText+"");h=a.find("tr:last a")}else{u.filter(":last").after('
'+o.addText+"
");h=u.filter(":last").next().find("a")}h.click(function(n){n.preventDefault();var u=r(o.prefix);var a=e("#"+o.prefix+"-empty");var l=a.clone(true);l.removeClass(o.emptyCssClass).addClass(o.formCssClass).attr("id",o.prefix+"-"+u);if(l.is("tr")){l.children(":last").append('
'+o.deleteText+"
")}else if(l.is("ul")||l.is("ol")){l.append('
  • '+o.deleteText+"
  • ")}else{l.children(":first").append(''+o.deleteText+"")}l.find("*").each(function(){f(this,o.prefix,u)});l.insertBefore(e(a));i(o.prefix,true);if(s(o.prefix)!==""&&s(o.prefix)-r(o.prefix)<=0){h.parent().hide()}l.find("a."+o.deleteCssClass).click(function(t){t.preventDefault();var n=e(this).parents("."+o.formCssClass);var r=n.parent();while(n.next().hasClass("nested-inline-row")){n.next().remove()}n.remove();i(o.prefix,false);if(o.removed){o.removed(r)}});if(l.is("tr")){nested_formsets=t(o.prefix,u,o,false);if(nested_formsets.length){l.addClass("no-bottom-border")}nested_formsets.each(function(){if(!e(this).next()){border_class=""}else{border_class=" no-bottom-border"}e('').html(e("",{colspan:"100%"}).html(e(this))).insertBefore(e(a))})}else{nested_formsets=t(o.prefix,u,o,true);nested_formsets.each(function(){l.append(e(this))})}if(o.added){o.added(l)}u=u+1})}return this};e.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null};e.fn.tabularFormset=function(t){var n=e(this);var r=function(t){row_number=0;e(n.selector).not(".add-row").removeClass("row1 row2").each(function(){e(this).addClass("row"+(row_number%2+1));next=e(this).next();while(next.hasClass("nested-inline-row")){next.addClass("row"+(row_number%2+1));next=next.next()}row_number=row_number+1})};var i=function(){if(typeof DateTimeShortcuts!="undefined"){e(".datetimeshortcuts").remove();DateTimeShortcuts.init()}};var s=function(){if(typeof SelectFilter!="undefined"){e(".selectfilter").each(function(e,n){var r=n.name.split("-");SelectFilter.init(n.id,r[r.length-1],false,t.adminStaticPrefix)});e(".selectfilterstacked").each(function(e,n){var r=n.name.split("-");SelectFilter.init(n.id,r[r.length-1],true,t.adminStaticPrefix)})}};var o=function(t){t.find(".prepopulated_field").each(function(){var n=e(this),r=n.find("input, select, textarea"),i=r.data("dependency_list")||[],s=[];e.each(i,function(e,n){s.push("#"+t.find(".field-"+n).find("input, select, textarea").attr("id"))});if(s.length){r.prepopulate(s,r.attr("maxlength"))}})};n.formset({prefix:t.prefix,addText:t.addText,formCssClass:"dynamic-"+t.prefix,deleteCssClass:"inline-deletelink",deleteText:t.deleteText,emptyCssClass:"empty-form",removed:r,added:function(e){o(e);i();s();r(e)}});return n};e.fn.stackedFormset=function(t){var n=e(this);var r=function(t){t.children(".inline-related").not(".empty-form").children("h3").find(".inline_label").each(function(t){var n=t+1;e(this).html(e(this).html().replace(/(#\d+)/g,"#"+n))})};var i=function(){if(typeof DateTimeShortcuts!="undefined"){e(".datetimeshortcuts").remove();DateTimeShortcuts.init()}};var s=function(){if(typeof SelectFilter!="undefined"){e(".selectfilter").each(function(e,n){var r=n.name.split("-");SelectFilter.init(n.id,r[r.length-1],false,t.adminStaticPrefix)});e(".selectfilterstacked").each(function(e,n){var r=n.name.split("-");SelectFilter.init(n.id,r[r.length-1],true,t.adminStaticPrefix)})}};var o=function(t){t.find(".prepopulated_field").each(function(){var n=e(this),r=n.find("input, select, textarea"),i=r.data("dependency_list")||[],s=[];e.each(i,function(e,n){s.push("#"+t.find(".form-row .field-"+n).find("input, select, textarea").attr("id"))});if(s.length){r.prepopulate(s,r.attr("maxlength"))}})};n.formset({prefix:t.prefix,addText:t.addText,formCssClass:"dynamic-"+t.prefix,deleteCssClass:"inline-deletelink",deleteText:t.deleteText,emptyCssClass:"empty-form",removed:r,added:function(e){o(e);i();s();r(e.parent())}});return n};})(django.jQuery) +!function(e){function t(r,a,n,s){var d=e(!1),l=r.replace(/[-][0-9][-]/g,"-0-"),f=e("#"+l+"-group ."+l+"-0-nested-inline").not(".cloned");return f.length||(f=e("#"+l+"-group ."+l+"-nested-inline").not(".cloned")),f.each(function(f,o){var c=e(this).attr("id").split("-group")[0],p=c.replace(l+"-0",r+"-"+a),m=e(o).clone();if(m.addClass("cloned"),m.children().first().hasClass("tabular")){m.find(".form-row").not(".empty-form").remove(),m.find(".nested-inline-row").remove(),template_form=m.find("#"+c+"-empty"),new_form=template_form.clone().removeClass(n.emptyCssClass).addClass("dynamic-"+p),new_form.insertBefore(template_form);var h=new_form.find("input");h.each(function(){var t=e(this);t.val()&&t.removeAttr("value")}),i(m,c,p),m.find("#id_"+p+"-TOTAL_FORMS").val(1),m.find("#id_"+p+"-INITIAL_FORMS").val(0);var x=m.find(".add-row").text();m.find(".add-row").remove(),m.find(".tabular.inline-related tbody tr."+p+"-not-nested").tabularFormset({prefix:p,adminStaticPrefix:n.adminStaticPrefix,addText:x,deleteText:n.deleteText});var u=t(p,0,n,!1);u.length&&m.find(".form-row").addClass("no-bottom-border"),u.each(function(){e(this).next()?border_class=" no-bottom-border":border_class="",m.find("#"+p+"-empty").before(e('').html(e("",{colspan:"100%"}).html(e(this))))})}else{var u=t(p,0,n,!0);m.find(".inline-related").not(".empty-form").remove(),template_form=m.find("#"+c+"-empty"),new_form=template_form.clone().removeClass(n.emptyCssClass).addClass("dynamic-"+p),new_form.insertBefore(template_form);var h=new_form.find("input");h.each(function(){var t=e(this);t.val()&&t.removeAttr("value")}),new_form.find(".inline_label").text("#1"),i(m,c,p),m.find("#id_"+p+"-TOTAL_FORMS").val(1),m.find("#id_"+p+"-INITIAL_FORMS").val(0);var x=m.find(".add-row").text();m.find(".add-row").remove(),m.find(".inline-related").stackedFormset({prefix:p,adminStaticPrefix:n.adminStaticPrefix,addText:x,deleteText:n.deleteText}),u.each(function(){new_form.append(e(this))})}s&&(m=m.add(e('
    '))),d=d.length?d.add(m):m}),d}function i(t,i,a){t.attr("id",t.attr("id").replace(i,a)),t.find("*").each(function(){e(this).attr("for")&&e(this).attr("for",e(this).attr("for").replace(i,a)),e(this).attr("class")&&e(this).attr("class",e(this).attr("class").replace(i,a)),this.id&&(this.id=this.id.replace(i,a)),this.name&&(this.name=this.name.replace(i,a))}),prefix_fix=t.find(".inline-related").first(),nextIndex=r(a),prefix_fix.hasClass("tabular")?(prefix_fix=prefix_fix.find(".form-row").first(),prefix_fix.attr("id",prefix_fix.attr("id").replace("-empty","-"+nextIndex))):prefix_fix.attr("id",prefix_fix.attr("id").replace("-empty","-"+nextIndex)),prefix_fix.find("*").each(function(){e(this).attr("for")&&e(this).attr("for",e(this).attr("for").replace("__prefix__","0")),e(this).attr("class")&&e(this).attr("class",e(this).attr("class").replace("__prefix__","0")),this.id&&(this.id=this.id.replace("__prefix__","0")),this.name&&(this.name=this.name.replace("__prefix__","0"))})}function r(t){return formset_prop=e("#id_"+t+"-TOTAL_FORMS"),formset_prop.length?parseInt(formset_prop.attr("autocomplete","off").val()):0}function a(t,i){var a=r(t);e("#id_"+t+"-TOTAL_FORMS").attr("autocomplete","off").val(i?parseInt(a)+1:parseInt(a)-1)}function n(t){var i=e("#id_"+t+"-MAX_NUM_FORMS").attr("autocomplete","off").val();return"undefined"==typeof i?"":parseInt(i)}e.fn.formset=function(i){{var s=e.extend({},e.fn.formset.defaults,i),d=e(this),l=d.parent(),f=function(t,i,r){var a=new RegExp("("+i+"-(\\d+|__prefix__))"),n=i+"-"+r;e(t).attr("for")&&e(t).attr("for",e(t).attr("for").replace(a,n)),t.id&&(t.id=t.id.replace(a,n)),t.name&&(t.name=t.name.replace(a,n))};r(s.prefix)}d.each(function(t){e(this).not("."+s.emptyCssClass).addClass(s.formCssClass)});var o=""===n(s.prefix)||n(s.prefix)-r(s.prefix)>0;if(d.length&&o){var c;if("TR"==d.prop("tagName")){var p=this.eq(-1).children().length;l.append(''+s.addText+""),c=l.find("tr:last a")}else d.filter(":last").after('"),c=d.filter(":last").next().find("a");c.click(function(i){i.preventDefault();var d=r(s.prefix),l=e("#"+s.prefix+"-empty"),o=l.clone(!0);o.removeClass(s.emptyCssClass).addClass(s.formCssClass).attr("id",s.prefix+"-"+d),o.is("tr")?o.children(":last").append('
    '+s.deleteText+"
    "):o.is("ul")||o.is("ol")?o.append('
  • '+s.deleteText+"
  • "):o.children(":first").append(''+s.deleteText+""),o.find("*").each(function(){f(this,s.prefix,d)}),o.insertBefore(e(l)),a(s.prefix,!0),""!==n(s.prefix)&&n(s.prefix)-r(s.prefix)<=0&&c.parent().hide(),o.find("a."+s.deleteCssClass).click(function(t){t.preventDefault();for(var i=e(this).parents("."+s.formCssClass),r=i.parent();i.next().hasClass("nested-inline-row");)i.next().remove();i.remove(),a(s.prefix,!1),s.removed&&s.removed(r)}),o.is("tr")?(nested_formsets=t(s.prefix,d,s,!1),nested_formsets.length&&o.addClass("no-bottom-border"),nested_formsets.each(function(){e(this).next()?border_class=" no-bottom-border":border_class="",e('').html(e("",{colspan:"100%"}).html(e(this))).insertBefore(e(l))})):(nested_formsets=t(s.prefix,d,s,!0),nested_formsets.each(function(){o.append(e(this))})),s.added&&s.added(o),d+=1})}return this},e.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null},e.fn.tabularFormset=function(t){var i=e(this),r=function(t){row_number=0,e(i.selector).not(".add-row").removeClass("row1 row2").each(function(){for(e(this).addClass("row"+(row_number%2+1)),next=e(this).next();next.hasClass("nested-inline-row");)next.addClass("row"+(row_number%2+1)),next=next.next();row_number+=1})},a=function(){"undefined"!=typeof DateTimeShortcuts&&(e(".datetimeshortcuts").remove(),DateTimeShortcuts.init())},n=function(){"undefined"!=typeof SelectFilter&&(e(".selectfilter").each(function(e,i){var r=i.name.split("-");SelectFilter.init(i.id,r[r.length-1],!1,t.adminStaticPrefix)}),e(".selectfilterstacked").each(function(e,i){var r=i.name.split("-");SelectFilter.init(i.id,r[r.length-1],!0,t.adminStaticPrefix)}))},s=function(t){t.find(".prepopulated_field").each(function(){var i=e(this),r=i.find("input, select, textarea"),a=r.data("dependency_list")||[],n=[];e.each(a,function(e,i){n.push("#"+t.find(".field-"+i).find("input, select, textarea").attr("id"))}),n.length&&r.prepopulate(n,r.attr("maxlength"))})};return i.formset({prefix:t.prefix,addText:t.addText,formCssClass:"dynamic-"+t.prefix,deleteCssClass:"inline-deletelink",deleteText:t.deleteText,emptyCssClass:"empty-form",removed:r,added:function(e){s(e),a(),n(),r(e)}}),i},e.fn.stackedFormset=function(t){var i=e(this),r=function(t){t.children(".inline-related").not(".empty-form").children("h3").find(".inline_label").each(function(t){var i=t+1;e(this).html(e(this).html().replace(/(#\d+)/g,"#"+i))})},a=function(){"undefined"!=typeof DateTimeShortcuts&&(e(".datetimeshortcuts").remove(),DateTimeShortcuts.init())},n=function(){"undefined"!=typeof SelectFilter&&(e(".selectfilter").each(function(e,i){var r=i.name.split("-");SelectFilter.init(i.id,r[r.length-1],!1,t.adminStaticPrefix)}),e(".selectfilterstacked").each(function(e,i){var r=i.name.split("-");SelectFilter.init(i.id,r[r.length-1],!0,t.adminStaticPrefix)}))},s=function(t){t.find(".prepopulated_field").each(function(){var i=e(this),r=i.find("input, select, textarea"),a=r.data("dependency_list")||[],n=[];e.each(a,function(e,i){n.push("#"+t.find(".form-row .field-"+i).find("input, select, textarea").attr("id"))}),n.length&&r.prepopulate(n,r.attr("maxlength"))})};return i.formset({prefix:t.prefix,addText:t.addText,formCssClass:"dynamic-"+t.prefix,deleteCssClass:"inline-deletelink",deleteText:t.deleteText,emptyCssClass:"empty-form",removed:r,added:function(e){s(e),a(),n(),r(e.parent())}}),i}}(django.jQuery); \ No newline at end of file diff --git a/nested_inline/templates/admin/edit_inline/tabular-nested.html b/nested_inline/templates/admin/edit_inline/tabular-nested.html index d071e03..d27749f 100644 --- a/nested_inline/templates/admin/edit_inline/tabular-nested.html +++ b/nested_inline/templates/admin/edit_inline/tabular-nested.html @@ -85,7 +85,7 @@

    {{ recursive_formset.opts.verbose_name_plural|capfirst }}