1 {% load i18n adminmedia %}
4 <div class="group tabular{% if inline_admin_formset.opts.classes %} {{ inline_admin_formset.opts.classes|join:" " }}{% endif %}"
5 id="{{ inline_admin_formset.formset.prefix }}-group" >
6 <h2 class="collapse-handler">{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
8 <li class="add-handler-container"><a href="javascript://" class="icon add-handler" title="{% trans 'Add Another' %}"> </a></li>
10 {{ inline_admin_formset.formset.management_form }}
11 {{ inline_admin_formset.formset.non_form_errors }}
13 <div class="module table">
14 <div class="module thead">
16 {% for field in inline_admin_formset.fields %}
17 {% if not field.widget.is_hidden %}
18 <div class="th {{ field.label|lower }}{% if field.required %} required{% endif %}">{{ field.label|capfirst }}</div>
21 <div class="th content_type">Content type</div>
22 <div class="th value">Value</div>
23 {% if inline_admin_formset.formset.can_delete %}<div class="th"> </div>{% endif %}
26 {% for inline_admin_form in inline_admin_formset %}
28 <div class="module tbody{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last %} empty-form{% endif %}"
29 id="{{ inline_admin_formset.formset.prefix }}{% if not forloop.last %}{{ forloop.counter0 }}{% else %}-empty{% endif %}">
30 {% if inline_admin_form.form.non_field_errors %}
31 <ul class="errorlist"><li>{{ inline_admin_form.form.non_field_errors }}</li></ul>
33 <h3 style="display: none;"><b>{{ inline_admin_formset.opts.verbose_name|title }} #{{ forloop.counter }}</b> {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}</h3>
35 {% for fieldset in inline_admin_form %}
36 {% for line in fieldset %}
37 {% for field in line %}
38 {% if field.is_hidden %} {{ field.field }} {% endif %}
44 {% for fieldset in inline_admin_form %}
45 {% for line in fieldset %}
46 {% for field in line %}
47 <div class="td {{ field.field.name }} {% if field.field.errors %} error{% endif %}">
48 {% if field.is_readonly %}
49 <p>{{ field.contents }}</p>
52 {{ field.field.errors.as_ul }}
58 {% with inline_admin_form.form.content_type as field %}<div class="td {{ field.name }}{% if field.errors %} error{% endif %}">{{ field }}{{ field.errors.as_ul }}</div>{% endwith %}
59 {% with inline_admin_form.form.value as field %}<div class="td {{ field.name }}{% if field.errors %} error{% endif %}">{{ field }}{{ field.errors.as_ul }}</div>{% endwith %}
60 <div class="td tools">
63 {% if inline_admin_form.show_url %}<li class="viewsite-link-container"><a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/" class="icon viewsite-link" title="{% trans 'View on Site' %}"> </a></li>{% endif %}
64 {% if inline_admin_formset.opts.sortable_field_name %}
65 <li class="drag-handler-container"><a href="javascript://" class="icon drag-handler" title="{% trans 'Move Item' %}"></a></li>
67 {% if inline_admin_formset.formset.can_delete %}<li class="delete-handler-container">{{ inline_admin_form.deletion_field.field }}<a href="javascript://" class="icon {% if inline_admin_form.original %}delete-handler{% else %}remove-handler{% endif %}" title="{% trans 'Remove' %}"> </a>{% endif %}
71 {{ inline_admin_form.fk_field.field }}
72 {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
77 <div class="module add-item">
78 <a href="javascript://" class="add-handler">{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}</a>
80 <li class="add-handler-container"><a href="javascript://" class="icon add-handler" title="{% trans 'Add Item' %}"> </a></li>
81 </ul><br clear="all" />
85 <script type="text/javascript">
87 $(document).ready(function($) {
89 $("#{{ inline_admin_formset.formset.prefix }}-group").inline({
90 prefix: "{{ inline_admin_formset.formset.prefix }}",
91 deleteCssClass: "delete-handler",
92 emptyCssClass: "empty-form",
93 onAdded: tabular_onAdded
96 {% if inline_admin_formset.opts.sortable_field_name %}
99 * uses onAdded() and onRemoved() of inline() call above
100 * uses sortable_updateFormIndex() and is_form_filled() from change_from.html
103 // hide sortable_field(_name) from form
104 // hide div.td.{{ field.name }}
105 var position_nodes = $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.td.{{ inline_admin_formset.opts.sortable_field_name }}");
106 position_nodes.hide();
108 // hide its header (div.th) too (hard)
109 // "div.th.{{ inline_admin_formset.opts.sortable_field_name }}" is not correct because
110 // its div.th.<field.label> (and not name, see line#18).
112 // so let's get the "position/idx" the first position div
113 var tabular_row = position_nodes.first().parent().children("div.td");
114 // get the "position" (== i) in the "table"
115 for (var i = 0; i < tabular_row.length; i++) {
116 if ($(tabular_row[i]).hasClass("{{ inline_admin_formset.opts.sortable_field_name }}")) break;
118 // we have the same order in the header of the "table"
119 // so delete the div at the "position" (== i)
120 var position_header = $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.th")[i];
122 $(position_header).hide()
126 var container = $("#{{ inline_admin_formset.formset.prefix }}-group > div.table"),
127 dynamic_forms = container.find("div.dynamic-form"),
132 // loop thru all inline forms
133 for (var i = 0; i < dynamic_forms.length; i++) {
134 curr_form = $(dynamic_forms[i]);
135 // the real position according to the sort_field(_name)
136 real_pos = curr_form.find("div.{{ inline_admin_formset.opts.sortable_field_name }}").find("input").val();
137 // if there is none it's an empty inline (=> we are at the end)
138 // TODO: klemens: maybe buggy. try continue?
139 if (!real_pos) continue;
141 real_pos = parseInt(real_pos, 10);
143 // check if real position is not equal to the CURRENT position in the dom
144 if (real_pos != container.find("div.dynamic-form").index(curr_form)) {
145 // move to correct postition
146 curr_form.insertBefore(container.find("div.dynamic-form")[real_pos]);
147 // to update the inline lables
154 $("#{{ inline_admin_formset.formset.prefix }}-group > div.table").sortable({
155 // drag&drop the inlines with the drag-handler only
156 handle: "a.drag-handler",
157 // very scary magic after drap&drop operations
158 // pretty similar to inline() widget's removeHandler()
159 // but removeHandler() can remove the current form and just reorder the rest
160 // if we would do the same after drag&drop we would loose some form values
161 // because while looping inputs would have the same names and maybe overwrite each other.
162 placeholder: 'ui-sortable-placeholder',
163 forcePlaceholderSize: true,
164 items: "div.dynamic-form",
166 start: function(evt, ui) {
168 ui.placeholder.height(ui.placeholder.height()-4);
169 //sadly we have to do this every time we start dragging
170 var template = "<div class='tr'>",
171 // minus 1 because we don't need the "sortable_field_name row"
172 len = ui.item.find("div.tr").children("div.td").length - 1;
174 for (var i = 0; i < len; i++) {
175 template += "<div class='td'></div>"
179 ui.placeholder.addClass("tbody module").append(template);
181 update: function(evt, ui) {
185 forceHelperSize: true,
186 containment: '#{{ inline_admin_formset.formset.prefix }}-group > div.table',
187 tolerance: 'pointer',
188 helper: function(evt, elem) {
189 var helper = $("<div class='module table' />");
190 helper.html(elem.clone());
195 // sets the new positions onSubmit (0 - n)
196 $("#{{ opts.module_name }}_form").bind("submit", function(){
197 var forms = $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.dynamic-form"),
200 for (var i = 0; i < forms.length; i++) {
203 if (is_form_filled(form)) {
204 form.find("div.{{ inline_admin_formset.opts.sortable_field_name }}").find("input").val(idx);