Refactored sorting JS files to be includes so that server-side variables may be passed to them.

Added 'after_sorting_js_callback_name' attribute to SortableAdminBase.
Added callback to be executed after sorting for each of the possible sorting scenarios.
Added custom template examples to add a callback to be executed when sorting is finished.
This commit is contained in:
Brandon Taylor
2018-06-18 11:40:24 -04:00
parent fa8a5f12a8
commit e35f36b25a
10 changed files with 270 additions and 193 deletions
Binary file not shown.
+3
View File
@@ -83,6 +83,9 @@ class ProjectAdmin(SortableAdmin):
NonSortableCreditInline, NonSortableNoteInline
]
list_display = ['__str__', 'category']
after_sorting_js_callback_name = 'afterSortCallback'
sortable_change_list_template = 'adminsortable/custom_change_list.html'
sortable_change_form_template = "adminsortable/custom_change_form.html"
admin.site.register(Project, ProjectAdmin)
@@ -0,0 +1,15 @@
{% extends "adminsortable/change_form.html" %}
{% block extrahead %}
{{ block.super }}
<script>
django.jQuery(document).on('order:changed', function(event) {
console.log(event.message);
});
window['{{ after_sorting_js_callback_name }}'] = function() {
django.jQuery(document).trigger({ type: 'order:changed', message: 'Order changed', time: new Date() });
};
</script>
{% endblock %}
@@ -0,0 +1,15 @@
{% extends 'adminsortable/change_list.html' %}
{% block extrahead %}
{{ block.super }}
<script>
django.jQuery(document).on('order:changed', function(event) {
console.log(event.message);
});
window['{{ after_sorting_js_callback_name }}'] = function() {
django.jQuery(document).trigger({ type: 'order:changed', message: 'Order changed', time: new Date() });
};
</script>
{% endblock %}