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:
Binary file not shown.
@@ -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 %}
|
||||
Reference in New Issue
Block a user