From 3d45182c2bdafcbeffd3b4245b67345b699abc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eero=20J=C3=A4=C3=A4skel=C3=A4inen?= Date: Wed, 15 May 2024 16:17:15 +0300 Subject: [PATCH] Updated sorting to comply with latest layout. --- application/controllers/Services.php | 2 +- assets/js/pages/services.js | 35 +++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/application/controllers/Services.php b/application/controllers/Services.php index 80961f90..bd25bb11 100644 --- a/application/controllers/Services.php +++ b/application/controllers/Services.php @@ -106,7 +106,7 @@ class Services extends EA_Controller $keyword = request('keyword', ''); - $order_by = request('order_by', 'row_order ASC, update_datetime DESC'); + $order_by = 'update_datetime DESC'; $limit = request('limit', 1000); diff --git a/assets/js/pages/services.js b/assets/js/pages/services.js index 65566b7e..c22559e1 100644 --- a/assets/js/pages/services.js +++ b/assets/js/pages/services.js @@ -94,18 +94,47 @@ App.Pages.Services = (function () { */ const sorting = new Sortable(document.querySelector('.results'), { + onStart : function(ev) { + if (ev.from.querySelector('hr') == null) + return; + if (! (ev.item.nextSibling && ev.item.nextSibling.tagName == 'HR')) + return; + ev.item.dataset['hadHR'] = true; + ev.item.nextSibling.remove(); + }, onUpdate : async function(ev){ resetForm(); let afterId; const currentItemId = ev.item.dataset['id']; + const hadHR = ev.item.dataset['hadHR'] == 'true'; +; if (ev.newIndex == 0) afterId = -1; - else if (ev.item.previousSibling !== null && ev.item.previousSibling.classList.contains('service-row')) { - afterId = parseInt(ev.item.previousSibling.dataset['id']); + else if (ev.item.previousSibling !== null) { + let prevItem =ev.item.previousSibling; + if (prevItem.tagName == 'HR') + prevItem = prevItem.previousSibling; + + if (! prevItem.classList.contains('service-row')){ + window.App.Utils.Message.show(lang('unexpected_issues'),'Failed to get previous service to sort!'); + throw 'Failed to get previous service to sort'; + } + + afterId = parseInt(prevItem.dataset['id']); + } try { - await sort(currentItemId, afterId) + await sort(currentItemId, afterId); + if (hadHR) + { + const newHr = document.createElement('HR'); + if (ev.oldIndex < ev.newIndex) + ev.item.before(newHr); + else + ev.item.after(newHr); + delete ev.item.dataset.hadHR; + } } catch (err){ $services.find('.form-message').addClass('alert-danger').text(lang('error')).show();