Made new windows position themselves randomly.
[philo.git] / templates / admin / philo / edit_inline / tabular_attribute.html
1 {% load i18n adminmedia %}
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 collapse collapse-closed closed">
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          <th>Content Type</th>
16          <th>Value</th>
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.field_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
24         {% endif %}
25         <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 %}"
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 class="{{ field.field.name }}">
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         <td>{% with inline_admin_form.form.content_type as field %}{{ field.errors.as_ul }}{{ field }}{% endwith %}</td>
59         <td>{% with inline_admin_form.form.value as field %}{{ field.errors.as_ul }}{{ field }}{% endwith %}</td>
60         {% if inline_admin_formset.formset.can_delete %}
61           <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
62         {% endif %}
63         </tr>
64      {% endfor %}
65      </tbody>
66    </table>
67 </fieldset>
68   </div>
69 </div>
70
71 <script type="text/javascript">
72 (function($) {
73     $(document).ready(function($) {
74         var rows = "#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr";
75         var alternatingRows = function(row) {
76             $(rows).not(".add-row").removeClass("row1 row2")
77                 .filter(":even").addClass("row1").end()
78                 .filter(rows + ":odd").addClass("row2");
79         }
80         var reinitDateTimeShortCuts = function() {
81             // Reinitialize the calendar and clock widgets by force
82             if (typeof DateTimeShortcuts != "undefined") {
83                 $(".datetimeshortcuts").remove();
84                 DateTimeShortcuts.init();
85             }
86         }
87         var updateSelectFilter = function() {
88             // If any SelectFilter widgets are a part of the new form,
89             // instantiate a new SelectFilter instance for it.
90             if (typeof SelectFilter != "undefined"){
91                 $(".selectfilter").each(function(index, value){
92                   var namearr = value.name.split('-');
93                   SelectFilter.init(value.id, namearr[namearr.length-1], false, "{% admin_media_prefix %}");
94                 })
95                 $(".selectfilterstacked").each(function(index, value){
96                   var namearr = value.name.split('-');
97                   SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% admin_media_prefix %}");
98                 })
99             }
100         }
101         var initPrepopulatedFields = function(row) {
102             row.find('.prepopulated_field').each(function() {
103                 var field = $(this);
104                 var input = field.find('input, select, textarea');
105                 var dependency_list = input.data('dependency_list') || [];
106                 var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea');
107                 if (dependencies.length) {
108                     input.prepopulate(dependencies, input.attr('maxlength'));
109                 }
110             });
111         }
112         $(rows).formset({
113             prefix: "{{ inline_admin_formset.formset.prefix }}",
114             addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
115             formCssClass: "dynamic-{{ inline_admin_formset.formset.prefix }}",
116             deleteCssClass: "inline-deletelink",
117             deleteText: "{% trans "Remove" %}",
118             emptyCssClass: "empty-form",
119             removed: alternatingRows,
120             added: (function(row) {
121                 initPrepopulatedFields(row);
122                 reinitDateTimeShortCuts();
123                 updateSelectFilter();
124                 alternatingRows(row);
125             })
126         });
127     });
128 })(django.jQuery);
129 </script>