Skip to content

EspoCRM – Open Source CRM Application

modal shourtcut fix

Yuri Kuznetsov19c998d34367
diff --git a/client/src/views/modals/compose-email.js b/client/src/views/modals/compose-email.js
index ed8e88e67f..cd740fc195 100644
--- a/client/src/views/modals/compose-email.js
+++ b/client/src/views/modals/compose-email.js
@@ -42,7 +42,7 @@ class ComposeEmailModalView extends EditModalView {
shortcutKeys = {
/** @this ComposeEmailModalView */
'Control+Enter': function (e) {
- if (this.buttonList.findIndex(item => item.name === 'send' && !item.hidden) === -1) {
+ if (this.buttonList.findIndex(item => item.name === 'send' && !item.hidden && !item.disabled) === -1) {
return;
}
@@ -53,7 +53,7 @@ class ComposeEmailModalView extends EditModalView {
},
/** @this ComposeEmailModalView */
'Control+KeyS': function (e) {
- if (this.buttonList.findIndex(item => item.name === 'saveDraft' && !item.hidden) === -1) {
+ if (this.buttonList.findIndex(item => item.name === 'saveDraft' && !item.hidden && !item.disabled) === -1) {
return;
}
diff --git a/client/src/views/modals/edit.js b/client/src/views/modals/edit.js
index 5254caecbe..7257e6f649 100644
--- a/client/src/views/modals/edit.js
+++ b/client/src/views/modals/edit.js
@@ -74,7 +74,7 @@ class EditModalView extends ModalView {
return;
}
- if (this.buttonList.findIndex(item => item.name === 'save' && !item.hidden) === -1) {
+ if (this.buttonList.findIndex(item => item.name === 'save' && !item.hidden && !item.disabled) === -1) {
return;
}
@@ -94,7 +94,7 @@ class EditModalView extends ModalView {
return;
}
- if (this.buttonList.findIndex(item => item.name === 'save' && !item.hidden) === -1) {
+ if (this.buttonList.findIndex(item => item.name === 'save' && !item.hidden && !item.disabled) === -1) {
return;
}
@@ -385,50 +385,59 @@ class EditModalView extends ModalView {
* @protected
* @param {{bypassClose?: boolean}} [data]
*/
- actionSave(data = {}) {
+ async actionSave(data = {}) {
const editView = this.getRecordView();
const model = editView.model;
- const $buttons = this.dialog.$el.find('.modal-footer button');
+ const disabledButtons = [];
- $buttons.addClass('disabled').attr('disabled', 'disabled');
+ this.buttonList.forEach(it => {
+ if (!it.name || it.disabled) {
+ return;
+ }
- editView
- .save()
- .then(() => {
- const wasNew = !this.id;
+ this.disableButton(it.name);
- if (wasNew) {
- this.id = model.id;
- }
+ disabledButtons.push(it.name);
+ });
- this.trigger('after:save', model, {bypassClose: data.bypassClose});
+ try {
+ await editView.save();
+ } catch (e) {
+ disabledButtons.forEach(it => this.enableButton(it));
- if (!data.bypassClose) {
- this.dialog.close();
+ return;
+ }
- if (wasNew) {
- const url = `#${this.scope}/view/${model.id}`;
- const name = model.attributes[this.nameAttribute] || this.model.id;
+ const wasNew = !this.id;
- const msg = this.translate('Created') + '\n' +
- `[${name}](${url})`;
+ if (wasNew) {
+ this.id = model.id;
+ }
- Espo.Ui.notify(msg, 'success', 4000, {suppress: true});
- }
+ this.trigger('after:save', model, {bypassClose: data.bypassClose});
- return;
- }
+ if (!data.bypassClose) {
+ this.dialog.close();
+
+ if (wasNew) {
+ const url = `#${this.scope}/view/${model.id}`;
+ const name = model.attributes[this.nameAttribute] || this.model.id;
+
+ const msg = this.translate('Created') + '\n' +
+ `[${name}](${url})`;
+
+ Espo.Ui.notify(msg, 'success', 4000, {suppress: true});
+ }
+
+ return;
+ }
- $(this.containerElement).find('.modal-header .modal-title-text')
- .html(this.composeHeaderHtml());
+ $(this.containerElement).find('.modal-header .modal-title-text')
+ .html(this.composeHeaderHtml());
- $buttons.removeClass('disabled').removeAttr('disabled');
- })
- .catch(() => {
- $buttons.removeClass('disabled').removeAttr('disabled');
- })
+ disabledButtons.forEach(it => this.enableButton(it));
}
actionSaveAndContinueEditing() {
diff --git a/client/src/views/modals/related-list.js b/client/src/views/modals/related-list.js
index 1f6e8e891f..60aaa82d30 100644
--- a/client/src/views/modals/related-list.js
+++ b/client/src/views/modals/related-list.js
@@ -671,7 +671,7 @@ class RelatedListModalView extends ModalView {
return;
}
- if (this.buttonList.findIndex(item => item.name === 'createRelated' && !item.hidden) === -1) {
+ if (this.buttonList.findIndex(item => item.name === 'createRelated' && !item.hidden && !item.disabled) === -1) {
return;
}
diff --git a/client/src/views/record/edit.js b/client/src/views/record/edit.js
index 69b7de1989..6a69fcb1ad 100644
--- a/client/src/views/record/edit.js
+++ b/client/src/views/record/edit.js
@@ -241,7 +241,7 @@ class EditRecordView extends DetailRecordView {
return;
}
- if (this.buttonList.findIndex(item => item.name === 'cancel' && !item.hidden) === -1) {
+ if (this.buttonList.findIndex(item => item.name === 'cancel' && !item.hidden && !item.disabled) === -1) {
return;
}