Skip to content

EspoCRM – Open Source CRM Application

sendbox ui impr

Yuri Kuznetsov19a09cc6d1e8
diff --git a/client/src/views/admin/formula-sandbox/index.js b/client/src/views/admin/formula-sandbox/index.js
index d1c5a5ccfd..54eaada510 100644
--- a/client/src/views/admin/formula-sandbox/index.js
+++ b/client/src/views/admin/formula-sandbox/index.js
@@ -36,7 +36,6 @@ export default class extends View {
targetEntityType = null
storageKey = 'formulaSandbox'
-
setup() {
const entityTypeList = [''].concat(
this.getMetadata()
@@ -132,7 +131,7 @@ export default class extends View {
return;
}
- let dataToStore = {
+ const dataToStore = {
script: this.model.get('script'),
targetType: this.model.get('targetType'),
targetId: this.model.get('targetId'),
@@ -143,6 +142,13 @@ export default class extends View {
});
}
+ /**
+ * @return {import('views/record/detail').default}
+ */
+ getRecordView() {
+ return this.getView('record');
+ }
+
createRecordView() {
return this.createView('record', 'views/admin/formula-sandbox/record/edit', {
selector: '.record',
@@ -157,7 +163,7 @@ export default class extends View {
this.setPageTitle(this.getLanguage().translate('Formula Sandbox', 'labels', 'Admin'));
}
- run() {
+ async run() {
const script = this.model.get('script');
this.model.set({
@@ -175,50 +181,62 @@ export default class extends View {
return;
}
- Espo.Ajax
- .postRequest('Formula/action/run', {
+ this.getRecordView().disableActionItems();
+ Espo.Ui.notifyWait();
+
+ /** @var {Record} */
+ let response;
+
+ try {
+ response = await Espo.Ajax.postRequest('Formula/action/run', {
expression: script,
targetId: this.model.get('targetId'),
targetType: this.model.get('targetType'),
- })
- .then(response => {
- this.model.set('output', response.output || null);
+ });
+ } catch (e) {
+ this.getRecordView().enableActionItems();
+
+ return;
+ }
+
+ this.getRecordView().enableActionItems();
- let errorMessage = null;
+ this.model.set('output', response.output || null);
- if (!response.isSuccess) {
- errorMessage = response.message || null;
- }
+ let errorMessage = null;
- this.model.set('errorMessage', errorMessage);
+ if (!response.isSuccess) {
+ errorMessage = response.message || null;
+ }
+
+ this.model.set('errorMessage', errorMessage);
- if (response.isSuccess) {
- Espo.Ui.success(
- this.translate('runSuccess', 'messages', 'Formula')
- );
+ if (response.isSuccess) {
+ Espo.Ui.success(
+ this.translate('runSuccess', 'messages', 'Formula')
+ );
- return;
- }
+ return;
+ }
- if (response.isSyntaxError) {
- let msg = this.translate('checkSyntaxError', 'messages', 'Formula');
+ if (response.isSyntaxError) {
+ let msg = this.translate('checkSyntaxError', 'messages', 'Formula');
- if (response.message) {
- msg += ' ' + response.message;
- }
+ if (response.message) {
+ msg += ' ' + response.message;
+ }
- Espo.Ui.error(msg);
+ Espo.Ui.error(msg);
- return;
- }
+ return;
+ }
- let msg = this.translate('runError', 'messages', 'Formula');
+ let msg = this.translate('runError', 'messages', 'Formula');
- if (response.message) {
- msg += ' ' + response.message;
- }
+ if (response.message) {
+ msg += ' ' + response.message;
+ }
- Espo.Ui.error(msg);
- });
+ Espo.Ui.error(msg);
}
}