Skip to content

EspoCRM – Open Source CRM Application

category impr dev

Yuri Kuznetsove640315d8d61
diff --git a/client/res/templates/record/list-tree.tpl b/client/res/templates/record/list-tree.tpl
index b00595ef7d..ecc8d7691d 100644
--- a/client/res/templates/record/list-tree.tpl
+++ b/client/res/templates/record/list-tree.tpl
@@ -11,7 +11,10 @@
<div class="no-data">{{translate 'No Data'}}</div>
{{/if}}
-<div class="list list-expanded list-tree{{#if noData}} hidden{{/if}}">
+<div
+ class="list list-expanded list-tree {{#if noData}} hidden {{/if}}"
+ {{#if isEditable}} data-editable="true" {{/if}}
+>
{{#if showRoot}}
<div class="root-item">
<a
diff --git a/client/src/views/record/list-tree-item.js b/client/src/views/record/list-tree-item.js
index ba4afa6e96..6626bd260b 100644
--- a/client/src/views/record/list-tree-item.js
+++ b/client/src/views/record/list-tree-item.js
@@ -38,6 +38,12 @@ class ListTreeRecordItemView extends View {
level = 0
listViewName = 'views/record/list-tree'
+ /**
+ * @private
+ * @type {import('views/record/list-tree').default}
+ */
+ rootView
+
data() {
return {
name: this.model.get('name'),
@@ -282,11 +288,14 @@ class ListTreeRecordItemView extends View {
if (!this.readOnly) {
const $remove = this.$el.find('> .cell [data-action="remove"]');
- this.$el.find('> .cell').on('mouseenter', function () {
+ this.$el.find('> .cell').on('mouseenter', () => {
+ if (this.rootView.movedId) {
+ return;
+ }
$remove.removeClass('hidden');
});
- this.$el.find('> .cell').on('mouseleave', function () {
+ this.$el.find('> .cell').on('mouseleave', () => {
$remove.addClass('hidden');
});
}
diff --git a/client/src/views/record/list-tree.js b/client/src/views/record/list-tree.js
index 4082067e41..51f9909f8d 100644
--- a/client/src/views/record/list-tree.js
+++ b/client/src/views/record/list-tree.js
@@ -30,6 +30,7 @@
import ListRecordView from 'views/record/list';
import RecordModal from 'helpers/record-modal';
+import {Draggable} from '@shopify/draggable';
class ListTreeRecordView extends ListRecordView {
@@ -51,8 +52,31 @@ class ListTreeRecordView extends ListRecordView {
level = 0
itemViewName = 'views/record/list-tree-item'
+ /**
+ * @protected
+ * @type {boolean}
+ */
+ readOnly
+
expandToggleInactive = false;
+ /**
+ * @private
+ * @type {ListTreeRecordView}
+ */
+ rootView
+
+ /**
+ * @type {string|null}
+ */
+ movedId = null
+
+ /**
+ * @private
+ * @type {boolean}
+ */
+ blockDraggable = false
+
// noinspection JSCheckFunctionSignatures
data() {
const data = super.data();
@@ -77,6 +101,8 @@ class ListTreeRecordView extends ListRecordView {
data.expandToggleInactive = this.expandToggleInactive;
data.hasExpandToggle = !this.getUser().isPortal();
+ data.isEditable = this.level === 0 && !this.readOnly;
+
return data;
}
@@ -139,6 +165,14 @@ class ListTreeRecordView extends ListRecordView {
}
}
+ afterRender() {
+ super.afterRender();
+
+ if (this.level === 0 && !this.readOnly) {
+ this.initDraggableRoot();
+ }
+ }
+
/**
* @param {string|null} id
*/
@@ -296,6 +330,189 @@ class ListTreeRecordView extends ListRecordView {
this.setSelected(null);
}
}
+
+ /**
+ * @private
+ */
+ initDraggableRoot() {
+ // @todo Test touchscreen.
+
+ const draggable = new Draggable(this.element, {
+ distance: 8,
+ draggable: '.list-group-item > .cell > .link',
+ mirror: {
+ cursorOffsetX: 5,
+ cursorOffsetY: 5,
+ appendTo: 'body',
+ },
+ });
+
+ /** @type {HTMLElement[]} */
+ let rows;
+ /** @type {Map<HTMLElement, number>} */
+ let levelMap;
+ /** @type {HTMLElement|null} */
+ let movedLink = null;
+ /** @type {HTMLElement|null} */
+ let movedFromLi = null;
+
+ draggable.on('mirror:created', event => {
+ const mirror = event.mirror;
+ const source = event.source;
+ const originalSource = event.originalSource;
+
+ originalSource.style.display = '';
+ source.style.display = 'none';
+
+ mirror.style.display = 'block';
+ mirror.style.cursor = 'grabbing';
+ mirror.classList.add('draggable-helper', 'draggable-helper-transparent', 'text-info');
+ mirror.classList.remove('link');
+ mirror.style.pointerEvents = 'auto';
+ mirror.removeAttribute('href');
+ mirror.style.textDecoration = 'none';
+ });
+
+ draggable.on('mirror:move', event => {
+ event.mirror.style.pointerEvents = 'auto';
+ });
+
+ draggable.on('drag:start', event => {
+ if (this.blockDraggable) {
+ event.cancel();
+
+ return;
+ }
+
+ rows = Array.from(this.element.querySelectorAll('.list-group-tree > .list-group-item'));
+
+ levelMap = new Map();
+
+ rows.forEach(row => {
+ let depth = 0;
+ let current = row;
+
+ while (current && current !== this.element) {
+ current = current.parentElement;
+
+ depth ++;
+ }
+
+ levelMap.set(row, depth);
+ });
+
+ rows.sort((a, b) => levelMap.get(b) - levelMap.get(a));
+
+ this.movedId = event.source.dataset.id;
+ movedLink = event.originalSource;
+ movedFromLi = movedLink.parentElement.parentElement;
+
+ movedLink.classList.add('text-info');
+ });
+
+ let overId = null;
+ let overParentId = null;
+ let isAfter = false;
+ let wasOutOfSelf = false;
+
+ draggable.on('drag:move', event => {
+ isAfter = false;
+ overId = null;
+
+ let rowFound = null;
+
+ for (const row of rows) {
+ const rect = row.getBoundingClientRect();
+
+ const isIn =
+ rect.left < event.sensorEvent.clientX &&
+ rect.right > event.sensorEvent.clientX &&
+ rect.top < event.sensorEvent.clientY &&
+ rect.bottom >= event.sensorEvent.clientY;
+
+ if (!isIn) {
+ continue;
+ }
+
+ const itemId = row.dataset.id ?? null;
+ let itemParentId = null;
+
+ if (!itemId) {
+ const parent = row.closest(`.list-group-item[data-id]`);
+
+ if (parent instanceof HTMLElement) {
+ // Over a plus row.
+ itemParentId = parent.dataset.id;
+ }
+ }
+
+ const itemIsAfter = event.sensorEvent.clientY - rect.top >= rect.bottom - event.sensorEvent.clientY;
+
+ if (itemParentId && itemIsAfter) {
+ continue;
+ }
+
+ if (itemId === this.movedId) {
+ break;
+ }
+
+ if (movedFromLi.contains(row)) {
+ break;
+ }
+
+ isAfter = itemIsAfter;
+ overParentId = itemParentId;
+ overId = itemId;
+ rowFound = row;
+
+ break;
+ }
+
+ for (const row of rows) {
+ row.classList.remove('border-top-highlighted');
+ row.classList.remove('border-bottom-highlighted');
+ }
+
+ if (!rowFound) {
+ return;
+ }
+
+ if (isAfter) {
+ rowFound.classList.add('border-bottom-highlighted');
+ rowFound.classList.remove('border-top-highlighted');
+ } else {
+ rowFound.classList.add('border-top-highlighted');
+ rowFound.classList.remove('border-bottom-highlighted');
+ }
+ });
+
+ draggable.on('drag:stop', () => {
+ if (movedLink) {
+ movedLink.classList.remove('text-info');
+ }
+
+ rows.forEach(row => {
+ row.classList.remove('border-bottom-highlighted');
+ row.classList.remove('border-top-highlighted');
+ });
+
+ rows = undefined;
+
+ this.movedId = null;
+ movedLink = null;
+ movedFromLi = null;
+ levelMap = undefined;
+ overParentId = null;
+ overId = null;
+ isAfter = false;
+ wasOutOfSelf = false;
+
+ // @todo Skip if no change.
+
+
+ //this.blockDraggable = true;
+ });
+ }
}
export default ListTreeRecordView;
diff --git a/frontend/less/espo/custom.less b/frontend/less/espo/custom.less
index c2e0645748..0c46b2666d 100644
--- a/frontend/less/espo/custom.less
+++ b/frontend/less/espo/custom.less
@@ -2928,18 +2928,69 @@ table.table td.cell .html-container {
.list-group-tree {
border: 0;
-}
-.list-group-tree > li {
- border: 0;
- padding: 0 0 0 var(--panel-padding);
+
+ > li {
+ border: 0;
+ padding: 0 0 0 var(--panel-padding);
+
+ .cell {
+ padding: var(--3px) 0;
+
+ .remove-link {
+ margin-left: var(--4px);
+ margin-right: var(--4px);
+ }
+ }
+ }
}
-.list-group-tree > li .cell {
- padding: var(--3px) 0;
+.list-tree {
+ &[data-editable="true"] {
+ .list-group-tree {
+ > li {
+ position: relative;
- .remove-link {
- margin-left: var(--4px);
- margin-right: var(--4px);
+ &.border-bottom-highlighted,
+ &.border-top-highlighted {
+ &::after {
+ display: block;
+ content: " ";
+ height: var(--2px);
+ width: var(--20px);
+ background-color: var(--gray-soft);
+ left: var(--30px);
+ position: absolute;
+ border-radius: var(--1px);
+ }
+ }
+
+ &.border-bottom-highlighted {
+ &::after {
+ bottom: var(--minus-1px);
+ }
+ }
+
+ &.border-top-highlighted {
+ &::after {
+ top: var(--minus-1px);
+ }
+ }
+
+ > .cell {
+ user-select: none;
+ }
+
+ a[data-action="fold"],
+ a[data-action="unfold"],
+ a[data-action="remove"],
+ a[data-action="create"] {
+ &,
+ &:hover {
+ color: var(--btn-text-color);
+ }
+ }
+ }
+ }
}
}
@@ -3978,6 +4029,10 @@ body:has(.modal-backdrop) {
opacity: 1;
position: absolute;
z-index: 10002;
+
+ &.draggable-helper-transparent {
+ opacity: 0.5;
+ }
}
.reminders-container {