Upped the django requirement to 1.3. Brought over grappelli use of the grp_tags libra...
[philo.git] / templates / admin / philo / edit_inline / grappelli_tabular_attribute.html
1 {% load i18n adminmedia grp_tags %}
2
3 <!-- group -->
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>
7         <ul class="tools">
8                 <li class="add-handler-container"><a href="javascript://" class="icon add-handler" title="{% trans 'Add Another' %}"> </a></li>
9         </ul>
10         {{ inline_admin_formset.formset.management_form }}
11         {{ inline_admin_formset.formset.non_form_errors }}
12         <!-- container -->
13         <div class="module table">
14                 <div class="module thead">
15                         <div class="tr">
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>
19                                         {% endif %}
20                                 {% endfor %}
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">&nbsp;</div>{% endif %}
24                         </div>
25                 </div>
26                 {% for inline_admin_form in inline_admin_formset %}
27                         <!-- element -->
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>
32                                 {% endif %}
33                                 <h3 style="display: none;"><b>{{ inline_admin_formset.opts.verbose_name|title }} #{{ forloop.counter }}</b>&nbsp;&nbsp;{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}</h3>
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                                 <div class="tr">
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>
50                                                                         {% else %}
51                                                                                 {{ field.field }}
52                                                                                 {{ field.field.errors.as_ul }}
53                                                                         {% endif %}
54                                                                 </div>
55                                                         {% endfor %}
56                                                 {% endfor %}
57                                         {% endfor %}
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">
61                                                 {% spaceless %}
62                                                 <ul class="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>
66                                                         {% endif %}
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 %}
68                                                 </ul>
69                                                 {% endspaceless %}
70                                         </div>
71                                         {{ inline_admin_form.fk_field.field }}
72                                         {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
73                                 </div>
74                         </div>
75                 {% endfor %}
76         </div>
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>
79                 <ul class="tools">
80                         <li class="add-handler-container"><a href="javascript://" class="icon add-handler" title="{% trans 'Add Item' %}"> </a></li>
81                 </ul><br clear="all" />
82         </div>
83 </div>
84
85 <script type="text/javascript">
86 (function($) {
87         $(document).ready(function($) {
88                 
89                 var prefix = "{{ inline_admin_formset.formset.prefix }}";
90                 var related_lookup_fields_fk = {% get_related_lookup_fields_fk inline_admin_formset.opts %};
91                 var related_lookup_fields_m2m = {% get_related_lookup_fields_m2m inline_admin_formset.opts %};
92                 var related_lookup_fields_generic = {% get_related_lookup_fields_generic inline_admin_formset.opts %};
93                 $.each(related_lookup_fields_fk, function() {
94                         $("#{{ inline_admin_formset.formset.prefix }}-group > div.table")
95                         .find("input[name^='" + prefix + "'][name$='" + this + "']")
96                         .grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
97                 });
98                 $.each(related_lookup_fields_m2m, function() {
99                         $("#{{ inline_admin_formset.formset.prefix }}-group > div.table")
100                         .find("input[name^='" + prefix + "'][name$='" + this + "']")
101                         .grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"});
102                 });
103                 $.each(related_lookup_fields_generic, function() {
104                         var content_type = this[0],
105                                 object_id = this[1];
106                         $("#{{ inline_admin_formset.formset.prefix }}-group > div.table")
107                         .find("input[name^='" + prefix + "'][name$='" + this[1] + "']")
108                         .each(function() {
109                                 var i = $(this).attr("id").match(/-\d+-/);
110                                 if (i) {
111                                         var ct_id = "#id_" + prefix + i[0] + content_type,
112                                                 obj_id = "#id_" + prefix + i[0] + object_id;
113                                         $(this).grp_related_generic({content_type:ct_id, object_id:obj_id, lookup_url:"{% url grp_related_lookup %}"});
114                                 }
115                         });
116                 });
117                 
118                 $("#{{ inline_admin_formset.formset.prefix }}-group").grp_inline({
119                         prefix: "{{ inline_admin_formset.formset.prefix }}",
120                         onBeforeAdded: function(inline) {},
121                         onAfterAdded: function(form) {
122                                 grappelli.reinitDateTimeFields(form);
123                                 grappelli.updateSelectFilter(form);
124                                 $.each(related_lookup_fields_fk, function() {
125                                         form.find("input[name^='" + prefix + "'][name$='" + this + "']")
126                                         .grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
127                                 });
128                                 $.each(related_lookup_fields_m2m, function() {
129                                         form.find("input[name^='" + prefix + "'][name$='" + this + "']")
130                                         .grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"});
131                                 });
132                                 $.each(related_lookup_fields_generic, function() {
133                                         var content_type = this[0],
134                                                 object_id = this[1];
135                                         form.find("input[name^='" + prefix + "'][name$='" + this[1] + "']")
136                                         .each(function() {
137                                                 var i = $(this).attr("id").match(/-\d+-/);
138                                                 if (i) {
139                                                         var ct_id = "#id_" + prefix + i[0] + content_type,
140                                                                 obj_id = "#id_" + prefix + i[0] + object_id;
141                                                         $(this).grp_related_generic({content_type:ct_id, object_id:obj_id, lookup_url:"{% url grp_related_lookup %}"});
142                                                 }
143                                         });
144                                 });
145                         },
146                 });
147                 
148                 {% if inline_admin_formset.opts.sortable_field_name %}
149                 $("#{{ inline_admin_formset.formset.prefix }}-group > div.table").sortable({
150                         handle: "a.drag-handler",
151                         items: "div.dynamic-form",
152                         axis: "y",
153                         appendTo: 'body',
154                         forceHelperSize: true,
155                         containment: '#{{ inline_admin_formset.formset.prefix }}-group > div.table',
156                         tolerance: 'pointer',
157                 });
158                 $("#{{ opts.module_name }}_form").bind("submit", function(){
159                         var sortable_field_name = "{{ inline_admin_formset.opts.sortable_field_name }}";
160                         var i = 0;
161                         $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.dynamic-form").each(function(){
162                                 var fields = $(this).find("div.td :input[value]");
163                                 if (fields.serialize()) {
164                                         $(this).find("input[name$='"+sortable_field_name+"']").val(i);
165                                         i++;
166                                 }
167                         });
168                 });
169                 {% endif %}
170                 
171         });
172 })(django.jQuery);
173 </script>