PageRenderTime 118ms CodeModel.GetById 58ms app.highlight 8ms RepoModel.GetById 32ms app.codeStats 0ms

/django/contrib/admin/templates/admin/edit_inline/tabular.html

https://code.google.com/p/mango-py/
HTML | 128 lines | 126 code | 2 blank | 0 comment | 0 complexity | 7ac2e71bc8da08681c2cc290711b4750 MD5 | raw file
  1{% load i18n adminmedia 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 }}</th>
 13       {% endif %}
 14     {% endfor %}
 15     {% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
 16     </tr></thead>
 17
 18     <tbody>
 19     {% for inline_admin_form in inline_admin_formset %}
 20        {% if inline_admin_form.form.non_field_errors %}
 21        <tr><td colspan="{{ inline_admin_form|cell_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
 22        {% endif %}
 23        <tr class="{% cycle "row1" "row2" %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}{% if forloop.last %} empty-form{% endif %}"
 24             id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
 25        <td class="original">
 26          {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
 27          {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
 28          {% 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 %}
 29            </p>{% endif %}
 30          {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
 31          {{ inline_admin_form.fk_field.field }}
 32          {% spaceless %}
 33          {% for fieldset in inline_admin_form %}
 34            {% for line in fieldset %}
 35              {% for field in line %}
 36                {% if field.is_hidden %} {{ field.field }} {% endif %}
 37              {% endfor %}
 38            {% endfor %}
 39          {% endfor %}
 40          {% endspaceless %}
 41        </td>
 42        {% for fieldset in inline_admin_form %}
 43          {% for line in fieldset %}
 44            {% for field in line %}
 45              <td class="{{ field.field.name }}">
 46              {% if field.is_readonly %}
 47                  <p>{{ field.contents }}</p>
 48              {% else %}
 49                  {{ field.field.errors.as_ul }}
 50                  {{ field.field }}
 51              {% endif %}
 52              </td>
 53            {% endfor %}
 54          {% endfor %}
 55        {% endfor %}
 56        {% if inline_admin_formset.formset.can_delete %}
 57          <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
 58        {% endif %}
 59        </tr>
 60     {% endfor %}
 61     </tbody>
 62   </table>
 63</fieldset>
 64  </div>
 65</div>
 66
 67<script type="text/javascript">
 68(function($) {
 69    $(document).ready(function($) {
 70        var rows = "#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr";
 71        var alternatingRows = function(row) {
 72            $(rows).not(".add-row").removeClass("row1 row2")
 73                .filter(":even").addClass("row1").end()
 74                .filter(rows + ":odd").addClass("row2");
 75        }
 76        var reinitDateTimeShortCuts = function() {
 77            // Reinitialize the calendar and clock widgets by force
 78            if (typeof DateTimeShortcuts != "undefined") {
 79                $(".datetimeshortcuts").remove();
 80                DateTimeShortcuts.init();
 81            }
 82        }
 83        var updateSelectFilter = function() {
 84            // If any SelectFilter widgets are a part of the new form,
 85            // instantiate a new SelectFilter instance for it.
 86            if (typeof SelectFilter != "undefined"){
 87                $(".selectfilter").each(function(index, value){
 88                  var namearr = value.name.split('-');
 89                  SelectFilter.init(value.id, namearr[namearr.length-1], false, "{% admin_media_prefix %}");
 90                });
 91                $(".selectfilterstacked").each(function(index, value){
 92                  var namearr = value.name.split('-');
 93                  SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% admin_media_prefix %}");
 94                });
 95            }
 96        }
 97        var initPrepopulatedFields = function(row) {
 98            row.find('.prepopulated_field').each(function() {
 99                var field = $(this);
100                var input = field.find('input, select, textarea');
101                var dependency_list = input.data('dependency_list') || [];
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                });
106                if (dependencies.length) {
107                    input.prepopulate(dependencies, input.attr('maxlength'));
108                }
109            });
110        }
111        $(rows).formset({
112            prefix: "{{ inline_admin_formset.formset.prefix }}",
113            addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
114            formCssClass: "dynamic-{{ inline_admin_formset.formset.prefix }}",
115            deleteCssClass: "inline-deletelink",
116            deleteText: "{% trans "Remove" %}",
117            emptyCssClass: "empty-form",
118            removed: alternatingRows,
119            added: (function(row) {
120                initPrepopulatedFields(row);
121                reinitDateTimeShortCuts();
122                updateSelectFilter();
123                alternatingRows(row);
124            })
125        });
126    });
127})(django.jQuery);
128</script>