PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://code.google.com/p/mango-py/
HTML | 149 lines | 141 code | 8 blank | 0 comment | 0 complexity | bcadb38ce75dcc7b14dbffe2e4ef9bd2 MD5 | raw file
  1<%def name="inline_edit(inline_admin_formset, formset_count)">
  2<%namespace name="admin" module="django.contrib.admin.templatetags.adminmedia" />
  3<div class="inline-group" id="${ inline_admin_formset.formset.prefix }-group">
  4  <div class="tabular inline-related${' last-related' if formset_count==0 else ''}">
  5<%!
  6    # filter to titlecase text
  7    def title(text):
  8        return text.title()
  9%>
 10
 11${inline_admin_formset.formset.management_form}
 12<fieldset class="module">
 13   <h2>${ inline_admin_formset.opts.verbose_name_plural|title,h }</h2>
 14   ${inline_admin_formset.formset.non_form_errors()}
 15   <table>
 16     <thead><tr>
 17
 18% for i, field in enumerate(inline_admin_formset.fields()):
 19       % if not field.widget.is_hidden:
 20         <th ${ 'colspan="2"' if i==0 else '' }${' class="required"' if field.required else '' }>${ capfirst(field.label) if field.label else "" }</th>
 21       % endif
 22% endfor
 23     
 24% if inline_admin_formset.formset.can_delete:
 25<th>${trans("Delete?")}</th>
 26% endif
 27</tr></thead>
 28
 29<tbody>
 30<%
 31    inline_admin_formset_list = [X for X in inline_admin_formset]
 32%>
 33% for row,inline_admin_form in enumerate(inline_admin_formset_list):
 34  % if inline_admin_form.form.non_field_errors():
 35    <tr><td colspan="${ inline_admin_form.field_count() }">${ inline_admin_form.form.non_field_errors() }</td></tr>
 36  % endif
 37    <tr class="${ "row1" if row % 2 == 0 else "row2" } ${'has_original' if inline_admin_form.original or inline_admin_form.show_url else ''} ${'empty-form' if row==len(inline_admin_formset_list)-1 else ''}"
 38        id="${ inline_admin_formset.formset.prefix }-${ row if row!=len(inline_admin_formset_list)-1 else 'empty'}">
 39<td class="original">
 40% if inline_admin_form.show_url:
 41<p>
 42<a href="../../../r/${inline_admin_form.original.content_type_id}/${inline_admin_form.original.id}/">${trans("View on site")}</a>
 43</p>
 44% endif
 45${inline_admin_form.pk_field().field}
 46% for fieldset in inline_admin_form:
 47    % for line in fieldset:
 48        % for field in line:
 49            % if hasattr(field.field, "is_hidden") and field.field.is_hidden:
 50            ${field.field} 
 51            % endif
 52        % endfor
 53    % endfor
 54% endfor
 55</td>
 56     
 57% for fieldset in inline_admin_form:
 58% for line in fieldset:
 59% for field in line:
 60<td class="${field.field.name}">
 61              % if hasattr(field,'is_readonly') and field.is_readonly:
 62                  <p>${ field.contents }</p>
 63              % else:
 64                  ${ field.field.errors.as_ul() }
 65                  ${ field.field }
 66              % endif
 67</td> 
 68% endfor
 69% endfor
 70% endfor
 71
 72% if inline_admin_formset.formset.can_delete:
 73<td class="delete">
 74% if inline_admin_form.original:
 75${inline_admin_form.deletion_field().field.as_widget()}
 76% endif
 77</td> 
 78% endif
 79        </tr>
 80% endfor
 81     </tbody>
 82   </table>   
 83</fieldset>
 84  </div>
 85</div>
 86
 87<script type="text/javascript">
 88(function($) {
 89    $(document).ready(function($) {
 90        var rows = "#${ inline_admin_formset.formset.prefix }-group .tabular.inline-related tbody tr";
 91        var alternatingRows = function(row) {
 92            $(rows).not(".add-row").removeClass("row1 row2")
 93                .filter(":even").addClass("row1").end()
 94                .filter(rows + ":odd").addClass("row2");
 95        }
 96        var reinitDateTimeShortCuts = function() {
 97            // Reinitialize the calendar and clock widgets by force
 98            if (typeof DateTimeShortcuts != "undefined") {
 99                $(".datetimeshortcuts").remove();
100                DateTimeShortcuts.init();
101            }
102        }
103        var updateSelectFilter = function() {
104            // If any SelectFilter widgets are a part of the new form,
105            // instantiate a new SelectFilter instance for it.
106            if (typeof SelectFilter != "undefined"){
107                $(".selectfilter").each(function(index, value){
108                  var namearr = value.name.split('-');
109                  SelectFilter.init(value.id, namearr[namearr.length-1], false, "${ admin_media_prefix() }");
110                })
111                $(".selectfilterstacked").each(function(index, value){
112                  var namearr = value.name.split('-');
113                  SelectFilter.init(value.id, namearr[namearr.length-1], true, "${ admin_media_prefix() }");
114                })
115            }
116        }
117        var initPrepopulatedFields = function(row) {
118            return;
119            row.find('.prepopulated_field').each(function() {
120                var field = $(this);
121                var input = field.find('input, select, textarea');
122                var dependency_list = input.data('dependency_list') || [];
123                var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea');
124                if (dependencies.length) {
125                    input.prepopulate(dependencies, input.attr('maxlength'));
126                }
127            });
128        }
129        $(rows).formset({
130            prefix: "${ inline_admin_formset.formset.prefix }",
131            addText: "Add another ${ title(inline_admin_formset.opts.verbose_name) }",
132            numCols: "${inline_admin_form.field_count()}",
133            formCssClass: "dynamic-${ inline_admin_formset.formset.prefix }",
134            deleteCssClass: "inline-deletelink",
135            deleteText: "${ trans('Remove') }",
136            emptyCssClass: "empty-form",
137            removed: alternatingRows,
138            added: (function(row) {
139                initPrepopulatedFields(row);
140                reinitDateTimeShortCuts();
141                updateSelectFilter();
142                alternatingRows(row);
143            })
144        });
145    });
146})(django.jQuery);
147</script>
148
149</%def>