Skip to content

EspoCRM – Open Source CRM Application

Side edit menu

Yuriief40541d9c11
diff --git a/client/res/templates/record/detail.tpl b/client/res/templates/record/detail.tpl
index d82c87c2a8..0f3b285fdd 100644
--- a/client/res/templates/record/detail.tpl
+++ b/client/res/templates/record/detail.tpl
@@ -38,6 +38,10 @@
class="btn-group actions-btn-group"
role="group"
>{{{editButtons}}}</div>
+ <div
+ class="btn-group pull-right"
+ role="group"
+ >{{{editSideButtons}}}</div>
</div>
</div>
{{/unless}}
diff --git a/client/res/templates/record/edit.tpl b/client/res/templates/record/edit.tpl
index 6aa9605351..479f666799 100644
--- a/client/res/templates/record/edit.tpl
+++ b/client/res/templates/record/edit.tpl
@@ -6,6 +6,10 @@
class="btn-group actions-btn-group"
role="group"
>{{{buttons}}}</div>
+ <div
+ class="btn-group pull-right"
+ role="group"
+ >{{{sideButtons}}}</div>
</div>
</div>
{{/unless}}
diff --git a/client/src/helpers/action-item-setup.js b/client/src/helpers/action-item-setup.js
index 9c34f7168f..db63a97179 100644
--- a/client/src/helpers/action-item-setup.js
+++ b/client/src/helpers/action-item-setup.js
@@ -69,10 +69,16 @@ class ActionItemSetupHelper {
* view: import('view').default<any>,
* type: string,
* waitFunc: (Promise) => void,
- * addFunc: (item: import('views/record/detail').DropdownItem) => void,
+ * addFunc: (
+ * item: import('views/record/detail').DropdownItem |
+ * import('views/record/detail').Button
+ * ) => void,
* showFunc: (string) => void,
* hideFunc: (string) => void,
+ * enableFunc?: (string) => void,
+ * disableFunc?: (string) => void,
* listenToViewModelSync?: boolean,
+ * syncEvent?: 'sync'|'change',
* }} options
*/
setup(options) {
@@ -82,7 +88,10 @@ class ActionItemSetupHelper {
const addFunc = options.addFunc;
const showFunc = options.showFunc;
const hideFunc = options.hideFunc;
+ const enableFunc = options.enableFunc ?? (() => {});
+ const disableFunc = options.disableFunc ?? (() => {});
+ /** @type {Record[]} */
const actionList = [];
// noinspection JSUnresolvedReference
@@ -92,13 +101,15 @@ class ActionItemSetupHelper {
throw new Error();
}
+ const path = type.split('.');
+
/** @type {({name?: string} & Record | string)[]} */
const actionDefsListOriginal = [
- ...this.metadata.get(['clientDefs', 'Global', type]) || [],
- ...this.metadata.get(['clientDefs', scope, type]) || [],
+ ...this.metadata.get(['clientDefs', 'Global', ...path], []),
+ ...this.metadata.get(['clientDefs', scope, ...path], []),
];
- /** @type {({name?: string} & Object.<string, *>)[]} */
+ /** @type {({name?: string} & Record<string, any>)[]} */
let actionDefsList = actionDefsListOriginal.map(item => {
if (typeof item === 'string') {
return {name: item};
@@ -146,7 +157,7 @@ class ActionItemSetupHelper {
return;
}
- if (!item.initFunction && !item.checkVisibilityFunction) {
+ if (!item.initFunction && !item.checkVisibilityFunction && !item.checkAvailabilityFunction) {
return;
}
@@ -166,6 +177,14 @@ class ActionItemSetupHelper {
}
}
+ if (item?.checkAvailabilityFunction) {
+ const isNotAvailable = !handler[item.checkAvailabilityFunction].call(handler);
+
+ if (isNotAvailable) {
+ disableFunc(item.name);
+ }
+ }
+
item.handlerInstance = handler;
resolve();
@@ -177,11 +196,27 @@ class ActionItemSetupHelper {
return;
}
+ const onChange = () => {
+ actionList.forEach(item => {
+ const handler = item.handlerInstance;
+
+ if (!handler || !item.checkAvailabilityFunction) {
+ return;
+ }
+ const isAvailable = handler[item.checkAvailabilityFunction].call(handler);
+
+ isAvailable ?
+ enableFunc(item.name) :
+ disableFunc(item.name);
+ });
+ }
+
const onSync = () => {
actionList.forEach(item => {
- if (item.handlerInstance && item.checkVisibilityFunction) {
- const isNotVisible = !item.handlerInstance[item.checkVisibilityFunction]
- .call(item.handlerInstance);
+ const handler = item.handlerInstance;
+
+ if (handler && item.checkVisibilityFunction) {
+ const isNotVisible = !handler[item.checkVisibilityFunction].call(handler);
if (isNotVisible) {
hideFunc(item.name);
@@ -206,7 +241,8 @@ class ActionItemSetupHelper {
return;
}
- view.listenTo(view.model, 'sync', () => onSync());
+ view.listenTo(view.model, 'change', () => onChange());
+ view.listenTo(view.model, options.syncEvent ?? 'sync', () => onSync());
}
}
diff --git a/client/src/views/modals/edit.js b/client/src/views/modals/edit.js
index 434e831d98..9c1a3d93f5 100644
--- a/client/src/views/modals/edit.js
+++ b/client/src/views/modals/edit.js
@@ -556,7 +556,22 @@ class EditModalView extends ModalView {
addFunc: item => this.addDropdownItem(item),
showFunc: name => this.showActionItem(name),
hideFunc: name => this.hideActionItem(name),
- listenToViewModelSync: true,
+ });
+
+ actionItemSetup.setup({
+ view: this,
+ type: 'recordControls.modelEditSide.buttons',
+ waitFunc: promise => this.wait(promise),
+ addFunc: item => {
+ this.addButton({
+ ...item,
+ position: 'right',
+ })
+ },
+ showFunc: name => this.showActionItem(name),
+ hideFunc: name => this.hideActionItem(name),
+ enableFunc: name => this.enableButton(name),
+ disableFunc: name => this.disableButton(name),
});
}
}
diff --git a/client/src/views/record/detail.ts b/client/src/views/record/detail.ts
index d342a28e5e..c46d3fc09d 100644
--- a/client/src/views/record/detail.ts
+++ b/client/src/views/record/detail.ts
@@ -101,6 +101,12 @@ export interface Button {
* A click handler.
*/
onClick?: () => void;
+ /**
+ * An icon class.
+ *
+ * @since 10.0.0
+ */
+ iconClass?: string;
}
/**
@@ -497,6 +503,20 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
},
]
+ /**
+ * Side buttons for edit mode.
+ *
+ * @since 10.0.0
+ */
+ protected sideButtonList: Button[] = []
+
+ /**
+ * Side buttons for edit mode.
+ *
+ * @since 10.0.0
+ */
+ protected sideButtonEditList: Button[] = []
+
/**
* A dropdown item list for edit mode.
*/
@@ -1027,9 +1047,9 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
return;
}
- if (this.type === this.TYPE_DETAIL) {
- const actionItemSetup = new ActionItemSetup();
+ const actionItemSetup = new ActionItemSetup();
+ if (this.type === this.TYPE_DETAIL) {
actionItemSetup.setup({
view: this,
type: 'detailActionList',
@@ -1037,6 +1057,8 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
addFunc: item => this.addDropdownItem(item),
showFunc: name => this.showActionItem(name),
hideFunc: name => this.hideActionItem(name),
+ enableFunc: name => this.enableActionItem(name),
+ disableFunc: name => this.disableActionItem(name),
});
if (this.saveAndContinueEditingAction) {
@@ -1050,8 +1072,6 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
}
if (this.type === this.TYPE_EDIT || this.type === this.TYPE_DETAIL) {
- const actionItemSetup = new ActionItemSetup();
-
actionItemSetup.setup({
view: this,
type: 'editActionList',
@@ -1065,6 +1085,25 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
},
showFunc: name => this.showActionItem(name),
hideFunc: name => this.hideActionItem(name),
+ enableFunc: name => this.enableActionItem(name),
+ disableFunc: name => this.disableActionItem(name),
+ });
+
+ actionItemSetup.setup({
+ view: this,
+ type: 'recordControls.editSide.buttons',
+ waitFunc: promise => this.wait(promise),
+ addFunc: item => {
+ if (this.type === this.TYPE_EDIT) {
+ this.sideButtonList.push(item);
+ } else {
+ this.sideButtonEditList.push(item);
+ }
+ },
+ showFunc: name => this.showActionItem(name),
+ hideFunc: name => this.hideActionItem(name),
+ enableFunc: name => this.enableActionItem(name),
+ disableFunc: name => this.disableActionItem(name),
});
}
}
@@ -1091,43 +1130,15 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
hideActionItem(name: string) {
let changed = false;
- for (const item of this.buttonList) {
- if (item.name === name) {
- changed ||= !item.hidden;
-
- item.hidden = true;
-
- break;
- }
- }
-
- for (const item of this.dropdownItemList) {
- if (item.name === name) {
- changed ||= !item.hidden
-
- item.hidden = true;
-
- break;
- }
- }
-
- for (const item of this.dropdownEditItemList) {
- if (item.name === name) {
- changed ||= !item.hidden
-
- item.hidden = true;
+ for (const list of this.getActionGroups()) {
+ for (const item of list) {
+ if (item.name === name) {
+ changed ||= !item.hidden;
- break;
- }
- }
+ item.hidden = true;
- for (const item of this.buttonEditList) {
- if (item.name === name) {
- changed ||= !item.hidden
-
- item.hidden = true;
-
- break;
+ break;
+ }
}
}
@@ -1140,6 +1151,17 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
}
}
+ private getActionGroups(): (Button[]|DropdownItem[])[] {
+ return [
+ this.buttonList,
+ this.dropdownItemList,
+ this.dropdownEditItemList,
+ this.buttonEditList,
+ this.sideButtonList,
+ this.sideButtonEditList,
+ ];
+ }
+
/**
* Show a button or dropdown action item.
*
@@ -1148,43 +1170,15 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
showActionItem(name: string) {
let changed: any = false;
- for (const item of this.buttonList) {
- if (item.name === name) {
- changed ||= item.hidden;
-
- item.hidden = false;
-
- break;
- }
- }
-
- for (const item of this.dropdownItemList) {
- if (item.name === name) {
- changed ||= item.hidden;
-
- item.hidden = false;
-
- break;
- }
- }
+ for (const list of this.getActionGroups()) {
+ for (const item of list) {
+ if (item.name === name) {
+ changed ||= item.hidden;
- for (const item of this.dropdownEditItemList) {
- if (item.name === name) {
- changed ||= item.hidden;
-
- item.hidden = false;
-
- break;
- }
- }
+ item.hidden = false;
- for (const item of this.buttonEditList) {
- if (item.name === name) {
- changed ||= item.hidden;
-
- item.hidden = false;
-
- break;
+ break;
+ }
}
}
@@ -1206,48 +1200,20 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
disableActionItem(name: string) {
let changed = false;
- for (const item of this.buttonList) {
- if (item.name === name) {
- changed ||= !item.disabled;
-
- item.disabled = true;
-
- break;
- }
- }
-
- for (const item of this.dropdownItemList) {
- if (item.name === name) {
- changed ||= !item.disabled;
-
- item.disabled = true;
+ for (const list of this.getActionGroups()) {
+ for (const item of list) {
+ if (item.name === name) {
+ changed ||= !item.disabled;
- break;
- }
- }
-
- for (const item of this.dropdownEditItemList) {
- if (item.name === name) {
- changed ||= !item.disabled;
+ item.disabled = true;
- item.disabled = true;
-
- break;
- }
- }
-
- for (const item of this.buttonEditList) {
- if (item.name === name) {
- changed ||= !item.disabled;
-
- item.disabled = true;
-
- break;
+ break;
+ }
}
}
if (!changed) {
- return false;
+ return;
}
if (this.isRendered()) {
@@ -1264,48 +1230,20 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
enableActionItem(name: string) {
let changed: any = false;
- for (const item of this.buttonList) {
- if (item.name === name) {
- changed ||= item.disabled;
-
- item.disabled = false;
-
- break;
- }
- }
-
- for (const item of this.dropdownItemList) {
- if (item.name === name) {
- changed ||= item.disabled;
-
- item.disabled = false;
-
- break;
- }
- }
-
- for (const item of this.dropdownEditItemList) {
- if (item.name === name) {
- changed ||= item.disabled;
-
- item.disabled = false;
-
- break;
- }
- }
-
- for (const item of this.buttonEditList) {
- if (item.name === name) {
- changed ||= item.disabled;
+ for (const list of this.getActionGroups()) {
+ for (const item of list) {
+ if (item.name === name) {
+ changed ||= item.disabled;
- item.disabled = false;
+ item.disabled = false;
- break;
+ break;
+ }
}
}
if (!changed) {
- return false;
+ return;
}
if (this.isRendered()) {
@@ -1323,27 +1261,34 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
return false;
}
- if (this.type === this.TYPE_DETAIL && this.mode === this.MODE_EDIT) {
- const hasButton = this.buttonEditList
- .findIndex(item => item.name === name && !item.disabled && !item.hidden) !== -1;
+ let groups: (Button[] | DropdownItem[])[];
- if (hasButton) {
- return true;
- }
+ if (this.type === this.TYPE_DETAIL && this.mode === this.MODE_EDIT) {
+ groups = [
+ this.buttonEditList,
+ this.dropdownEditItemList,
+ this.sideButtonEditList,
+ ];
- return this.dropdownEditItemList
- .findIndex(item => item.name === name && !item.disabled && !item.hidden) !== -1;
+ } else {
+ groups = [
+ this.buttonList,
+ this.dropdownItemList,
+ this.sideButtonList,
+ ];
}
- const hasButton = this.buttonList
- .findIndex(item => item.name === name && !item.disabled && !item.hidden) !== -1;
+ for (const list of groups) {
+ const has = list.findIndex((item: Button | DropdownItem) => {
+ return item.name === name && !item.disabled && !item.hidden;
+ }) !== -1
- if (hasButton) {
- return true;
+ if (has) {
+ return true;
+ }
}
- return this.dropdownItemList
- .findIndex(item => item.name === name && !item.disabled && !item.hidden) !== -1;
+ return false;
}
/**
@@ -1935,6 +1880,8 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
this.buttonEditList = Utils.cloneDeep(this.buttonEditList);
this.dropdownItemList = Utils.cloneDeep(this.dropdownItemList);
this.dropdownEditItemList = Utils.cloneDeep(this.dropdownEditItemList);
+ this.sideButtonList = Utils.cloneDeep(this.sideButtonList);
+ this.sideButtonEditList = Utils.cloneDeep(this.sideButtonEditList);
this.returnAfterCreate = this.options.returnAfterCreate ?? false;
@@ -2110,6 +2057,10 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
actionItems = [...this.buttonList, ...this.dropdownItemList]
} else if (target.classList.contains('edit-action-item')) {
actionItems = [...this.buttonEditList, ...this.dropdownEditItemList];
+ } else if (target.classList.contains('side-action-item')) {
+ actionItems = [...this.sideButtonList];
+ } else if (target.classList.contains('edit-side-action-item')) {
+ actionItems = [...this.sideButtonEditList];
}
Utils.handleAction(this, event as MouseEvent, target, {actionItems: actionItems});
@@ -3906,6 +3857,36 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
});
this.assignView('editButtons', editButtonsView);
+
+ const editSideButtonsView = new DetailRecordButtonsView({
+ entityType: this.entityType,
+ dataProvider: () => {
+ return {
+ buttonList: this.sideButtonEditList,
+ dropdownItemList: [],
+ allDisabled: this.allActionItemsDisabled,
+ };
+ },
+ actionClassName: 'edit-side-action-item',
+ });
+
+ this.assignView('editSideButtons', editSideButtonsView);
+ }
+
+ if (this.type === 'edit') {
+ const sideButtonsView = new DetailRecordButtonsView({
+ entityType: this.entityType,
+ dataProvider: () => {
+ return {
+ buttonList: this.sideButtonList,
+ dropdownItemList: [],
+ allDisabled: this.allActionItemsDisabled,
+ };
+ },
+ actionClassName: 'side-action-item',
+ });
+
+ this.assignView('sideButtons', sideButtonsView);
}
}
@@ -3917,9 +3898,19 @@ class DetailRecordView<S extends DetailRecordViewSchema = DetailRecordViewSchema
return this.getView<DetailRecordButtonsView>('editButtons');
}
+ private getSideButtonsView(): DetailRecordButtonsView | null {
+ return this.getView<DetailRecordButtonsView>('sideButtons');
+ }
+
+ private getEditSideButtonsView(): DetailRecordButtonsView | null {
+ return this.getView<DetailRecordButtonsView>('editSideButtons');
+ }
+
private reRenderButtons() {
this.getButtonsView()?.reRender({buffer: true});
this.getEditButtonsView()?.reRender({buffer: true});
+ this.getSideButtonsView()?.reRender({buffer: true});
+ this.getEditSideButtonsView()?.reRender({buffer: true});
}
/**
diff --git a/client/src/views/record/detail/buttons.ts b/client/src/views/record/detail/buttons.ts
index 4c727cc94a..4be1ed14dc 100644
--- a/client/src/views/record/detail/buttons.ts
+++ b/client/src/views/record/detail/buttons.ts
@@ -64,6 +64,7 @@ export default class DetailRecordButtonsView extends View<{
className: data.buttonClassName,
hidden: it.hidden,
disabled: it.disabled || data.allDisabled,
+ iconClass: it.iconClass,
}).node()
);
});
diff --git a/schema/metadata/clientDefs.json b/schema/metadata/clientDefs.json
index 89a7d8e365..5402566e57 100644
--- a/schema/metadata/clientDefs.json
+++ b/schema/metadata/clientDefs.json
@@ -762,6 +762,31 @@
]
}
},
+ "recordControls": {
+ "description": "Record controls. To be used for arbitrary action elements. As of v10.0.",
+ "type": "object",
+ "propertyNames": {
+ "enum": [
+ "editSide",
+ "modelEditSide"
+ ]
+ },
+ "additionalProperties": {
+ "type": "object",
+ "propertyNames": {
+ "enum": ["buttons"]
+ },
+ "additionalProperties": {
+ "type": "array",
+ "items": {
+ "anyOf": [
+ {"enum": ["__APPEND__"]},
+ {"$ref": "#/definitions/actionDefs"}
+ ]
+ }
+ }
+ }
+ },
"iconClass": {
"description": "A scope icon CSS class.",
"type": "string"
@@ -911,7 +936,11 @@
},
"checkVisibilityFunction": {
"type": "string",
- "description": "A handler function that checks whether the action is available. Should return a boolean value. Called on model sync."
+ "description": "A handler function that checks whether the action is visible. Should return a boolean value. Called on model sync."
+ },
+ "checkAvailabilityFunction": {
+ "type": "string",
+ "description": "A handler function that checks whether the action is available. Should return a boolean value. As of v10.0."
},
"configCheck": {
"description": "A config path (separated by the .) to check whether the action is enabled. The ! prefix reverts.",