X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/f50cd63e40d7dfc9ffb51b679748b0003fddb019..82b08f79564159d7acbcaf255ed1ac1fb4882e64:/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html?ds=inline diff --git a/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html b/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html index ccead57..25c1ac4 100644 --- a/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html +++ b/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html @@ -1,4 +1,4 @@ -{% load i18n adminmedia %} +{% load i18n adminmedia grp_tags %}
(function($) { - $(document).ready(function($) { - - $("#{{ inline_admin_formset.formset.prefix }}-group").grp_inline({ - prefix: "{{ inline_admin_formset.formset.prefix }}", - onBeforeAdded: function(inline) {}, - onAfterAdded: function(form) { - grappelli.reinitDateTimeFields(form); - grappelli.updateSelectFilter(form); - form.find("input.vForeignKeyRawIdAdminField").grp_related_fk({lookup_url:"{% url grp_related_lookup %}"}); - form.find("input.vManyToManyRawIdAdminField").grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"}); - form.find("input[name*='object_id'][name$='id']").grp_related_generic({lookup_url:"{% url grp_related_lookup %}"}); - }, - }); - - {% if inline_admin_formset.opts.sortable_field_name %} - $("#{{ inline_admin_formset.formset.prefix }}-group > div.table").sortable({ - handle: "a.drag-handler", - items: "div.dynamic-form", - axis: "y", - appendTo: 'body', - forceHelperSize: true, - containment: '#{{ inline_admin_formset.formset.prefix }}-group > div.table', - tolerance: 'pointer', - }); - $("#{{ opts.module_name }}_form").bind("submit", function(){ - var sortable_field_name = "{{ inline_admin_formset.opts.sortable_field_name }}"; - var i = 0; - $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.dynamic-form").each(function(){ - var fields = $(this).find("div.td :input[value]"); - if (fields.serialize()) { - $(this).find("input[name$='"+sortable_field_name+"']").val(i); - i++; - } - }); - }); - {% endif %} - - }); + $(document).ready(function($) { + + var prefix = "{{ inline_admin_formset.formset.prefix }}"; + var related_lookup_fields_fk = {% get_related_lookup_fields_fk inline_admin_formset.opts %}; + var related_lookup_fields_m2m = {% get_related_lookup_fields_m2m inline_admin_formset.opts %}; + var related_lookup_fields_generic = {% get_related_lookup_fields_generic inline_admin_formset.opts %}; + $.each(related_lookup_fields_fk, function() { + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table") + .find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_fk({lookup_url:"{% url grp_related_lookup %}"}); + }); + $.each(related_lookup_fields_m2m, function() { + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table") + .find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"}); + }); + $.each(related_lookup_fields_generic, function() { + var content_type = this[0], + object_id = this[1]; + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table") + .find("input[name^='" + prefix + "'][name$='" + this[1] + "']") + .each(function() { + var i = $(this).attr("id").match(/-\d+-/); + if (i) { + var ct_id = "#id_" + prefix + i[0] + content_type, + obj_id = "#id_" + prefix + i[0] + object_id; + $(this).grp_related_generic({content_type:ct_id, object_id:obj_id, lookup_url:"{% url grp_related_lookup %}"}); + } + }); + }); + + $("#{{ inline_admin_formset.formset.prefix }}-group").grp_inline({ + prefix: "{{ inline_admin_formset.formset.prefix }}", + onBeforeAdded: function(inline) {}, + onAfterAdded: function(form) { + grappelli.reinitDateTimeFields(form); + grappelli.updateSelectFilter(form); + $.each(related_lookup_fields_fk, function() { + form.find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_fk({lookup_url:"{% url grp_related_lookup %}"}); + }); + $.each(related_lookup_fields_m2m, function() { + form.find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"}); + }); + $.each(related_lookup_fields_generic, function() { + var content_type = this[0], + object_id = this[1]; + form.find("input[name^='" + prefix + "'][name$='" + this[1] + "']") + .each(function() { + var i = $(this).attr("id").match(/-\d+-/); + if (i) { + var ct_id = "#id_" + prefix + i[0] + content_type, + obj_id = "#id_" + prefix + i[0] + object_id; + $(this).grp_related_generic({content_type:ct_id, object_id:obj_id, lookup_url:"{% url grp_related_lookup %}"}); + } + }); + }); + }, + }); + + {% if inline_admin_formset.opts.sortable_field_name %} + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table").sortable({ + handle: "a.drag-handler", + items: "div.dynamic-form", + axis: "y", + appendTo: 'body', + forceHelperSize: true, + containment: '#{{ inline_admin_formset.formset.prefix }}-group > div.table', + tolerance: 'pointer', + }); + $("#{{ opts.module_name }}_form").bind("submit", function(){ + var sortable_field_name = "{{ inline_admin_formset.opts.sortable_field_name }}"; + var i = 0; + $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.dynamic-form").each(function(){ + var fields = $(this).find("div.td :input[value]"); + if (fields.serialize()) { + $(this).find("input[name$='"+sortable_field_name+"']").val(i); + i++; + } + }); + }); + {% endif %} + + }); })(django.jQuery);