Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / django / contrib / admin / templates / admin / edit_inline / tabular.html @ 1a305335

History | View | Annotate | Download (6.17 KB)

1
{% load i18n admin_static admin_modify %}
2
<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
3
  <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
4
{{ inline_admin_formset.formset.management_form }}
5
<fieldset class="module">
6
   <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
7
   {{ inline_admin_formset.formset.non_form_errors }}
8
   <table>
9
     <thead><tr>
10
     {% for field in inline_admin_formset.fields %}
11
       {% if not field.widget.is_hidden %}
12
         <th{% if forloop.first %} colspan="2"{% endif %}{% if field.required %} class="required"{% endif %}>{{ field.label|capfirst }}
13
         {% if field.help_text %}&nbsp;<img src="{% static "admin/img/icon-unknown.gif" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}" />{% endif %}
14
         </th>
15
       {% endif %}
16
     {% endfor %}
17
     {% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
18
     </tr></thead>
19

    
20
     <tbody>
21
     {% for inline_admin_form in inline_admin_formset %}
22
        {% if inline_admin_form.form.non_field_errors %}
23
        <tr><td colspan="{{ inline_admin_form|cell_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
24
        {% endif %}
25
        <tr class="form-row {% cycle "row1" "row2" %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}{% if forloop.last %} empty-form{% endif %}"
26
             id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
27
        <td class="original">
28
          {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
29
          {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
30
          {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
31
            </p>{% endif %}
32
          {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
33
          {{ inline_admin_form.fk_field.field }}
34
          {% spaceless %}
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 %}
39
              {% endfor %}
40
            {% endfor %}
41
          {% endfor %}
42
          {% endspaceless %}
43
        </td>
44
        {% for fieldset in inline_admin_form %}
45
          {% for line in fieldset %}
46
            {% for field in line %}
47
              <td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
48
              {% if field.is_readonly %}
49
                  <p>{{ field.contents }}</p>
50
              {% else %}
51
                  {{ field.field.errors.as_ul }}
52
                  {{ field.field }}
53
              {% endif %}
54
              </td>
55
            {% endfor %}
56
          {% endfor %}
57
        {% endfor %}
58
        {% if inline_admin_formset.formset.can_delete %}
59
          <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
60
        {% endif %}
61
        </tr>
62
     {% endfor %}
63
     </tbody>
64
   </table>
65
</fieldset>
66
  </div>
67
</div>
68

    
69
<script type="text/javascript">
70
(function($) {
71
    $(document).ready(function($) {
72
        var rows = "#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr";
73
        var alternatingRows = function(row) {
74
            $(rows).not(".add-row").removeClass("row1 row2")
75
                .filter(":even").addClass("row1").end()
76
                .filter(rows + ":odd").addClass("row2");
77
        }
78
        var reinitDateTimeShortCuts = function() {
79
            // Reinitialize the calendar and clock widgets by force
80
            if (typeof DateTimeShortcuts != "undefined") {
81
                $(".datetimeshortcuts").remove();
82
                DateTimeShortcuts.init();
83
            }
84
        }
85
        var updateSelectFilter = function() {
86
            // If any SelectFilter widgets are a part of the new form,
87
            // instantiate a new SelectFilter instance for it.
88
            if (typeof SelectFilter != "undefined"){
89
                $(".selectfilter").each(function(index, value){
90
                  var namearr = value.name.split('-');
91
                  SelectFilter.init(value.id, namearr[namearr.length-1], false, "{% static "admin/" %}");
92
                });
93
                $(".selectfilterstacked").each(function(index, value){
94
                  var namearr = value.name.split('-');
95
                  SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% static "admin/" %}");
96
                });
97
            }
98
        }
99
        var initPrepopulatedFields = function(row) {
100
            row.find('.prepopulated_field').each(function() {
101
                var field = $(this);
102
                var input = field.find('input, select, textarea');
103
                var dependency_list = input.data('dependency_list') || [];
104
                var dependencies = [];
105
                $.each(dependency_list, function(i, field_name) {
106
                  dependencies.push('#' + row.find('.field-' + field_name).find('input, select, textarea').attr('id'));
107
                });
108
                if (dependencies.length) {
109
                    input.prepopulate(dependencies, input.attr('maxlength'));
110
                }
111
            });
112
        }
113
        $(rows).formset({
114
            prefix: "{{ inline_admin_formset.formset.prefix }}",
115
            addText: "{% blocktrans with verbose_name=inline_admin_formset.opts.verbose_name|title %}Add another {{ verbose_name }}{% endblocktrans %}",
116
            formCssClass: "dynamic-{{ inline_admin_formset.formset.prefix }}",
117
            deleteCssClass: "inline-deletelink",
118
            deleteText: "{% trans "Remove" %}",
119
            emptyCssClass: "empty-form",
120
            removed: alternatingRows,
121
            added: (function(row) {
122
                initPrepopulatedFields(row);
123
                reinitDateTimeShortCuts();
124
                updateSelectFilter();
125
                alternatingRows(row);
126
            })
127
        });
128
    });
129
})(django.jQuery);
130
</script>