email template for reply
This commit is contained in:
@@ -172,9 +172,7 @@ Espo.define('crm:views/record/panels/history', 'crm:views/record/panels/activiti
|
||||
this.createView('quickCreate', viewName, {
|
||||
attributes: attributes,
|
||||
}, function (view) {
|
||||
view.render(function () {
|
||||
view.getView('edit').hideField('selectTemplate');
|
||||
});
|
||||
view.render();
|
||||
|
||||
this.listenToOnce(view, 'after:save', function () {
|
||||
this.collection.fetch();
|
||||
|
||||
@@ -303,9 +303,7 @@ Espo.define('views/email/detail', ['views/detail', 'email-helper'], function (De
|
||||
this.createView('quickCreate', viewName, {
|
||||
attributes: attributes,
|
||||
}, function (view) {
|
||||
view.render(function () {
|
||||
view.getView('edit').hideField('selectTemplate');
|
||||
});
|
||||
view.render();
|
||||
|
||||
view.notify(false);
|
||||
|
||||
@@ -340,9 +338,7 @@ Espo.define('views/email/detail', ['views/detail', 'email-helper'], function (De
|
||||
this.createView('quickCreate', viewName, {
|
||||
attributes: attributes,
|
||||
}, function (view) {
|
||||
view.render(function () {
|
||||
view.getView('edit').hideField('selectTemplate');
|
||||
});
|
||||
view.render();
|
||||
|
||||
view.notify(false);
|
||||
});
|
||||
|
||||
@@ -37,17 +37,31 @@ Espo.define('views/email/record/compose', ['views/record/edit', 'views/email/rec
|
||||
setup: function () {
|
||||
Dep.prototype.setup.call(this);
|
||||
|
||||
this.initialBody = null;
|
||||
this.initialIsHtml = null;
|
||||
|
||||
if (!this.model.get('isHtml') && this.getPreferences().get('emailReplyForceHtml')) {
|
||||
var body = (this.model.get('body') || '').replace(/\n/g, '<br>');
|
||||
this.model.set('body', body);
|
||||
this.model.set('isHtml', true);
|
||||
}
|
||||
|
||||
if (this.model.get('body')) {
|
||||
this.initialBody = this.model.get('body');
|
||||
this.initialIsHtml = this.model.get('isHtml');
|
||||
}
|
||||
|
||||
if (!this.options.signatureDisabled && this.hasSignature()) {
|
||||
var body = this.prependSignature(this.model.get('body') || '', this.model.get('isHtml'));
|
||||
this.model.set('body', body);
|
||||
}
|
||||
|
||||
this.isBodyChanged = false;
|
||||
|
||||
this.listenTo(this.model, 'change:body', function () {
|
||||
this.isBodyChanged = true;
|
||||
}, this);
|
||||
|
||||
if (this.options.keepAttachmentsOnSelectTemplate) {
|
||||
this.initialAttachmentsIds = this.model.get('attachmentsIds') || [];
|
||||
this.initialAttachmentsNames = this.model.get('attachmentsNames') || {};
|
||||
@@ -64,7 +78,10 @@ Espo.define('views/email/record/compose', ['views/record/edit', 'views/email/rec
|
||||
var $div = $('<div>').html(bodyPlain);
|
||||
bodyPlain = $div.text();
|
||||
|
||||
if (bodyPlain !== '' && this.model.get('body') !== this.attributes.body) {
|
||||
if (
|
||||
bodyPlain !== '' &&
|
||||
this.isBodyChanged
|
||||
) {
|
||||
this.confirm({
|
||||
message: this.translate('confirmInsertTemplate', 'messages', 'Email'),
|
||||
confirmText: this.translate('Yes')
|
||||
@@ -87,6 +104,20 @@ Espo.define('views/email/record/compose', ['views/record/edit', 'views/email/rec
|
||||
if (this.hasSignature()) {
|
||||
body = this.appendSignature(body || '', data.isHtml);
|
||||
}
|
||||
|
||||
if (this.initialBody) {
|
||||
var initialBody = this.initialBody;
|
||||
if (data.isHtml !== this.initialIsHtml) {
|
||||
if (data.isHtml) {
|
||||
initialBody = this.plainToHtml(initialBody);
|
||||
} else {
|
||||
initialBody = this.htmlToPlain(initialBody);
|
||||
}
|
||||
}
|
||||
|
||||
body += initialBody;
|
||||
}
|
||||
|
||||
this.model.set('isHtml', data.isHtml);
|
||||
this.model.set('name', data.subject);
|
||||
this.model.set('body', '');
|
||||
@@ -160,6 +191,27 @@ Espo.define('views/email/record/compose', ['views/record/edit', 'views/email/rec
|
||||
model.set('status', 'Draft');
|
||||
|
||||
this.save();
|
||||
},
|
||||
|
||||
htmlToPlain: function (text) {
|
||||
text = text || '';
|
||||
var value = text.replace(/<br\s*\/?>/mg, '\n');
|
||||
|
||||
value = value.replace(/<\/p\s*\/?>/mg, '\n\n');
|
||||
|
||||
var $div = $('<div>').html(value);
|
||||
$div.find('style').remove();
|
||||
$div.find('link[ref="stylesheet"]').remove();
|
||||
|
||||
value = $div.text();
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
plainToHtml: function (html) {
|
||||
html = html || '';
|
||||
var value = html.replace(/\n/g, '<br>');
|
||||
return value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user