71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
/**
|
|
* @package ogre-sort
|
|
* @author cleverogre
|
|
* @version 1.0.0
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
jQuery(($) => {
|
|
if (typeof window['ogre_sort'] === 'undefined') return;
|
|
|
|
const update = (args) => {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: ogre_sort.ajaxurl,
|
|
data: args,
|
|
success: (response, textStatus, jqXHR) => {
|
|
if (response.success) {
|
|
console.log('Ogre Sort: Ajax sort request successful');
|
|
} else if (typeof response.data !== 'undefined' && response.data != '') {
|
|
console.log('Ogre Sort: Ajax sort error. ' + response.data);
|
|
} else {
|
|
console.log('Ogre Sort: Ajax sort error. Unknown sort error.');
|
|
}
|
|
},
|
|
error: (jqXHR, textStatus, errorThrown) => {
|
|
console.log('Ogre Sort: Ajax sort request failed');
|
|
},
|
|
complete: (jqXHR, textStatus) => {
|
|
console.log('Ogre Sort: Ajax request completed');
|
|
},
|
|
});
|
|
};
|
|
|
|
const fixHelper = (e, ui) => {
|
|
ui.children().children().each(function () {
|
|
$(this).width($(this).width());
|
|
});
|
|
return ui;
|
|
};
|
|
|
|
$('table.posts #the-list, table.pages #the-list').sortable({
|
|
'items': 'tr',
|
|
'axis': 'y',
|
|
'helper': fixHelper,
|
|
'update': (e, ui) => {
|
|
const args = {
|
|
action: 'ogre_sort',
|
|
relationship: ogre_sort.current_relationship,
|
|
order: $('#the-list').sortable('serialize'),
|
|
};
|
|
if (typeof ogre_sort.term != 'undefined') {
|
|
args.term = ogre_sort.term;
|
|
}
|
|
update(args);
|
|
},
|
|
});
|
|
|
|
$('table.tags #the-list').sortable({
|
|
'items': 'tr',
|
|
'axis': 'y',
|
|
'helper': fixHelper,
|
|
'update': (e, ui) => {
|
|
update({
|
|
action: 'ogre_sort',
|
|
relationship: ogre_sort.current_relationship,
|
|
order: $('#the-list').sortable('serialize'),
|
|
});
|
|
},
|
|
});
|
|
});
|