closable error usage
This commit is contained in:
@@ -26,11 +26,16 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/admin/authentication/fields/test-connection', 'views/fields/base', function (Dep) {
|
||||
define('views/admin/authentication/fields/test-connection', 'views/fields/base', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
_template: '<button class="btn btn-default" data-action="testConnection">{{translate \'Test Connection\' scope=\'Settings\'}}</button>',
|
||||
_template: `
|
||||
<button
|
||||
class="btn btn-default"
|
||||
data-action="testConnection"
|
||||
>{{translate \'Test Connection\' scope=\'Settings\'}}</button>
|
||||
`,
|
||||
|
||||
events: {
|
||||
'click [data-action="testConnection"]': function () {
|
||||
@@ -55,6 +60,7 @@ Espo.define('views/admin/authentication/fields/test-connection', 'views/fields/b
|
||||
'accountDomainNameShort': this.model.get('ldapAccountDomainNameShort'),
|
||||
'accountCanonicalForm': this.model.get('ldapAccountCanonicalForm')
|
||||
};
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -69,29 +75,33 @@ Espo.define('views/admin/authentication/fields/test-connection', 'views/fields/b
|
||||
url: 'Settings/action/testLdapConnection',
|
||||
type: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
error: function (xhr, status) {
|
||||
error: (xhr, status) => {
|
||||
var statusReason = xhr.getResponseHeader('X-Status-Reason') || '';
|
||||
|
||||
statusReason = statusReason.replace(/ $/, '');
|
||||
statusReason = statusReason.replace(/,$/, '');
|
||||
|
||||
var msg = this.translate('Error') + ' ' + xhr.status;
|
||||
|
||||
if (statusReason) {
|
||||
msg += ': ' + statusReason;
|
||||
}
|
||||
Espo.Ui.error(msg);
|
||||
|
||||
Espo.Ui.error(msg, true);
|
||||
|
||||
console.error(msg);
|
||||
|
||||
xhr.errorIsHandled = true;
|
||||
|
||||
this.$el.find('button').prop('disabled', false);
|
||||
}.bind(this)
|
||||
}).done(function () {
|
||||
}
|
||||
}).then(() => {
|
||||
this.$el.find('button').prop('disabled', false);
|
||||
|
||||
Espo.Ui.success(this.translate('ldapTestConnection', 'messages', 'Settings'));
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -60,9 +60,10 @@ define('views/email-account/fields/test-connection', 'views/fields/base', functi
|
||||
this.checkAvailability();
|
||||
|
||||
this.stopListening(this.model, 'change:host');
|
||||
this.listenTo(this.model, 'change:host', function () {
|
||||
|
||||
this.listenTo(this.model, 'change:host', () => {
|
||||
this.checkAvailability();
|
||||
}, this);
|
||||
});
|
||||
},
|
||||
|
||||
getData: function () {
|
||||
@@ -76,10 +77,10 @@ define('views/email-account/fields/test-connection', 'views/fields/base', functi
|
||||
emailAddress: this.model.get('emailAddress'),
|
||||
userId: this.model.get('assignedUserId'),
|
||||
};
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
|
||||
test: function () {
|
||||
var data = this.getData();
|
||||
|
||||
@@ -93,31 +94,35 @@ define('views/email-account/fields/test-connection', 'views/fields/base', functi
|
||||
url: this.url,
|
||||
type: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
error: function (xhr, status) {
|
||||
error: (xhr, status) => {
|
||||
var statusReason = xhr.getResponseHeader('X-Status-Reason') || '';
|
||||
statusReason = statusReason.replace(/ $/, '');
|
||||
statusReason = statusReason.replace(/,$/, '');
|
||||
|
||||
var msg = this.translate('Error');
|
||||
|
||||
if (xhr.status != 200) {
|
||||
msg += ' ' + xhr.status;
|
||||
}
|
||||
|
||||
if (statusReason) {
|
||||
msg += ': ' + statusReason;
|
||||
}
|
||||
Espo.Ui.error(msg);
|
||||
console.error(msg);
|
||||
xhr.errorIsHandled = true;
|
||||
$btn.removeClass('disabled');
|
||||
}.bind(this)
|
||||
}).done(function () {
|
||||
$btn.removeClass('disabled');
|
||||
Espo.Ui.success(this.translate('connectionIsOk', 'messages', 'EmailAccount'));
|
||||
}.bind(this));
|
||||
|
||||
Espo.Ui.error(msg, true);
|
||||
|
||||
console.error(msg);
|
||||
|
||||
xhr.errorIsHandled = true;
|
||||
|
||||
$btn.removeClass('disabled');
|
||||
}
|
||||
}).then(() => {
|
||||
$btn.removeClass('disabled');
|
||||
|
||||
Espo.Ui.success(this.translate('connectionIsOk', 'messages', 'EmailAccount'));
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ define('views/outbound-email/fields/test-send', 'views/fields/base', function (D
|
||||
|
||||
this.stopListening(this.model, 'change:smtpServer');
|
||||
|
||||
this.listenTo(this.model, 'change:smtpServer', function () {
|
||||
this.listenTo(this.model, 'change:smtpServer', () => {
|
||||
this.checkAvailability();
|
||||
}, this);
|
||||
});
|
||||
},
|
||||
|
||||
getSmtpData: function () {
|
||||
@@ -74,6 +74,7 @@ define('views/outbound-email/fields/test-send', 'views/fields/base', function (D
|
||||
'fromAddress': this.model.get('outboundEmailFromAddress'),
|
||||
'type': 'outboundEmail',
|
||||
};
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -83,10 +84,10 @@ define('views/outbound-email/fields/test-send', 'views/fields/base', function (D
|
||||
|
||||
this.createView('popup', 'views/outbound-email/modals/test-send', {
|
||||
emailAddress: this.getUser().get('emailAddress')
|
||||
}, function (view) {
|
||||
}, (view) => {
|
||||
view.render();
|
||||
|
||||
this.listenToOnce(view, 'send', function (emailAddress) {
|
||||
this.listenToOnce(view, 'send', (emailAddress) => {
|
||||
this.$el.find('button').addClass('disabled');
|
||||
data.emailAddress = emailAddress;
|
||||
|
||||
@@ -95,59 +96,53 @@ define('views/outbound-email/fields/test-send', 'views/fields/base', function (D
|
||||
view.close();
|
||||
|
||||
Espo.Ajax.postRequest('Email/action/sendTestEmail', data)
|
||||
.then(
|
||||
function () {
|
||||
this.$el.find('button').removeClass('disabled');
|
||||
.then(() => {
|
||||
this.$el.find('button').removeClass('disabled');
|
||||
|
||||
Espo.Ui.success(this.translate('testEmailSent', 'messages', 'Email'));
|
||||
Espo.Ui.success(this.translate('testEmailSent', 'messages', 'Email'));
|
||||
})
|
||||
.catch((xhr) => {
|
||||
var reason = xhr.getResponseHeader('X-Status-Reason') || '';
|
||||
|
||||
reason = reason
|
||||
.replace(/ $/, '')
|
||||
.replace(/,$/, '');
|
||||
|
||||
var msg = this.translate('Error');
|
||||
|
||||
if (xhr.status !== 200) {
|
||||
msg += ' ' + xhr.status;
|
||||
}
|
||||
.bind(this)
|
||||
)
|
||||
.fail(
|
||||
function (xhr) {
|
||||
var reason = xhr.getResponseHeader('X-Status-Reason') || '';
|
||||
|
||||
reason = reason
|
||||
.replace(/ $/, '')
|
||||
.replace(/,$/, '');
|
||||
if (xhr.responseText) {
|
||||
try {
|
||||
var data = JSON.parse(xhr.responseText);
|
||||
|
||||
var msg = this.translate('Error');
|
||||
|
||||
if (xhr.status !== 200) {
|
||||
msg += ' ' + xhr.status;
|
||||
reason = data.message || reason;
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Could not parse error response body.');
|
||||
|
||||
if (xhr.responseText) {
|
||||
try {
|
||||
var data = JSON.parse(xhr.responseText);
|
||||
|
||||
reason = data.message || reason;
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Could not parse error response body.');
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (reason) {
|
||||
msg += ': ' + reason;
|
||||
}
|
||||
|
||||
Espo.Ui.error(msg);
|
||||
|
||||
console.error(msg);
|
||||
|
||||
xhr.errorIsHandled = true;
|
||||
|
||||
this.$el.find('button').removeClass('disabled');
|
||||
}
|
||||
.bind(this)
|
||||
);
|
||||
|
||||
}, this);
|
||||
}.bind(this));
|
||||
if (reason) {
|
||||
msg += ': ' + reason;
|
||||
}
|
||||
|
||||
Espo.Ui.error(msg, true);
|
||||
|
||||
console.error(msg);
|
||||
|
||||
xhr.errorIsHandled = true;
|
||||
|
||||
this.$el.find('button').removeClass('disabled');
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user