Skip to content

EspoCRM – Open Source CRM Application

Use Virtual DOM for modal buttons

Yurii1fe0b2856feb
diff --git a/client/modules/crm/src/views/meeting/modals/detail.js b/client/modules/crm/src/views/meeting/modals/detail.js
index 003d0f22e6..9534441ccb 100644
--- a/client/modules/crm/src/views/meeting/modals/detail.js
+++ b/client/modules/crm/src/views/meeting/modals/detail.js
@@ -225,26 +225,7 @@ class MeetingModalDetailView extends DetailModalView {
showAcceptanceButton() {
this.showActionItem('setAcceptanceStatus');
-
- if (!this.isRendered()) {
- this.once('after:render', this.showAcceptanceButton, this);
-
- return;
- }
-
- const data = this.getAcceptanceButtonData();
-
- const $button = this.$el.find('.modal-footer [data-name="setAcceptanceStatus"]');
-
- $button.html(data.html);
-
- $button.removeClass('btn-default');
- $button.removeClass('btn-success');
- $button.removeClass('btn-warning');
- $button.removeClass('btn-info');
- $button.removeClass('btn-primary');
- $button.removeClass('btn-danger');
- $button.addClass('btn-' + data.style);
+ this.updateActionItem('setAcceptanceStatus', this.getAcceptanceButtonData());
}
hideAcceptanceButton() {
diff --git a/client/src/components/controls.ts b/client/src/components/controls.ts
index ead1a327cd..d23e1555e3 100644
--- a/client/src/components/controls.ts
+++ b/client/src/components/controls.ts
@@ -47,6 +47,7 @@ interface ButtonOptions {
html?: string | null;
iconHtml?: string | null;
data?: Record<string, unknown>;
+ onClick?: (event: MouseEvent) => void;
}
interface DropdownItemOptions {
@@ -65,6 +66,7 @@ interface DropdownItemOptions {
html?: string | null;
iconHtml?: string | null;
data?: Record<string, unknown>;
+ onClick?: (event: MouseEvent) => void;
}
/**
@@ -84,7 +86,7 @@ export class ButtonComponent {
'btn': true,
'disabled': this.options.disabled === true,
'hidden': this.options.hidden === true,
- 'action': true,
+ 'action': this.options.action != null,
};
const style = this.options.style ?? 'default';
@@ -114,6 +116,12 @@ export class ButtonComponent {
const {content, props} = prepareItemContent(this.options, this.language);
+ const on: any = {};
+
+ if (this.options.onClick) {
+ on.click = (event: MouseEvent) => this.options.onClick!(event)
+ }
+
return h(tag, {
key: this.options.name ?? undefined,
class: classes,
@@ -121,9 +129,10 @@ export class ButtonComponent {
dataset: {
...this.options.data,
name: (this.options.name ?? undefined)!,
- action: (this.options.action ?? this.options.name ?? undefined)!,
+ action: (this.options.action ?? undefined)!,
},
props,
+ on: on,
}, content);
}
}
@@ -144,7 +153,7 @@ export class DropdownItemComponent {
const classes: any = {
'disabled': this.options.disabled === true,
'hidden': this.options.hidden === true,
- 'action': true,
+ 'action': this.options.action != null,
};
if (this.options.className) {
@@ -173,15 +182,22 @@ export class DropdownItemComponent {
attrs.role = 'button';
}
+ const on: any = {};
+
+ if (this.options.onClick) {
+ on.click = (event: MouseEvent) => this.options.onClick!(event)
+ }
+
const a = h('a', {
class: classes,
attrs: attrs,
dataset: {
...this.options.data,
name: (this.options.name ?? undefined)!,
- action: (this.options.action ?? this.options.name ?? undefined)!,
+ action: (this.options.action ?? undefined)!,
},
props: props,
+ on: on,
}, content);
return h('li', {
diff --git a/client/src/ui/dialog.ts b/client/src/ui/dialog.ts
index 4997836e96..5384c73bc3 100644
--- a/client/src/ui/dialog.ts
+++ b/client/src/ui/dialog.ts
@@ -26,6 +26,9 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
+import {h, patch, VNode} from 'bullbone';
+import {ButtonComponent, DropdownItemComponent} from 'components/controls';
+
const shownDialogList: Dialog[] = [];
/**
@@ -74,8 +77,8 @@ export interface DialogButton {
text?: string;
disabled?: boolean;
hidden?: boolean;
- style?: 'default' | 'danger' | 'success' | 'warning';
- onClick?: (dialog: Dialog, event: MouseEvent, target: HTMLElement) => void;
+ style?: 'default' | 'danger' | 'success' | 'warning' | 'info' | 'text';
+ onClick?: (dialog: Dialog, event: MouseEvent) => void;
className?: string;
title?: string;
groupIndex?: number;
@@ -122,6 +125,12 @@ class Dialog {
private readonly el: HTMLElement
private $mouseDownTarget: JQuery | undefined
+ private footerComponent: FooterComponent
+
+ private readonly footerElement: HTMLElement | null = null
+
+ private footerVNode: VNode | null = null
+
/**
* @param options Options.
*/
@@ -184,8 +193,22 @@ class Dialog {
this.backdrop = 'static';
}
+ const hasFooter = !!(this.buttonList.length || this.dropdownItemList.length);
+
+ this.footerComponent = new FooterComponent({
+ dataProvider: () => ({
+ buttonList: this.buttonList,
+ dropdownItemList: this.dropdownItemList,
+ })
+ }, this);
+
+ if (hasFooter) {
+ this.footerElement = document.createElement('footer');
+
+ this.footerVNode = patch(this.footerElement, this.footerComponent.node());
+ }
+
const $header = this.getHeader();
- const $footer = this.getFooter();
const $body = $('<div>')
.addClass('modal-body body')
@@ -197,14 +220,14 @@ class Dialog {
$content.append($header);
}
- if ($footer && this.options.footerAtTheTop) {
- $content.append($footer);
+ if (this.footerElement && this.options.footerAtTheTop) {
+ $content.append(this.footerElement);
}
$content.append($body);
- if ($footer && !this.options.footerAtTheTop) {
- $content.append($footer);
+ if (this.footerElement && !this.options.footerAtTheTop) {
+ $content.append(this.footerElement);
}
const $dialog = $('<div>')
@@ -228,7 +251,7 @@ class Dialog {
//this.close();
});*/
- this.initButtonEvents();
+ //this.initButtonEvents();
if (this.draggable) {
this.$el.find('header').css('cursor', 'pointer');
@@ -386,13 +409,14 @@ class Dialog {
* Init button events.
*/
initButtonEvents() {
- this.buttonList.forEach(item => {
+ /*this.buttonList.forEach(item => {
if (typeof item.onClick !== 'function') {
return;
}
const $button = $(`#${this.id} .modal-footer button[data-name="${item.name}"]`);
+ $button.off('click');
$button.on('click', e => item.onClick?.(this, e.originalEvent as MouseEvent, e.currentTarget));
});
@@ -407,8 +431,9 @@ class Dialog {
const $button = $(`#${this.id} .modal-footer a[data-name="${item.name}"]`);
+ $button.off('click');
$button.on('click', e => item.onClick?.(this, e.originalEvent as MouseEvent, e.currentTarget));
- });
+ });*/
}
private getHeader(): JQuery | null {
@@ -523,130 +548,14 @@ class Dialog {
}
/**
- * Get a footer.
+ * @internal
*/
- getFooter(): JQuery | null {
- if (!this.buttonList.length && !this.dropdownItemList.length) {
- return null;
- }
-
- const $footer = $('<footer>').addClass('modal-footer');
-
- const $main = $('<div>')
- .addClass('btn-group')
- .addClass('main-btn-group');
-
- const $additional = $('<div>')
- .addClass('btn-group')
- .addClass('additional-btn-group');
-
- this.buttonList.forEach(o => {
- const style = o.style || 'default';
-
- const $button =
- $('<button>')
- .attr('type', 'button')
- .attr('data-name', o.name)
- .addClass('btn')
- .addClass('btn-' + style)
- .addClass(o.className || 'btn-xs-wide');
-
- if (o.disabled) {
- $button.attr('disabled', 'disabled');
- $button.addClass('disabled');
- }
-
- if (o.hidden) {
- $button.addClass('hidden');
- }
-
- if (o.title) {
- $button.attr('title', o.title);
- }
-
- if (o.text) {
- $button.text(o.text);
- }
-
- if (o.html) {
- $button.html(o.html);
- }
-
- if (o.pullLeft || o.position === 'right') {
- $additional.append($button);
-
- return;
- }
-
- $main.append($button);
- });
-
- const allDdItemsHidden = this.dropdownItemList.filter(o => o && !o.hidden).length === 0;
-
- const $dropdown = $('<div>')
- .addClass('btn-group')
- .addClass(allDdItemsHidden ? 'hidden' : '')
- .append(
- $('<button>')
- .attr('type', 'button')
- .addClass('btn btn-default dropdown-toggle')
- .addClass(allDdItemsHidden ? 'hidden' : '')
- .attr('data-toggle', 'dropdown')
- .append(
- $('<span>').addClass('fas fa-ellipsis-h')
- )
- );
-
- const $ul = $('<ul>').addClass('dropdown-menu pull-right');
-
- $dropdown.append($ul);
-
- this.dropdownItemList.forEach((o, i) => {
- if (o === false) {
- if (i === this.dropdownItemList.length - 1) {
- return;
- }
-
- $ul.append(`<li class="divider"></li>`);
-
- return;
- }
-
- const $a = $('<a>')
- .attr('role', 'button')
- .attr('tabindex', '0')
- .attr('data-name', o.name);
-
- if (o.text) {
- $a.text(o.text);
- }
-
- if (o.title) {
- $a.attr('title', o.title);
- }
-
- if (o.html) {
- $a.html(o.html);
- }
-
- const $li = $('<li>')
- .addClass(o.hidden ? ' hidden' : '')
- .append($a);
-
- $ul.append($li);
- });
-
- if ($ul.children().length) {
- $main.append($dropdown);
- }
-
- if ($additional.children().length) {
- $footer.append($additional);
+ reRenderFooter() {
+ if (!this.footerElement) {
+ return;
}
- $footer.append($main);
-
- return $footer;
+ this.footerVNode = patch(this.footerVNode ?? this.footerElement, this.footerComponent.node());
}
/**
@@ -860,3 +769,125 @@ class Dialog {
}
export default Dialog;
+
+
+class FooterComponent {
+
+ constructor(
+ private options: {
+ dataProvider: () => {
+ buttonList: DialogButton[];
+ dropdownItemList: (DialogButton | false)[];
+ }
+ },
+ private dialog: Dialog,
+ ) {}
+
+ protected getPreparedData() {
+ const data = this.options.dataProvider();
+
+ const buttonList = data.buttonList.filter(it => !it.hidden);
+
+ const dropdownItemList = data.dropdownItemList
+ .filter(it => it === false || !it.hidden)
+ .filter((it, i, list) => {
+ if (it === false && (i === 0 || i === list.length - 1)) {
+ return false;
+ }
+
+ if (it === false && list[i - 1] === false) {
+ return false;
+ }
+
+ return true;
+ });
+
+ return {buttonList, dropdownItemList};
+ }
+
+ node() {
+ const data = this.getPreparedData();
+
+ const elements: any[] = [];
+
+ const left: any[] = [];
+ const right: any[] = [];
+ const lis: any[] = [];
+
+ data.buttonList.forEach(it => {
+ const button = new ButtonComponent({
+ name: it.name,
+ className: it.className ?? 'btn-xs-wide',
+ style: it.style,
+ title: it.title,
+ hidden: it.hidden,
+ disabled: it.disabled,
+ text: it.text,
+ html: it.html,
+ onClick: event => {
+ if (it.onClick) {
+ it.onClick(this.dialog, event);
+ }
+ },
+ }).node();
+
+ it.pullLeft || it.position === 'right' ?
+ right.push(button) :
+ left.push(button);
+ });
+
+ data.dropdownItemList.forEach(it => {
+ if (it === false) {
+ lis.push(
+ h('li', {class: {'divider': true}})
+ );
+
+ return;
+ }
+
+ lis.push(
+ new DropdownItemComponent({
+ name: it.name,
+ title: it.title,
+ hidden: it.hidden,
+ disabled: it.disabled,
+ text: it.text,
+ html: it.html,
+ onClick: event => {
+ if (it.onClick) {
+ it.onClick(this.dialog, event);
+ }
+ },
+ }).node()
+ )
+ });
+
+ if (lis.length) {
+ left.push(
+ h(
+ 'button',
+ {
+ key: '_menu-dropdown-button',
+ attrs: {type: 'button'},
+ props: {
+ className: 'btn btn-default dropdown-toggle',
+ },
+ dataset: {toggle: 'dropdown'},
+ },
+ h('span', {props: {className: 'fas fa-ellipsis-h'}})
+ ),
+ h('ul', {props: {className: 'dropdown-menu pull-right'}}, lis)
+ );
+ }
+
+ elements.push(
+ h('div', {props: {className: 'btn-group main-btn-group'}}, left),
+ );
+
+ elements.push(
+ h('div', {props: {className: 'btn-group additional-btn-group'}}, right),
+ );
+
+ return h('footer', {props: {className: 'modal-footer'}}, elements);
+ }
+}
diff --git a/client/src/views/main/header-buttons.ts b/client/src/views/main/header-buttons.ts
index 61ad4e4980..add2f315da 100644
--- a/client/src/views/main/header-buttons.ts
+++ b/client/src/views/main/header-buttons.ts
@@ -50,10 +50,6 @@ export default class HeaderButtonsView extends View<{
@inject(Language)
private language: Language
- protected data() {
- return this.options.dataProvider();
- }
-
protected content(): VNode {
const data = this.options.dataProvider();
@@ -62,8 +58,8 @@ export default class HeaderButtonsView extends View<{
const dropdown = data.dropdown
.filter(it => it === false || !it.hidden)
.filter((it, i, list) => {
- if (i === 0) {
- return true;
+ if (it === false && (i === 0 || i === list.length - 1)) {
+ return false;
}
if (it === false && list[i - 1] === false) {
@@ -82,7 +78,7 @@ export default class HeaderButtonsView extends View<{
new ButtonComponent({
scope: this.options.scope,
name: it.name ?? null,
- action: it.action,
+ action: it.action ?? it.name,
link: it.link,
text: it.text,
label: it.label,
@@ -124,7 +120,7 @@ export default class HeaderButtonsView extends View<{
dropdownItems.push(
new DropdownItemComponent({
name: it.name ?? null,
- action: it.action,
+ action: it.action ?? it.name,
scope: this.options.scope,
link: it.link,
label: it.label,
@@ -161,12 +157,8 @@ export default class HeaderButtonsView extends View<{
const dropdownItems: any[] = [];
- dropdown.forEach((it, i) => {
+ dropdown.forEach(it => {
if (it === false) {
- if (i === 0 || i === data.dropdown.length - 1) {
- return;
- }
-
dropdownItems.push(
h('li', {class: {'divider': true}})
);
@@ -177,7 +169,7 @@ export default class HeaderButtonsView extends View<{
dropdownItems.push(
new DropdownItemComponent({
name: it.name ?? null,
- action: it.action,
+ action: it.action ?? it.name,
scope: this.options.scope,
link: it.link,
label: it.label,
diff --git a/client/src/views/modal.ts b/client/src/views/modal.ts
index 83410c6706..62334a0975 100644
--- a/client/src/views/modal.ts
+++ b/client/src/views/modal.ts
@@ -93,7 +93,7 @@ interface ActionItem {
/**
* A style.
*/
- style?: 'primary' | 'danger' | 'success' | 'warning' | 'text';
+ style?: 'primary' | 'danger' | 'success' | 'warning' | 'info' | 'text';
/**
* An icon HTML.
*/
@@ -303,9 +303,11 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
/**
* Use a flexible header font size.
*/
- protected flexibleHeaderFontSize: boolean;
+ protected flexibleHeaderFontSize: boolean
- private fontSizePercentage: number;
+ private fontSizePercentage: number
+
+ private footerReRenderPromise: Promise<void> | null = null
protected init() {
this.addHandler('click', '.action', (e, target) => {
@@ -502,10 +504,10 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
'<span>' + this.getHelper().escapeString(o.text as string) + '</span>';
}
- o.onClick = o.onClick ?? ((_d, event, target) => {
+ o.onClick = o.onClick ?? ((_d, event) => {
const handler = o.handler || (o.data || {}).handler;
- Utils.handleAction(this, event, target, {
+ Utils.handleAction(this, event, event.target as HTMLElement, {
action: o.name,
handler: handler,
actionFunction: o.actionFunction,
@@ -549,7 +551,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
// noinspection ES6ConvertLetToConst
let handler = o.handler || (o.data || {}).handler;
- Utils.handleAction(this, e.originalEvent, e.currentTarget, {
+ Utils.handleAction(this, e, e.target, {
action: o.name,
handler: handler,
actionFunction: o.actionFunction,
@@ -647,25 +649,19 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
* @param name A button name.
*/
disableButton(name: string) {
- this.buttonList.forEach((d) => {
- if (d.name !== name) {
+ this.buttonList.forEach(item => {
+ if (item.name !== name) {
return;
}
- d.disabled = true;
+ item.disabled = true;
});
if (!this.isRendered()) {
return;
}
- if (!this.containerElement) {
- return;
- }
-
- $(this.containerElement).find(`footer button[data-name="${name}"]`)
- .addClass('disabled')
- .attr('disabled', 'disabled');
+ this.reRenderFooter();
}
/**
@@ -674,25 +670,19 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
* @param name A button name.
*/
enableButton(name: string) {
- this.buttonList.forEach((d) => {
- if (d.name !== name) {
+ this.buttonList.forEach(item => {
+ if (item.name !== name) {
return;
}
- d.disabled = false;
+ item.disabled = false;
});
if (!this.isRendered()) {
return;
}
- if (!this.containerElement) {
- return;
- }
-
- $(this.containerElement).find('footer button[data-name="'+name+'"]')
- .removeClass('disabled')
- .removeAttr('disabled');
+ this.reRenderFooter();
}
/**
@@ -718,8 +708,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
if (position === true) {
this.buttonList.unshift(o);
- }
- else if (typeof position === 'string') {
+ } else if (typeof position === 'string') {
index = -1;
this.buttonList.forEach((item, i) => {
@@ -776,20 +765,32 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
}
}
- private reRenderFooter() {
+ private async reRenderFooter() {
if (!this.dialog) {
return;
}
- this.updateDialog();
+ if (this.footerReRenderPromise) {
+ return this.footerReRenderPromise;
+ }
+
+ let resolvePromise: (value: void) => void;
+
+ const promise = new Promise<void>(resolve => resolvePromise = resolve as any);
+
+ this.footerReRenderPromise = promise;
- const $footer = this.dialog.getFooter();
+ queueMicrotask(() => {
+ this.updateDialog();
+ this.dialog.reRenderFooter();
+ //this.dialog.initButtonEvents();
- $(this.containerElement).find('footer.modal-footer')
- .empty()
- .append($footer as JQuery);
+ this.footerReRenderPromise = null;
- this.dialog.initButtonEvents();
+ resolvePromise();
+ });
+
+ return promise;
}
/**
@@ -835,7 +836,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
*
* @todo Remove in 11.0.
*/
- protected showButton(name: string) {
+ protected async showButton(name: string) {
for (const item of this.buttonList) {
if (item.name === name) {
item.hidden = false;
@@ -848,11 +849,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
return;
}
- if (!this.containerElement) {
- return;
- }
-
- $(this.containerElement).find(`footer button[data-name="${name}"]`).removeClass('hidden');
+ await this.reRenderFooter();
this.adjustButtons();
}
@@ -862,7 +859,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
*
* @todo Remove in 11.0.
*/
- protected hideButton(name: string) {
+ protected async hideButton(name: string) {
for (const item of this.buttonList) {
if (item.name === name) {
item.hidden = true;
@@ -875,11 +872,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
return;
}
- if (!this.containerElement) {
- return;
- }
-
- $(this.containerElement).find(`footer button[data-name="${name}"]`).addClass('hidden');
+ await this.reRenderFooter();
this.adjustButtons();
}
@@ -889,7 +882,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
*
* @param name A name.
*/
- showActionItem(name: string) {
+ async showActionItem(name: string) {
for (const item of this.buttonList) {
if (item.name === name) {
item.hidden = false;
@@ -910,23 +903,32 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
return;
}
- if (!this.containerElement) {
- return;
- }
+ await this.reRenderFooter();
+
+ this.adjustButtons();
+ }
- const $el = $(this.containerElement);
+ /**
+ * Update action item.
+ *
+ * @param name A name.
+ * @param item Values to update. *
+ * @since 10.0.0
+ */
+ async updateActionItem(name: string, item: Partial<ActionItem>) {
+ const found = [...this.buttonList, ...this.dropdownItemList].find(it => it && it.name === name);
- $el.find(`footer button[data-name="${name}"]`).removeClass('hidden');
- $el.find(`footer li > a[data-name="${name}"]`).parent().removeClass('hidden');
+ if (!found) {
+ return;
+ }
- if (!this.isDropdownItemListEmpty()) {
- const $dropdownGroup = $el.find('footer .main-btn-group > .btn-group');
+ Object.assign(found, item);
- $dropdownGroup.removeClass('hidden');
- $dropdownGroup.find('> button').removeClass('hidden');
+ if (!this.isRendered()) {
+ return;
}
- this.adjustButtons();
+ await this.reRenderFooter();
}
/**
@@ -934,7 +936,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
*
* @param name A name.
*/
- hideActionItem(name: string) {
+ async hideActionItem(name: string) {
for (const item of this.buttonList) {
if (item.name === name) {
item.hidden = true;
@@ -955,17 +957,7 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
return;
}
- const $el = $(this.containerElement);
-
- $el.find(`footer button[data-name="${name}"]`).addClass('hidden');
- $el.find(`footer li > a[data-name="${name}"]`).parent().addClass('hidden');
-
- if (this.isDropdownItemListEmpty()) {
- const $dropdownGroup = $el.find('footer .main-btn-group > .btn-group');
-
- $dropdownGroup.addClass('hidden');
- $dropdownGroup.find('> button').addClass('hidden');
- }
+ await this.reRenderFooter();
this.adjustButtons();
}
@@ -1005,22 +997,6 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
.findIndex(item => item && item.name === name && !item.disabled && !item.hidden) !== -1;
}
- private isDropdownItemListEmpty(): boolean {
- if (this.dropdownItemList.length === 0) {
- return true;
- }
-
- let isEmpty = true;
-
- this.dropdownItemList.forEach((item) => {
- if (item && !item.hidden) {
- isEmpty = false;
- }
- });
-
- return isEmpty;
- }
-
private adjustHeaderFontSize(step: number = 0) {
step = step || 0;
@@ -1139,6 +1115,10 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
}
private adjustLeftButtons() {
+ if (!this.containerElement) {
+ return;
+ }
+
const $buttons = $(this.containerElement)
.find('footer.modal-footer > .main-btn-group button.btn');
@@ -1153,6 +1133,10 @@ class ModalView<S extends ViewSchema = ViewSchema> extends View<S> {
}
private adjustRightButtons() {
+ if (!this.containerElement) {
+ return;
+ }
+
const $buttons = $(this.containerElement)
.find('footer.modal-footer > .additional-btn-group button.btn:not(.btn-text)');
diff --git a/client/src/views/record/detail/buttons.ts b/client/src/views/record/detail/buttons.ts
index ed33176eec..e2ee76a273 100644
--- a/client/src/views/record/detail/buttons.ts
+++ b/client/src/views/record/detail/buttons.ts
@@ -54,6 +54,7 @@ export default class DetailRecordButtonsView extends View<{
buttons.push(
new ButtonComponent({
name: it.name,
+ action: it.name,
scope: this.options.entityType,
label: it.label,
labelTranslation: it.labelTranslation,
@@ -88,12 +89,8 @@ export default class DetailRecordButtonsView extends View<{
const dropdownItems: VNode[] = [];
- data.dropdownItemList.forEach((it, i) => {
+ data.dropdownItemList.forEach(it => {
if (it === false) {
- if (i === 0 || i === data.dropdownItemList.length - 1) {
- return;
- }
-
dropdownItems.push(
h('li', {class: {'divider': true}})
);
@@ -104,6 +101,7 @@ export default class DetailRecordButtonsView extends View<{
dropdownItems.push(
new DropdownItemComponent({
name: it.name,
+ action: it.name,
scope: this.options.entityType,
label: it.label,
labelTranslation: it.labelTranslation,
@@ -126,63 +124,6 @@ export default class DetailRecordButtonsView extends View<{
return fragment(elements);
}
- /*
- // language=Handlebars
- templateContent_ = `
- {{#each buttonList}}
- {{#unless hidden}}
- {{button name
- scope=../entityType
- label=label
- labelTranslation=labelTranslation
- style=style
- hidden=hidden
- html=html
- title=title
- text=text
- className=../buttonClassName
- disabled=disabled
- }}
- {{/unless}}
- {{/each}}
-
- {{#if dropdownItemList}}
- <button
- type="button"
- class="btn btn-default dropdown-toggle dropdown-item-list-button {{#if dropdownEmpty}} hidden {{/if}}"
- data-toggle="dropdown"
- ><span class="fas fa-ellipsis-h"></span></button>
- <ul class="dropdown-menu pull-left">
- {{#each dropdownItemList}}
- {{#if this}}
- {{#unless hidden}}
- {{dropdownItem
- name
- scope=../entityType
- label=label
- labelTranslation=labelTranslation
- html=html
- title=title
- text=text
- hidden=hidden
- disabled=disabled
- data=data
- className=../actionClassName
- }}
- {{/unless}}
- {{else}}
- {{#unless @first}}
- {{#unless @last}}
- <li class="divider"></li>
- {{/unless}}
- {{/unless}}
- {{/if}}
- {{/each}}
- </ul>
- {{/if}}
- `
- */
-
protected data() {
const data = this.options.dataProvider();
@@ -191,8 +132,8 @@ export default class DetailRecordButtonsView extends View<{
const dropdownItemList = data.dropdownItemList
.filter(it => it === false || !it.hidden)
.filter((it, i, list) => {
- if (i === 0) {
- return true;
+ if (it === false && (i === 0 || i === list.length - 1)) {
+ return false;
}
if (it === false && list[i - 1] === false) {