CMTV
Well-known member
Since XenForo supports Dragula, I think it is time to add drag-and-drop sorting functionality and get rid of inconvenient "Sort" pages/setting "Display order" property for each entity.
Would be nice to have this for smilies, notices, nodes:
Please, like this message if you want something presented above in XenForo.
This can be done really easily. I did this by simply extending
Two things:
Would be nice to have this for smilies, notices, nodes:
Please, like this message if you want something presented above in XenForo.
This can be done really easily. I did this by simply extending
XF.ListSorter
javascript handler:
JavaScript:
var CMTV_CB = window.CMTV_CB || {};
!function($, window, document, _undefined)
{
"use strict";
CMTV_CB.DataListSorter = XF.extend(XF.ListSorter, {
options: $.extend({}, XF.ListSorter.prototype.options, {
sortUrl: 'admin.php?criteria-builder/categories/ajaxSort'
}),
init: function ()
{
this.dragula = dragula([this.$target.find('.dataList-table tbody')[0]], {
moves: XF.proxy(this, 'isMoveable'),
accepts: XF.proxy(this, 'isValidTarget')
});
this.dragula.on('drop', XF.proxy(this, 'onDrop'));
},
onDrop: function (el, target, source, sibling)
{
var data = {
moved: $(el).data('category-id'),
before: $(sibling).data('category-id')
};
XF.ajax('post', this.options.sortUrl, data, function() {});
}
});
XF.Element.register('datalist-sorter', 'CMTV_CB.DataListSorter');
}
(jQuery, window, document);
Two things:
- Making
dragula
object to work withtbody
- After successfull element drop -> make an ajax request and recalculate all
display_order
s
moved
and before
ids.
Last edited:
Upvote
24