This commit is contained in:
Yuri Kuznetsov
2024-08-09 10:59:57 +03:00
parent e7331efcbe
commit 3c756e6252
10 changed files with 339 additions and 328 deletions
@@ -26,22 +26,21 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/inbound-email/fields/email-address', ['views/fields/email-address'], function (Dep) {
import EmailAddressFieldView from 'views/fields/email-address';
return Dep.extend({
export default class extends EmailAddressFieldView {
setup: function () {
Dep.prototype.setup.call(this);
setup() {
super.setup();
this.on('change', () => {
var emailAddress = this.model.get('emailAddress');
this.on('change', () => {
const emailAddress = this.model.get('emailAddress');
this.model.set('name', emailAddress);
this.model.set('name', emailAddress);
if (this.model.isNew() || !this.model.get('replyToAddress')) {
this.model.set('replyToAddress', emailAddress);
}
});
},
});
});
if (this.model.isNew() || !this.model.get('replyToAddress')) {
this.model.set('replyToAddress', emailAddress);
}
});
}
}
@@ -30,5 +30,6 @@ import FolderView from 'views/email-account/fields/folder';
export default class extends FolderView {
// noinspection JSUnusedGlobalSymbols
getFoldersUrl = 'InboundEmail/action/getFolders'
}
@@ -30,5 +30,6 @@ import FoldersView from 'views/email-account/fields/folders';
export default class extends FoldersView {
// noinspection JSUnusedGlobalSymbols
getFoldersUrl = 'InboundEmail/action/getFolders'
}
@@ -26,57 +26,54 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/inbound-email/fields/target-user-position', ['views/fields/enum'], function (Dep) {
import EnumFieldView from 'views/fields/enum';
return Dep.extend({
export default class extends EnumFieldView {
setup: function () {
Dep.prototype.setup.call(this);
setup() {
super.setup();
this.translatedOptions = {
'': '--' + this.translate('All') + '--'
};
this.translatedOptions = {'': `--${this.translate('All')}--`};
this.params.options = [''];
this.params.options = [''];
if (this.model.get('targetUserPosition') && this.model.get('teamId')) {
this.params.options.push(this.model.get('targetUserPosition'));
}
if (this.model.get('targetUserPosition') && this.model.get('teamId')) {
this.params.options.push(this.model.get('targetUserPosition'));
}
this.loadRoleList(() => {
if (this.mode === 'edit') {
if (this.isRendered()) {
this.render();
}
}
});
this.listenTo(this.model, 'change:teamId', () => {
this.loadRoleList(() => {
this.loadRoleList(() => {
if (this.mode === this.MODE_EDIT) {
if (this.isRendered()) {
this.render();
});
});
},
loadRoleList: function (callback, context) {
var teamId = this.model.get('teamId');
if (!teamId) {
this.params.options = [''];
}
}
});
this.getModelFactory().create('Team', (team) => {
team.id = teamId;
this.listenTo(this.model, 'change:teamId', () => {
this.loadRoleList(() => this.render());
});
}
this.listenToOnce(team, 'sync', () => {
this.params.options = team.get('positionList') || [];
this.params.options.unshift('');
/**
* @private
* @param {function} callback
*/
loadRoleList(callback) {
const teamId = this.model.attributes.teamId;
callback.call(context);
});
if (!teamId) {
this.params.options = [''];
}
team.fetch();
this.getModelFactory().create('Team', /** import('model').default */team => {
team.id = teamId;
team.fetch().then(() => {
this.params.options = team.get('positionList') || [];
this.params.options.unshift('');
callback.call(this);
});
},
});
});
});
}
}
@@ -26,10 +26,10 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/inbound-email/fields/test-connection', ['views/email-account/fields/test-connection'], function (Dep) {
import TestConnectionView from 'views/email-account/fields/test-connection';
return Dep.extend({
export default class extends TestConnectionView {
url = 'InboundEmail/action/testConnection'
}
url: 'InboundEmail/action/testConnection',
});
});
@@ -26,24 +26,23 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/inbound-email/fields/test-send', ['views/email-account/fields/test-send'], function (Dep) {
import TestSendView from 'views/email-account/fields/test-send';
return Dep.extend({
export default class extends TestSendView {
getSmtpData: function () {
return {
'server': this.model.get('smtpHost'),
'port': this.model.get('smtpPort'),
'auth': this.model.get('smtpAuth'),
'security': this.model.get('smtpSecurity'),
'username': this.model.get('smtpUsername'),
'password': this.model.get('smtpPassword') || null,
'authMechanism': this.model.get('smtpAuthMechanism'),
'fromName': this.model.get('fromName'),
'fromAddress': this.model.get('emailAddress'),
'type': 'inboundEmail',
'id': this.model.id,
};
},
});
});
getSmtpData() {
return {
server: this.model.get('smtpHost'),
port: this.model.get('smtpPort'),
auth: this.model.get('smtpAuth'),
security: this.model.get('smtpSecurity'),
username: this.model.get('smtpUsername'),
password: this.model.get('smtpPassword') || null,
authMechanism: this.model.get('smtpAuthMechanism'),
fromName: this.model.get('fromName'),
fromAddress: this.model.get('emailAddress'),
type: 'inboundEmail',
id: this.model.id,
};
}
}
+207 -207
View File
@@ -26,22 +26,23 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/inbound-email/record/detail', ['views/record/detail'], function (Dep) {
import DetailRecordView from 'views/record/detail';
return Dep.extend({
export default class extends DetailRecordView {
setup: function () {
Dep.prototype.setup.call(this);
setup() {
super.setup();
this.setupFieldsBehaviour();
this.initSslFieldListening();
},
this.setupFieldsBehaviour();
this.initSslFieldListening();
}
modifyDetailLayout: function (layout) {
layout.filter(panel => panel.tabLabel === '$label:SMTP').forEach(panel => {
modifyDetailLayout(layout) {
layout.filter(panel => panel.tabLabel === '$label:SMTP')
.forEach(panel => {
panel.rows.forEach(row => {
row.forEach(item => {
let labelText = this.translate(item.name, 'fields', 'InboundEmail');
const labelText = this.translate(item.name, 'fields', 'InboundEmail');
if (labelText && labelText.indexOf('SMTP ') === 0) {
item.labelText = Espo.Utils.upperCaseFirst(labelText.substring(5));
@@ -49,242 +50,241 @@ define('views/inbound-email/record/detail', ['views/record/detail'], function (D
});
})
});
},
}
wasFetched: function () {
if (!this.model.isNew()) {
return !!((this.model.get('fetchData') || {}).lastUID);
}
wasFetched() {
if (!this.model.isNew()) {
return !!((this.model.get('fetchData') || {}).lastUID);
}
return false;
},
return false;
}
initSmtpFieldsControl: function () {
this.controlSmtpFields();
this.controlSentFolderField();
this.listenTo(this.model, 'change:useSmtp', this.controlSmtpFields, this);
this.listenTo(this.model, 'change:smtpAuth', this.controlSmtpFields, this);
this.listenTo(this.model, 'change:storeSentEmails', this.controlSentFolderField, this);
},
initSmtpFieldsControl() {
this.controlSmtpFields();
this.controlSentFolderField();
this.listenTo(this.model, 'change:useSmtp', this.controlSmtpFields, this);
this.listenTo(this.model, 'change:smtpAuth', this.controlSmtpFields, this);
this.listenTo(this.model, 'change:storeSentEmails', this.controlSentFolderField, this);
}
controlSmtpFields: function () {
if (this.model.get('useSmtp')) {
this.showField('smtpHost');
this.showField('smtpPort');
this.showField('smtpAuth');
this.showField('smtpSecurity');
this.showField('smtpTestSend');
this.showField('fromName');
this.showField('smtpIsShared');
this.showField('smtpIsForMassEmail');
this.showField('storeSentEmails');
controlSmtpFields() {
if (this.model.get('useSmtp')) {
this.showField('smtpHost');
this.showField('smtpPort');
this.showField('smtpAuth');
this.showField('smtpSecurity');
this.showField('smtpTestSend');
this.showField('fromName');
this.showField('smtpIsShared');
this.showField('smtpIsForMassEmail');
this.showField('storeSentEmails');
this.setFieldRequired('smtpHost');
this.setFieldRequired('smtpPort');
this.setFieldRequired('smtpHost');
this.setFieldRequired('smtpPort');
this.controlSmtpAuthField();
this.controlSmtpAuthField();
return;
}
return;
}
this.hideField('smtpHost');
this.hideField('smtpPort');
this.hideField('smtpAuth');
this.hideField('smtpUsername');
this.hideField('smtpPassword');
this.hideField('smtpAuthMechanism');
this.hideField('smtpSecurity');
this.hideField('smtpTestSend');
this.hideField('fromName');
this.hideField('smtpIsShared');
this.hideField('smtpIsForMassEmail');
this.hideField('storeSentEmails');
this.hideField('sentFolder');
this.hideField('smtpHost');
this.hideField('smtpPort');
this.hideField('smtpAuth');
this.hideField('smtpUsername');
this.hideField('smtpPassword');
this.hideField('smtpAuthMechanism');
this.hideField('smtpSecurity');
this.hideField('smtpTestSend');
this.hideField('fromName');
this.hideField('smtpIsShared');
this.hideField('smtpIsForMassEmail');
this.hideField('storeSentEmails');
this.hideField('sentFolder');
this.setFieldNotRequired('smtpHost');
this.setFieldNotRequired('smtpPort');
this.setFieldNotRequired('smtpUsername');
},
this.setFieldNotRequired('smtpHost');
this.setFieldNotRequired('smtpPort');
this.setFieldNotRequired('smtpUsername');
}
controlSentFolderField: function () {
if (this.model.get('useSmtp') && this.model.get('storeSentEmails')) {
this.showField('sentFolder');
this.setFieldRequired('sentFolder');
controlSentFolderField() {
if (this.model.get('useSmtp') && this.model.get('storeSentEmails')) {
this.showField('sentFolder');
this.setFieldRequired('sentFolder');
return;
}
return;
}
this.hideField('sentFolder');
this.setFieldNotRequired('sentFolder');
},
this.hideField('sentFolder');
this.setFieldNotRequired('sentFolder');
}
controlSmtpAuthField: function () {
if (this.model.get('smtpAuth')) {
this.showField('smtpUsername');
this.showField('smtpPassword');
this.showField('smtpAuthMechanism');
this.setFieldRequired('smtpUsername');
controlSmtpAuthField() {
if (this.model.get('smtpAuth')) {
this.showField('smtpUsername');
this.showField('smtpPassword');
this.showField('smtpAuthMechanism');
this.setFieldRequired('smtpUsername');
return;
}
return;
}
this.hideField('smtpUsername');
this.hideField('smtpPassword');
this.hideField('smtpAuthMechanism');
this.setFieldNotRequired('smtpUsername');
},
this.hideField('smtpUsername');
this.hideField('smtpPassword');
this.hideField('smtpAuthMechanism');
this.setFieldNotRequired('smtpUsername');
}
controlStatusField: function () {
let list = ['username', 'port', 'host', 'monitoredFolders'];
if (this.model.get('status') === 'Active' && this.model.get('useImap')) {
list.forEach(item => {
this.setFieldRequired(item);
});
return;
}
controlStatusField() {
const list = ['username', 'port', 'host', 'monitoredFolders'];
if (this.model.get('status') === 'Active' && this.model.get('useImap')) {
list.forEach(item => {
this.setFieldNotRequired(item);
});
},
setupFieldsBehaviour: function () {
this.controlStatusField();
this.listenTo(this.model, 'change:status', (model, value, o) => {
if (o.ui) {
this.controlStatusField();
}
this.setFieldRequired(item);
});
this.listenTo(this.model, 'change:useImap', (model, value, o) => {
if (o.ui) {
this.controlStatusField();
}
});
return;
}
if (this.wasFetched()) {
this.setFieldReadOnly('fetchSince');
list.forEach(item => {
this.setFieldNotRequired(item);
});
}
setupFieldsBehaviour() {
this.controlStatusField();
this.listenTo(this.model, 'change:status', (model, value, o) => {
if (o.ui) {
this.controlStatusField();
}
});
this.listenTo(this.model, 'change:useImap', (model, value, o) => {
if (o.ui) {
this.controlStatusField();
}
});
if (this.wasFetched()) {
this.setFieldReadOnly('fetchSince');
} else {
this.setFieldNotReadOnly('fetchSince');
}
this.initSmtpFieldsControl();
const handleRequirement = (model) => {
if (model.get('createCase')) {
this.showField('caseDistribution');
} else {
this.setFieldNotReadOnly('fetchSince');
this.hideField('caseDistribution');
}
this.initSmtpFieldsControl();
if (
model.get('createCase') &&
['Round-Robin', 'Least-Busy'].indexOf(model.get('caseDistribution')) !== -1
) {
this.setFieldRequired('team');
this.showField('targetUserPosition');
} else {
this.setFieldNotRequired('team');
this.hideField('targetUserPosition');
}
let handleRequirement = (model) => {
if (model.get('createCase')) {
this.showField('caseDistribution');
} else {
this.hideField('caseDistribution');
}
if (model.get('createCase') && 'Direct-Assignment' === model.get('caseDistribution')) {
this.setFieldRequired('assignToUser');
this.showField('assignToUser');
} else {
this.setFieldNotRequired('assignToUser');
this.hideField('assignToUser');
}
if (
model.get('createCase') &&
['Round-Robin', 'Least-Busy'].indexOf(model.get('caseDistribution')) !== -1
) {
this.setFieldRequired('team');
this.showField('targetUserPosition');
} else {
this.setFieldNotRequired('team');
this.hideField('targetUserPosition');
}
if (model.get('createCase') && model.get('createCase') !== '') {
this.showField('team');
} else {
this.hideField('team');
}
};
if (model.get('createCase') && 'Direct-Assignment' === model.get('caseDistribution')) {
this.setFieldRequired('assignToUser');
this.showField('assignToUser');
} else {
this.setFieldNotRequired('assignToUser');
this.hideField('assignToUser');
}
this.listenTo(this.model, 'change:createCase', (model, value, o) => {
handleRequirement(model);
if (model.get('createCase') && model.get('createCase') !== '') {
this.showField('team');
} else {
this.hideField('team');
}
};
if (!o.ui) {
return;
}
this.listenTo(this.model, 'change:createCase', (model, value, o) => {
handleRequirement(model);
if (!model.get('createCase')) {
this.model.set({
caseDistribution: '',
teamId: null,
teamName: null,
assignToUserId: null,
assignToUserName: null,
targetUserPosition: '',
});
}
});
handleRequirement(this.model);
this.listenTo(this.model, 'change:caseDistribution', (model, value, o) => {
handleRequirement(model);
if (!o.ui) {
return;
}
setTimeout(() => {
if (!this.model.get('caseDistribution')) {
this.model.set({
assignToUserId: null,
assignToUserName: null,
targetUserPosition: ''
});
if (!o.ui) {
return;
}
if (!model.get('createCase')) {
if (this.model.get('caseDistribution') === 'Direct-Assignment') {
this.model.set({
caseDistribution: '',
teamId: null,
teamName: null,
assignToUserId: null,
assignToUserName: null,
targetUserPosition: '',
});
}
});
handleRequirement(this.model);
this.model.set({
assignToUserId: null,
assignToUserName: null,
});
}, 10);
});
}
this.listenTo(this.model, 'change:caseDistribution', (model, value, o) => {
handleRequirement(model);
initSslFieldListening() {
this.listenTo(this.model, 'change:security', (model, value, o) => {
if (!o.ui) {
return;
}
if (!o.ui) {
return;
}
if (value) {
this.model.set('port', 993);
} else {
this.model.set('port', 143);
}
});
setTimeout(() => {
if (!this.model.get('caseDistribution')) {
this.model.set({
assignToUserId: null,
assignToUserName: null,
targetUserPosition: ''
});
this.listenTo(this.model, 'change:smtpSecurity', (model, value, o) => {
if (!o.ui) {
return;
}
return;
}
if (this.model.get('caseDistribution') === 'Direct-Assignment') {
this.model.set({
targetUserPosition: '',
});
}
this.model.set({
assignToUserId: null,
assignToUserName: null,
});
}, 10);
});
},
initSslFieldListening: function () {
this.listenTo(this.model, 'change:security', (model, value, o) => {
if (!o.ui) {
return;
}
if (value) {
this.model.set('port', 993);
} else {
this.model.set('port', 143);
}
});
this.listenTo(this.model, 'change:smtpSecurity', (model, value, o) => {
if (!o.ui) {
return;
}
if (value === 'SSL') {
this.model.set('smtpPort', 465);
} else if (value === 'TLS') {
this.model.set('smtpPort', 587);
} else {
this.model.set('smtpPort', 25);
}
});
},
});
});
if (value === 'SSL') {
this.model.set('smtpPort', 465);
} else if (value === 'TLS') {
this.model.set('smtpPort', 587);
} else {
this.model.set('smtpPort', 25);
}
});
}
}
+33 -34
View File
@@ -26,48 +26,47 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/inbound-email/record/edit', ['views/record/edit', 'views/inbound-email/record/detail'],
function (Dep, Detail) {
import EditRecordView from 'views/record/edit';
import Detail from 'views/inbound-email/record/detail';
return Dep.extend({
export default class extends EditRecordView {
setup: function () {
Dep.prototype.setup.call(this);
setup() {
super.setup();
Detail.prototype.setupFieldsBehaviour.call(this);
Detail.prototype.initSslFieldListening.call(this);
Detail.prototype.setupFieldsBehaviour.call(this);
Detail.prototype.initSslFieldListening.call(this);
if (Detail.prototype.wasFetched.call(this)) {
this.setFieldReadOnly('fetchSince');
}
},
if (Detail.prototype.wasFetched.call(this)) {
this.setFieldReadOnly('fetchSince');
}
}
modifyDetailLayout: function (layout) {
Detail.prototype.modifyDetailLayout.call(this, layout);
},
modifyDetailLayout(layout) {
Detail.prototype.modifyDetailLayout.call(this, layout);
}
controlStatusField: function () {
Detail.prototype.controlStatusField.call(this);
},
controlStatusField() {
Detail.prototype.controlStatusField.call(this);
}
initSmtpFieldsControl: function () {
Detail.prototype.initSmtpFieldsControl.call(this);
},
initSmtpFieldsControl() {
Detail.prototype.initSmtpFieldsControl.call(this);
}
controlSmtpFields: function () {
Detail.prototype.controlSmtpFields.call(this);
},
controlSmtpFields() {
Detail.prototype.controlSmtpFields.call(this);
}
controlSentFolderField: function () {
Detail.prototype.controlSentFolderField.call(this);
},
controlSentFolderField() {
Detail.prototype.controlSentFolderField.call(this);
}
controlSmtpAuthField: function () {
Detail.prototype.controlSmtpAuthField.call(this);
},
controlSmtpAuthField() {
Detail.prototype.controlSmtpAuthField.call(this);
}
wasFetched: function () {
Detail.prototype.wasFetched.call(this);
},
});
});
wasFetched() {
Detail.prototype.wasFetched.call(this);
}
}
@@ -26,13 +26,12 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/inbound-email/record/list', ['views/record/list'], function (Dep) {
import ListRecordView from 'views/record/list';
return Dep.extend({
export default class extends ListRecordView {
quickDetailDisabled: true,
quickEditDisabled: true,
massActionList: ['remove', 'massUpdate'],
checkAllResultDisabled: true,
});
});
quickDetailDisabled = true
quickEditDisabled = true
massActionList = ['remove', 'massUpdate']
checkAllResultDisabled = true
}
@@ -44,6 +44,9 @@ export default class extends BaseFieldView {
return {};
}
/**
* @protected
*/
checkAvailability() {
if (this.model.get('smtpServer')) {
this.$el.find('button').removeClass('hidden');
@@ -62,6 +65,10 @@ export default class extends BaseFieldView {
});
}
/**
* @protected
* @return {Record}
*/
getSmtpData() {
return {
'server': this.model.get('smtpServer'),
@@ -76,14 +83,23 @@ export default class extends BaseFieldView {
};
}
/**
* @protected
*/
enableButton() {
this.$el.find('button').removeClass('disabled').removeAttr('disabled');
}
/**
* @protected
*/
disabledButton() {
this.$el.find('button').addClass('disabled').attr('disabled', 'disabled');
}
/**
* @private
*/
send() {
const data = this.getSmtpData();