Author: zain
Date: 2009-07-02 03:10:57 -0500 (Thu, 02 Jul 2009)
New Revision: 11153
Modified:
django/branches/soc2009/admin-ui/django/contrib/admin/media/css/forms.css
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/stacked.html
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/tabular.html
Log:
[soc2009/admin-ui] Javascript inline addition for tabular inlines
Modified:
django/branches/soc2009/admin-ui/django/contrib/admin/media/css/forms.css
===================================================================
--- django/branches/soc2009/admin-ui/django/contrib/admin/media/css/forms.css
2009-07-02 07:19:44 UTC (rev 11152)
+++ django/branches/soc2009/admin-ui/django/contrib/admin/media/css/forms.css
2009-07-02 08:10:57 UTC (rev 11153)
@@ -274,7 +274,7 @@
color: #fff;
}
-.inline-related.tabular fieldset.module table {
+.tabular.inline-group fieldset.module table {
width: 100%;
}
@@ -282,26 +282,26 @@
border: none;
}
-.inline-group .tabular tr.has_original td {
+.tabular.inline-group tr.has_original td {
padding-top: 2em;
}
-.inline-group .tabular tr td.original {
+.tabular.inline-group tr td.original {
padding: 2px 0 0 0;
width: 0;
_position: relative;
}
-.inline-group .tabular th.original {
+.tabular.inline-group th.original {
width: 0px;
padding: 0;
}
-.inline-group .tabular td.original p {
+.tabular.inline-group td.original p {
position: absolute;
left: 0;
height: 1.1em;
- padding: 2px 7px;
+ padding: 2px 25px;
overflow: hidden;
font-size: 9px;
font-weight: bold;
Modified:
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/stacked.html
===================================================================
---
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/stacked.html
2009-07-02 07:19:44 UTC (rev 11152)
+++
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/stacked.html
2009-07-02 08:10:57 UTC (rev 11153)
@@ -53,7 +53,7 @@
$(id_prefix + "-add").click(function() {
var new_inline = $(id_prefix + '-empty').clone(true)
- .insertBefore(id_prefix +
'-addinline').fadeIn('normal');
+ .insertBefore(id_prefix +
'-empty').fadeIn('normal');
var inline_template = $(new_inline).html();
var new_inline_html = inline_template.replace(/__prefix__/g,
total_forms.val().toString());
Modified:
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/tabular.html
===================================================================
---
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/tabular.html
2009-07-02 07:19:44 UTC (rev 11152)
+++
django/branches/soc2009/admin-ui/django/contrib/admin/templates/admin/edit_inline/tabular.html
2009-07-02 08:10:57 UTC (rev 11153)
@@ -1,6 +1,5 @@
{% load i18n %}
-<div class="inline-group">
- <div class="tabular inline-related {% if forloop.last %}last-related{% endif
%}">
+<div class="tabular inline-group" id="{{
inline_admin_formset.opts.verbose_name}}-group">
{{ inline_admin_formset.formset.management_form }}
<fieldset class="module">
<h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
@@ -19,7 +18,8 @@
{% if inline_admin_form.form.non_field_errors %}
<tr><td colspan="{{ inline_admin_form.field_count }}">{{
inline_admin_form.form.non_field_errors }}</td></tr>
{% endif %}
- <tr class="{% if not inline_admin_formset.opts.order_field %}{% cycle
'row1' 'row2' %} {% endif %}{% if inline_admin_form.original or
inline_admin_form.show_url %}has_original{% endif %}">
+ <tr class="inline-related {% if forloop.last %}empty_form{% endif %}
{% if not inline_admin_formset.opts.order_field %}{% cycle 'row1' 'row2' %} {%
endif %}{% if inline_admin_form.original or inline_admin_form.show_url
%}has_original{% endif %}"
+ id="{{ inline_admin_formset.opts.verbose_name}}{% if not
forloop.last %}{{ forloop.counter }}{% else %}-empty{% endif %}">
<td class="original">
{% if inline_admin_form.original or inline_admin_form.show_url %}<p>
@@ -61,54 +61,95 @@
</table>
</fieldset>
- </div>
- {# <ul class="tools"> #}
- {# <li><a class="add" href="">Add another {{
inline_admin_formset.opts.verbose_name|title }}</a></li> #}
- {# </ul> #}
+<ul class="tools add_inline" id="{{
inline_admin_formset.opts.verbose_name}}-addinline">
+ <li><a id="{{ inline_admin_formset.opts.verbose_name }}-add" class="add"
href="#">Add a {{ inline_admin_formset.opts.verbose_name }}</a></li>
+</ul>
</div>
<script type="text/javascript">
$(function() {
+ /* Add inline */
+ // TODO: this block of code is the same for all inlines, so move it out
into a separate file
+ var prefix = "{{ inline_admin_formset.opts.verbose_name }}";
+ var id_prefix = "#" + prefix;
+ var total_forms = $(id_prefix + '-group input[id$="TOTAL_FORMS"]');
+ var initial_forms = $(id_prefix +
'-group').find('input[id$="INITIAL_FORMS"]');
+
+ // since javascript is turned on, unhide the "add new <inline>" link
+ $('.add_inline').show();
+
+ // hide the extras, but only if there were no form errors
+ if (!$('.errornote').html()) {
+ if (parseInt(initial_forms.val()) > 0) {
+ $(id_prefix + '-group .inline-related:gt(' + (initial_forms.val()
- 1) + ')')
+ .not('.empty_form').remove();
+ }
+ else {
+ $(id_prefix + '-group
.inline-related').not('.empty_form').remove();
+ }
+
+ total_forms.val(parseInt(initial_forms.val()));
+ }
+
+ $(id_prefix + "-add").click(function() {
+ var new_inline = $(id_prefix + '-empty').clone(true)
+ .insertBefore(id_prefix +
'-empty').fadeIn('normal');
+
+ var inline_template = $(new_inline).html();
+ var new_inline_html = inline_template.replace(/__prefix__/g,
total_forms.val().toString());
+
+ total_forms.val(parseInt(total_forms.val()) + 1);
+
+ $(new_inline).html(new_inline_html);
+ $(new_inline).attr('id', prefix + total_forms.val().toString());
+ $(new_inline).find('.inline_label').html('#' +
total_forms.val().toString());
+ $(new_inline).removeClass('empty_form');
+
+ return false;
+ });
+
{% if inline_admin_formset.opts.order_field %}
- // highlight each row on hover
- $("table.orderable tbody tr").hover(
- function() {
- $(this).addClass('hover');
- },
- function() {
- $(this).removeClass('hover');
- }
- );
+ /* Reordering Inlines */
- $('table.orderable').tableDnD({
- onDragStart: function(table, row_obj) {
- // once you start dragging a row, stop the hover()
highlighting.
- // this is needed because the highlighting from onDragStyle
isn't always in
- // sync with the hover() highlighting, which results in times
where you have
- // two rows highlighted.
- $("table.orderable tbody
tr").unbind('mouseenter').unbind('mouseleave');
- },
- onDrop: function(table, row_obj) {
- var counter = 0;
-
- $(row_obj).parent().find('input[id$="{{
inline_admin_formset.opts.order_field }}"]')
- .each(function (i) {
- $(this).val(counter++);
- });
-
- // rebind hover
- $("table.orderable tbody tr").hover(
- function() {
- $(this).addClass('hover');
- },
- function() {
- $(this).removeClass('hover');
- }
- );
- }
- });
+ // highlight each row on hover
+ $("table.orderable tbody tr").hover(
+ function() {
+ $(this).addClass('hover');
+ },
+ function() {
+ $(this).removeClass('hover');
+ }
+ );
+
+ $('table.orderable').tableDnD({
+ onDragStart: function(table, row_obj) {
+ // once you start dragging a row, stop the hover() highlighting.
+ // this is needed because the highlighting from onDragStyle isn't
always in
+ // sync with the hover() highlighting, which results in times
where you have
+ // two rows highlighted.
+ $("table.orderable tbody
tr").unbind('mouseenter').unbind('mouseleave');
+ },
+ onDrop: function(table, row_obj) {
+ var counter = 0;
+
+ $(row_obj).parent().find('input[id$="{{
inline_admin_formset.opts.order_field }}"]')
+ .each(function (i) {
+ $(this).val(counter++);
+ });
+
+ // rebind hover
+ $("table.orderable tbody tr").hover(
+ function() {
+ $(this).addClass('hover');
+ },
+ function() {
+ $(this).removeClass('hover');
+ }
+ );
+ }
+ });
{% endif %}
});
</script>
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---