Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tswicegood/pops
base: b120a80f57
...
head fork: tswicegood/pops
compare: 5ca5e6f766
Checking mergeability… Don't worry, you can still create the pull request.
  • 18 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
17 pops/static/pops/css/style.css
@@ -6479,6 +6479,13 @@ fieldset h2 {
.dashboard-container .module .nav.nav-list.nav-list-with-headers > li {
padding: 0 0 0 15px;
}
+div.tabular thead th.order,
+div.tabular tbody td.order {
+ display: none;
+}
+div.tabular a.btn {
+ cursor: pointer;
+}
@media (max-width: 979px) {
.navbar-fixed-top .navbar-inner {
padding: 0;
@@ -7827,3 +7834,13 @@ fieldset h2 {
width: 100%;
}
}
+.icon-undo {
+ background-position: -336px -96px;
+ -webkit-transform: scalex(-1);
+ -moz-transform: scalex(-1);
+ -o-transform: scalex(-1);
+ -ms-filter: "FlipH";
+ transform: scalex(-1);
+ filter: FlipH;
+}
+/* TODO: Refactor into a more appropriate location */
View
111 pops/static/pops/js/pops.inlineFormSet.js
@@ -7,6 +7,10 @@ if (typeof pops.inlineFormSet === 'undefined') {
var $ = arguments[1] || window.jQuery,
groupId = '#' + opts.prefix + '-group',
rows = groupId + ' .tabular.inline-related tbody tr',
+ rowsSelector = 'tbody tr:not(.add-row):not(.empty-form)',
+ $table = $(rows).closest('table'),
+ $totalForms = $table.closest('div.tabular').find('input[id$="TOTAL_FORMS"]'),
+
alternatingRows = function(row) {
$(rows).not('.add-row').removeClass('row1 row2')
.filter(':even').addClass('row1').end()
@@ -14,6 +18,7 @@ if (typeof pops.inlineFormSet === 'undefined') {
},
reinitDateTimeShortCuts = function() {
+ // TODO: Limit this to effected inputs
// Reinitialize the calendar and clock widgets by force
if (typeof DateTimeShortcuts != 'undefined') {
$('.datetimeshortcuts').remove();
@@ -59,13 +64,96 @@ if (typeof pops.inlineFormSet === 'undefined') {
input.prepopulate(dependencies, input.attr('maxlength'));
}
});
+ },
+
+ deleteLinkForRow = function(row) {
+ $(row).find("td.delete a").click(deleteLinkHandler);
+ },
+
+ deleteLinkHandler = function() {
+ var $this = $(this),
+ $row = $this.closest('tr');
+ if ($row.is('.has_original')) {
+ $this.parent().find('input').attr('checked', 'checked');
+ $row.addClass('deleted_row').fadeTo("fast", 0.5, updatePositions);
+ $this.unbind('click', deleteLinkHandler)
+ .removeClass('delete')
+ .addClass('undo')
+ .html(opts.undoHtml)
+ .click(undoClickHandler);
+ } else {
+ $row.fadeTo("fast", 0, function() {
+ $row.remove();
+ updatePositions();
+ });
+ }
+ },
+
+ updateIdFields = function(row, newPosition) {
+ var idExp = /([^ ]+?\-)([0-9]+|__prefix__)(\-[^ ]+)/i;
+
+ $.each(['select', 'input', 'a', 'textarea'], function (i, tagName) {
+ row.find(tagName).each(function() {
+ var $tag = $(this);
+ $.each(['id', 'name'], function (j, attrName) {
+ var oldVal = $tag.attr(attrName);
+ if (!oldVal) return;
+ var newVal = oldVal.replace(idExp, "$1" + newPosition + "$3");
+ $tag.attr(attrName, newVal);
+ });
+ });
+ });
+ },
+
+ reorderRows = function($rows) {
+ if (!opts.positionField) {
+ return;
+ }
+
+ if (!$rows) {
+ $rows = $table.find(rowsSelector);
+ }
+
+ $rows.each(function(i) {
+ $(this).find('td.' + opts.positionField + ' input').val(i + 1);
+ });
+ },
+
+ updatePositions = function() {
+ var $rows = $table.find(rowsSelector);
+ if (opts.positionField) {
+ reorderRows($rows);
+ }
+ $totalForms.val($rows.length);
+ },
+
+ undoClickHandler = function() {
+ var $this = $(this),
+ $row = $this.closest('tr');
+ $this.parent().find('input').removeAttr('checked');
+ $row.removeClass('deleted_row').fadeTo('fast', 1.0);
+ $this.unbind('click', undoClickHandler)
+ .removeClass('undo')
+ .addClass('delete')
+ .click(deleteLinkHandler)
+ .html(opts.deleteHtml);
+ updatePositions();
};
// Not sure if this is needed?
$('.tabular-inline textarea').addClass('xxlarge');
+ // TODO: Refactor all of these to allow false to turn them off
+ if (typeof opts.positionField === 'undefined') {
+ opts.positionField = 'order';
+ }
opts.addTextIcon = opts.addTextIcon || '<i class="icon icon-plus"></i> ';
opts.deleteTextIcon = opts.deleteTextIcon || '<i class="icon icon-minus"></i> ';
+ opts.deleteHtml = opts.deleteTextIcon + opts.deleteText;
+ opts.emptyCssClass = opts.emptyCssClass || 'empty-form';
+ opts.undoTextIcon = opts.undoTextIcon || '<i class="icon icon-undo"></i> ';
+ opts.undoText = opts.undoText || 'Undo';
+ opts.undoHtml = opts.undoTextIcon + opts.undoText;
var formsetOptions = {
prefix: opts.prefix,
@@ -73,8 +161,8 @@ if (typeof pops.inlineFormSet === 'undefined') {
formCssClass: 'dynamic-' + opts.prefix,
deleteCssClass: 'inline-deletelink btn',
addCssClass: 'add-row',
- deleteText: opts.deleteTextIcon + opts.deleteText,
- emptyCssClass: 'empty-form',
+ deleteText: opts.deleteHtml,
+ emptyCssClass: opts.emptyCssClass,
removed: alternatingRows,
added: (function(row) {
initPrepopulatedFields(row);
@@ -82,13 +170,26 @@ if (typeof pops.inlineFormSet === 'undefined') {
updateSelectFilter();
alternatingRows(row);
reinitChosen(row);
-
- // double check that it's shown (makes sure this works with dynamic_inlines_with_sorts)
- $(row).show();
+ deleteLinkForRow(row);
+ updatePositions();
})
};
$(rows).formset(formsetOptions);
+ // once again, go back the jQuery with jQuery UI
+ window.jQuery(rows).closest('table').sortable({
+ items: 'tbody tr:visible:not(.add-row)',
+ tolerance: 'pointer',
+ axis: 'y',
+ cancel: 'input,button,select,a',
+ helper: 'clone',
+ update: updatePositions
+ });
+
+ // Create all of the delete buttons
+ $(rows).not('.' + opts.emptyCssClass).find('a.delete')
+ .click(deleteLinkHandler);
+
$(groupId).find('.add-row a').addClass('btn pull-right');
};
}
View
26 pops/static/pops/less/style.less
@@ -449,6 +449,17 @@ fieldset {
}
}
+div.tabular {
+ thead th.order,
+ tbody td.order {
+ display: none;
+ }
+
+ a.btn {
+ cursor: pointer;
+ }
+}
+
@media (max-width: 979px) {
.navbar-fixed-top .navbar-inner {
padding: 0;
@@ -475,3 +486,18 @@ fieldset {
width: 100%;
}
}
+
+.icon-undo {
+ background-position: -336px -96px;
+ .flip();
+}
+
+/* TODO: Refactor into a more appropriate location */
+.flip() {
+ -webkit-transform: scaleX(-1);
+ -moz-transform: scaleX(-1);
+ -o-transform: scaleX(-1);
+ -ms-filter: "FlipH";
+ transform: scaleX(-1);
+ filter: FlipH;
+}
View
139 pops/templates/admin/edit_inline/tabular.html
@@ -1,66 +1,93 @@
{% load i18n adminmedia admin_modify %}
<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
-{{ inline_admin_formset.formset.management_form }}
-<fieldset class="module well">
- <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
- {{ inline_admin_formset.formset.non_form_errors }}
- <table class="table table-striped tabular-inline table-condensed table-bordered">
- <thead><tr>
- {% for field in inline_admin_formset.fields %}
- {% if not field.widget.is_hidden %}
- <th{% if forloop.first %} colspan="2"{% endif %}{% if field.required %} class="required"{% endif %}>{{ field.label|capfirst }}</th>
- {% endif %}
- {% endfor %}
- {% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
- </tr></thead>
- <tbody>
- {% for inline_admin_form in inline_admin_formset %}
- {% if inline_admin_form.form.non_field_errors %}
- <tr><td colspan="{{ inline_admin_form|cell_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
- {% endif %}
- <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 %}"
- id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
- <td class="original">
- {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
- {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
- {% 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 %}
- </p>{% endif %}
- {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
- {{ inline_admin_form.fk_field.field }}
- {% spaceless %}
- {% for fieldset in inline_admin_form %}
- {% for line in fieldset %}
- {% for field in line %}
- {% if field.is_hidden %} {{ field.field }} {% endif %}
+ {{ inline_admin_formset.formset.management_form }}
+
+ <fieldset class="module well">
+ <h2>
+ {{ inline_admin_formset.opts.verbose_name_plural|capfirst }}
+ </h2>
+
+ {{ inline_admin_formset.formset.non_form_errors }}
+
+ <table class="table table-striped tabular-inline table-condensed table-bordered">
+ <thead>
+ <tr>
+ {% for field in inline_admin_formset.fields %}
+ {% if not field.widget.is_hidden %}
+ <th class="{{ field.label|lower }}{% if field.required %} required{% endif %}">
+ {{ field.label|capfirst }}
+ </th>
+ {% endif %}
{% endfor %}
- {% endfor %}
- {% endfor %}
- {% endspaceless %}
- </td>
- {% for fieldset in inline_admin_form %}
- {% for line in fieldset %}
- {% for field in line %}
- <td class="{{ field.field.name }}">
- {% if field.is_readonly %}
- <p>{{ field.contents }}</p>
- {% else %}
- {{ field.field.errors.as_ul }}
- {{ field.field }}
+ </tr>
+ </thead>
+
+ <tbody>
+ {% for inline_admin_form in inline_admin_formset %}
+ {% if inline_admin_form.form.non_field_errors %}
+ <tr>
+ <td colspan="{{ inline_admin_form|cell_count }}">
+ {{ inline_admin_form.form.non_field_errors }}
+ </td>
+ </tr>
{% endif %}
- </td>
+
+ <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 %}"
+ id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
+
+ <td class="hidden original">
+ {% if inline_admin_form.has_auto_field %}
+ {{ inline_admin_form.pk_field.field }}
+ {% endif %}
+
+ {{ inline_admin_form.fk_field.field }}
+
+ {% for fieldset in inline_admin_form %}
+ {% for line in fieldset %}
+ {% for field in line %}
+ {% if field.is_hidden %}
+ {{ field.field }}
+ {% endif %}
+ {% endfor %}
+ {% endfor %}
+ {% endfor %}
+ </td>
+
+ {% for fieldset in inline_admin_form %}
+ {% for line in fieldset %}
+ {% for field in line %}
+ <td class="{{ field.field.name }}">
+ {% if field.is_readonly %}
+ <p>{{ field.contents }}</p>
+ {% else %}
+ {{ field.field.errors.as_ul }}
+ {{ field.field }}
+ {% endif %}
+ </td>
+ {% endfor %}
+ {% endfor %}
+ {% endfor %}
+
+ {% if inline_admin_formset.formset.can_delete %}
+ <td class="delete">
+ {% if inline_admin_form.original %}
+ <span class="hidden">
+ {{ inline_admin_form.deletion_field.field }}
+ </span>
+ <a class="delete btn">
+ <i class="icon-minus"></i>
+ {% trans 'Remove' %}
+ </a>
+ {% endif %}
+ </td>
+ {% endif %}
+ </tr>
{% endfor %}
- {% endfor %}
- {% endfor %}
- {% if inline_admin_formset.formset.can_delete %}
- <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
- {% endif %}
- </tr>
- {% endfor %}
- </tbody>
- </table>
-</fieldset>
+ </tbody>
+ </table>
+ </fieldset>
</div>
</div>

No commit comments for this range

Something went wrong with that request. Please try again.