Made new windows position themselves randomly.
[philo.git] / templates / admin / philo / edit_inline / tabular_container.html
1 {% load i18n adminmedia %}
2 {{ inline_admin_formset.formset.management_form }}
3 {% if inline_admin_formset.formset.forms %}
4 <div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
5   <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
6 <fieldset class="module{% if inline_admin_formset.classes %} {{ inline_admin_formset.classes|join:' ' }}{% endif %}">
7    <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
8    {{ inline_admin_formset.formset.non_form_errors }}
9    <table>
10          <tbody>
11          {% for inline_admin_form in inline_admin_formset %}
12                 {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
13                 {{ inline_admin_form.fk_field.field }}
14                 {% spaceless %}
15                 {% for fieldset in inline_admin_form %}
16                 {% for line in fieldset %}
17                   {% for field in line %}
18                         {% if field.is_hidden %} {{ field.field }} {% endif %}
19                   {% endfor %}
20                 {% endfor %}
21                 {% endfor %}
22                 {% endspaceless %}
23         {% endfor %}
24         {% for form in inline_admin_formset.formset.forms %}
25                 {% if form.non_field_errors %}
26                 <tr><td colspan="2">{{ form.non_field_errors }}</td></tr>
27                 {% endif %}
28                 <tr class="{% cycle "row1" "row2" %}{% comment %} {% if forloop.last %} empty-form{% endif %}{% endcomment %}"
29                          id="{{ formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
30                         <th>{{ form.verbose_name|capfirst }}:</th>
31                         {% for field in form %}
32                           {% if not field.is_hidden %}
33                           <td class="{{ field.field.name }}">
34                                   {{ field.field.errors.as_ul }}
35                                   {{ field }}
36                                   {% if field.field.help_text %}
37                                   <p class="help">{{ field.field.help_text|safe }}</p>
38                                   {% endif %}
39                           </td>
40                           {% endif %}
41                         {% endfor %}
42                 </tr>
43          {% endfor %}
44          </tbody>
45    </table>
46 </fieldset>
47   </div>
48 </div>
49
50 <script type="text/javascript">
51 (function($) {
52         $(document).ready(function($) {
53                 var rows = "#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr";
54                 var alternatingRows = function(row) {
55                         $(rows).not(".add-row").removeClass("row1 row2")
56                                 .filter(":even").addClass("row1").end()
57                                 .filter(rows + ":odd").addClass("row2");
58                 }
59                 var reinitDateTimeShortCuts = function() {
60                         // Reinitialize the calendar and clock widgets by force
61                         if (typeof DateTimeShortcuts != "undefined") {
62                                 $(".datetimeshortcuts").remove();
63                                 DateTimeShortcuts.init();
64                         }
65                 }
66                 var updateSelectFilter = function() {
67                         // If any SelectFilter widgets are a part of the new form,
68                         // instantiate a new SelectFilter instance for it.
69                         if (typeof SelectFilter != "undefined"){
70                                 $(".selectfilter").each(function(index, value){
71                                   var namearr = value.name.split('-');
72                                   SelectFilter.init(value.id, namearr[namearr.length-1], false, "{% admin_media_prefix %}");
73                                 })
74                                 $(".selectfilterstacked").each(function(index, value){
75                                   var namearr = value.name.split('-');
76                                   SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% admin_media_prefix %}");
77                                 })
78                         }
79                 }
80                 var initPrepopulatedFields = function(row) {
81                         row.find('.prepopulated_field').each(function() {
82                                 var field = $(this);
83                                 var input = field.find('input, select, textarea');
84                                 var dependency_list = input.data('dependency_list') || [];
85                                 var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea');
86                                 if (dependencies.length) {
87                                         input.prepopulate(dependencies, input.attr('maxlength'));
88                                 }
89                         });
90                 }
91                 $(rows).formset({
92                         prefix: "{{ inline_admin_formset.formset.prefix }}",
93                         addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
94                         formCssClass: "dynamic-{{ inline_admin_formset.formset.prefix }}",
95                         deleteCssClass: "inline-deletelink",
96                         deleteText: "{% trans "Remove" %}",
97                         emptyCssClass: "empty-form",
98                         removed: alternatingRows,
99                         added: (function(row) {
100                                 initPrepopulatedFields(row);
101                                 reinitDateTimeShortCuts();
102                                 updateSelectFilter();
103                                 alternatingRows(row);
104                         })
105                 });
106         });
107 })(django.jQuery);
108 </script>
109 {% endif %}