Skip to content

EspoCRM – Open Source CRM Application

drag handle

Yuri Kuznetsov346d19f37e77
diff --git a/client/res/templates/record/list-tree-item.tpl b/client/res/templates/record/list-tree-item.tpl
index 188d92b04d..445a1c76ae 100644
--- a/client/res/templates/record/list-tree-item.tpl
+++ b/client/res/templates/record/list-tree-item.tpl
@@ -13,10 +13,28 @@
data-action="unfold"
data-id="{{model.id}}"><span class="fas fa-chevron-right"></span></a>
- <span data-name="white-space" data-id="{{model.id}}" class="empty-icon{{#unless isEnd}} hidden{{/unless}}">&nbsp;</span>
+ <span
+ data-name="white-space"
+ data-id="{{model.id}}"
+ class="empty-icon{{#unless isEnd}} hidden{{/unless}}"
+ >&nbsp;</span>
- <a href="#{{model.entityType}}/view/{{model.id}}"
- class="link{{#if isSelected}} text-bold{{/if}}" data-id="{{model.id}}" title="{{name}}"
+ {{#if isMovable}}
+ <a
+ role="button"
+ class=""
+ data-id="{{model.id}}"
+ data-role="moveHandle"
+ data-title="{{name}}"
+ ><span class="fas fa-grip fa-sm"></span></a>
+ {{/if}}
+
+ <a
+ href="#{{model.entityType}}/view/{{model.id}}"
+ class="link{{#if isSelected}} text-bold{{/if}}"
+ data-id="{{model.id}}"
+ title="{{name}}"
+ {{#unless readOnly}} draggable="false" {{/unless}}
>{{name}}</a>
{{#unless readOnly}}
@@ -24,7 +42,8 @@
role="button"
tabindex="0"
class="action small remove-link hidden"
- data-action="remove" data-id="{{model.id}}"
+ data-action="remove"
+ data-id="{{model.id}}"
title="{{translate 'Remove'}}"
>
<span class="fas fa-times"></span>
diff --git a/client/src/views/record/list-tree-item.js b/client/src/views/record/list-tree-item.js
index 6626bd260b..7b4654b9cb 100644
--- a/client/src/views/record/list-tree-item.js
+++ b/client/src/views/record/list-tree-item.js
@@ -53,6 +53,7 @@ class ListTreeRecordItemView extends View {
isEnd: this.isEnd,
isSelected: this.isSelected,
readOnly: this.readOnly,
+ isMovable: this.options.moveSupported && !this.options.readOnly,
};
}
@@ -77,6 +78,24 @@ class ListTreeRecordItemView extends View {
}
}
+ /**
+ * @param {{
+ * moveSupported: boolean,
+ * readOnly: boolean,
+ * isSelected?: boolean,
+ * level?: number,
+ * selectedData?: {path: string, name: Record},
+ * rootView: import('views/record/list-tree').default,
+ * selectable?: boolean,
+ * createDisabled?: boolean,
+ * }} options
+ */
+ constructor(options) {
+ super(options);
+
+ this.options = options;
+ }
+
setIsSelected() {
this.isSelected = true;
this.selectedData.id = this.model.id;
@@ -200,6 +219,7 @@ class ListTreeRecordItemView extends View {
model.isEnd = true;
}
+ /** @type {ListTreeRecordItemView|null} */
const itemView = childrenView.getView(id);
if (!itemView) {
@@ -211,6 +231,7 @@ class ListTreeRecordItemView extends View {
itemView.afterIsEnd();
});
+ // @todo Refactor.
this.model.lastAreChecked = true;
});
}
@@ -320,7 +341,7 @@ class ListTreeRecordItemView extends View {
this.$el.find(' > .children').addClass('hidden');
}
- getCurrentPath() {
+ /*getCurrentPath() {
let pointer = this;
const path = [];
@@ -335,7 +356,7 @@ class ListTreeRecordItemView extends View {
}
return path;
- }
+ }*/
actionRemove() {
this.confirm({
diff --git a/client/src/views/record/list-tree.js b/client/src/views/record/list-tree.js
index 482ed839b4..16681b2b8e 100644
--- a/client/src/views/record/list-tree.js
+++ b/client/src/views/record/list-tree.js
@@ -50,6 +50,7 @@ class ListTreeRecordView extends ListRecordView {
createDisabled = false
selectedData = null
level = 0
+
itemViewName = 'views/record/list-tree-item'
/**
@@ -153,6 +154,10 @@ class ListTreeRecordView extends ListRecordView {
this.selectedData = this.options.selectedData;
}
+ this.entityType = this.collection.entityType;
+
+ this.moveSupported = !!this.getMetadata().get(`entityDefs.${this.entityType}.fields.order`);
+
super.setup();
if (this.selectable) {
@@ -175,8 +180,6 @@ class ListTreeRecordView extends ListRecordView {
}
});
}
-
- this.moveSupported = !!this.getMetadata().get(`entityDefs.${this.entityType}.fields.order`);
}
afterRender() {
@@ -248,6 +251,7 @@ class ListTreeRecordView extends ListRecordView {
selectable: this.selectable,
setViewBeforeCallback: this.options.skipBuildRows && !this.isRendered(),
rootView: this.rootView,
+ moveSupported: this.moveSupported,
}, () => {
built++;
@@ -359,7 +363,7 @@ class ListTreeRecordView extends ListRecordView {
const draggable = this.draggable = new Draggable(this.element, {
distance: 8,
- draggable: '.list-group-item > .cell > .link',
+ draggable: '.list-group-item > .cell > [data-role="moveHandle"]',
mirror: {
cursorOffsetX: 5,
cursorOffsetY: 5,
@@ -391,6 +395,8 @@ class ListTreeRecordView extends ListRecordView {
mirror.style.pointerEvents = 'auto';
mirror.removeAttribute('href');
mirror.style.textDecoration = 'none';
+
+ mirror.innerText = mirror.dataset.title;
});
draggable.on('mirror:move', event => {
diff --git a/frontend/less/espo/custom.less b/frontend/less/espo/custom.less
index 0c46b2666d..6e97f17b09 100644
--- a/frontend/less/espo/custom.less
+++ b/frontend/less/espo/custom.less
@@ -2956,9 +2956,9 @@ table.table td.cell .html-container {
display: block;
content: " ";
height: var(--2px);
- width: var(--20px);
+ width: var(--11px);
background-color: var(--gray-soft);
- left: var(--30px);
+ left: var(--32px);
position: absolute;
border-radius: var(--1px);
}
@@ -2989,6 +2989,19 @@ table.table td.cell .html-container {
color: var(--btn-text-color);
}
}
+
+ a[data-role="moveHandle"] {
+ &,
+ &:hover {
+ color: var(--text-muted-color);
+ }
+
+ margin-left: var(--2px);
+ margin-right: var(--2px);
+
+ font-size: var(--12px);
+ cursor: grab;
+ }
}
}
}