mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 20:49:20 +03:00
Added individual signatures for every identity.
This commit is contained in:
parent
996703311b
commit
1119022916
45 changed files with 1353 additions and 337 deletions
|
|
@ -33,7 +33,6 @@
|
|||
Data = require('Storage/User/Data'),
|
||||
Cache = require('Storage/User/Cache'),
|
||||
Remote = require('Storage/User/Remote'),
|
||||
Local = require('Storage/Client'),
|
||||
|
||||
ComposeAttachmentModel = require('Model/ComposeAttachment'),
|
||||
|
||||
|
|
@ -74,6 +73,7 @@
|
|||
}
|
||||
;
|
||||
|
||||
this.oLastMessage = null;
|
||||
this.oEditor = null;
|
||||
this.aDraftInfo = null;
|
||||
this.sInReplyTo = '';
|
||||
|
|
@ -198,49 +198,19 @@
|
|||
|
||||
this.composeEditorArea = ko.observable(null);
|
||||
|
||||
this.identities = AccountStore.identities;
|
||||
this.identities = IdentityStore.identities;
|
||||
this.identitiesOptions = ko.computed(function () {
|
||||
return _.map(IdentityStore.identities(), function (oItem) {
|
||||
return {
|
||||
'item': oItem,
|
||||
'optValue': oItem.id(),
|
||||
'optText': oItem.formattedName()
|
||||
};
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.currentIdentityID = ko.observable(
|
||||
Local.get(Enums.ClientSideKeyName.ComposeLastIdentityID, ''));
|
||||
|
||||
this.currentIdentity = ko.computed(function () {
|
||||
|
||||
var
|
||||
oItem = null,
|
||||
sID = this.currentIdentityID(),
|
||||
aList = IdentityStore.identities()
|
||||
;
|
||||
|
||||
if (Utils.isArray(aList))
|
||||
{
|
||||
oItem = _.find(aList, function (oItem) {
|
||||
return oItem && sID === oItem.id();
|
||||
});
|
||||
|
||||
if (!oItem)
|
||||
{
|
||||
oItem = _.find(aList, function (oItem) {
|
||||
return oItem && '' === oItem.id();
|
||||
});
|
||||
}
|
||||
|
||||
if (!oItem)
|
||||
{
|
||||
oItem = aList[0] ? aList[0] : null;
|
||||
}
|
||||
}
|
||||
|
||||
return oItem ? oItem : null;
|
||||
|
||||
}, this);
|
||||
this.currentIdentity = ko.observable(
|
||||
this.identities()[0] ? this.identities()[0] : null);
|
||||
|
||||
this.currentIdentity.extend({'toggleSubscribe': [this,
|
||||
function (oIdentity) {
|
||||
|
|
@ -361,7 +331,7 @@
|
|||
|
||||
Remote.sendMessage(
|
||||
this.sendMessageResponse,
|
||||
this.currentIdentityID(),
|
||||
this.currentIdentity() ? this.currentIdentity().id() : '',
|
||||
this.draftFolder(),
|
||||
this.draftUid(),
|
||||
sSentFolder,
|
||||
|
|
@ -371,7 +341,7 @@
|
|||
this.replyTo(),
|
||||
this.subject(),
|
||||
this.oEditor ? this.oEditor.isHtml() : false,
|
||||
this.oEditor ? this.oEditor.getData(true) : '',
|
||||
this.oEditor ? this.oEditor.getData(true, true) : '',
|
||||
this.prepearAttachmentsForSendOrSave(),
|
||||
this.aDraftInfo,
|
||||
this.sInReplyTo,
|
||||
|
|
@ -400,7 +370,7 @@
|
|||
|
||||
Remote.saveMessage(
|
||||
this.saveMessageResponse,
|
||||
this.currentIdentityID(),
|
||||
this.currentIdentity() ? this.currentIdentity().id() : '',
|
||||
this.draftFolder(),
|
||||
this.draftUid(),
|
||||
FolderStore.draftFolder(),
|
||||
|
|
@ -597,7 +567,6 @@
|
|||
ComposePopupView.prototype.findIdentityByMessage = function (sComposeType, oMessage)
|
||||
{
|
||||
var
|
||||
sDefaultIdentityID = Local.get(Enums.ClientSideKeyName.ComposeLastIdentityID, ''),
|
||||
aIdentities = IdentityStore.identities(),
|
||||
oResultIdentity = null,
|
||||
oIdentitiesCache = {},
|
||||
|
|
@ -640,34 +609,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (!oResultIdentity)
|
||||
{
|
||||
oResultIdentity = _.find(aIdentities, function (oItem) {
|
||||
return oItem.id() === sDefaultIdentityID;
|
||||
});
|
||||
}
|
||||
|
||||
if (!oResultIdentity && '' !== sDefaultIdentityID)
|
||||
{
|
||||
oResultIdentity = _.find(aIdentities, function (oItem) {
|
||||
return oItem.id() === '';
|
||||
});
|
||||
}
|
||||
|
||||
if (!oResultIdentity)
|
||||
{
|
||||
oResultIdentity = aIdentities[0] || null;
|
||||
}
|
||||
|
||||
return oResultIdentity;
|
||||
return oResultIdentity || aIdentities[0] || null;
|
||||
};
|
||||
|
||||
ComposePopupView.prototype.selectIdentity = function (oIdentity)
|
||||
{
|
||||
if (oIdentity)
|
||||
if (oIdentity && oIdentity.item)
|
||||
{
|
||||
this.currentIdentityID(oIdentity.optValue);
|
||||
Local.set(Enums.ClientSideKeyName.ComposeLastIdentityID, oIdentity.optValue);
|
||||
this.currentIdentity(oIdentity.item);
|
||||
this.setSignatureFromIdentity(oIdentity.item);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -775,97 +725,6 @@
|
|||
kn.routeOn();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sInputText
|
||||
* @param {string} sSignature
|
||||
* @param {string=} sFrom
|
||||
* @param {string=} sComposeType
|
||||
* @return {string}
|
||||
*/
|
||||
ComposePopupView.prototype.convertSignature = function (sInputText, sSignature, sFrom, sComposeType)
|
||||
{
|
||||
var bHtml = false, bData = false;
|
||||
if ('' !== sSignature)
|
||||
{
|
||||
if (':HTML:' === sSignature.substr(0, 6))
|
||||
{
|
||||
bHtml = true;
|
||||
sSignature = sSignature.substr(6);
|
||||
}
|
||||
|
||||
sSignature = sSignature.replace(/[\r]/g, '');
|
||||
|
||||
sFrom = Utils.pString(sFrom);
|
||||
if ('' !== sFrom)
|
||||
{
|
||||
sSignature = sSignature.replace(/{{FROM-FULL}}/g, sFrom);
|
||||
|
||||
if (-1 === sFrom.indexOf(' ') && 0 < sFrom.indexOf('@'))
|
||||
{
|
||||
sFrom = sFrom.replace(/@(.+)$/, '');
|
||||
}
|
||||
|
||||
sSignature = sSignature.replace(/{{FROM}}/g, sFrom);
|
||||
}
|
||||
|
||||
sSignature = sSignature.replace(/[\s]{1,2}{{FROM}}/g, '{{FROM}}');
|
||||
sSignature = sSignature.replace(/[\s]{1,2}{{FROM-FULL}}/g, '{{FROM-FULL}}');
|
||||
|
||||
sSignature = sSignature.replace(/{{FROM}}/g, '');
|
||||
sSignature = sSignature.replace(/{{FROM-FULL}}/g, '');
|
||||
|
||||
if (-1 < sSignature.indexOf('{{DATE}}'))
|
||||
{
|
||||
sSignature = sSignature.replace(/{{DATE}}/g, moment().format('llll'));
|
||||
}
|
||||
|
||||
// Enums.ComposeType.Empty === sComposeType
|
||||
if (-1 < sSignature.indexOf('{{BODY}}'))
|
||||
{
|
||||
if (sInputText)
|
||||
{
|
||||
bData = true;
|
||||
|
||||
sSignature = bHtml ? sSignature : Utils.plainToHtml(sSignature, true);
|
||||
sSignature = sSignature.replace('{{BODY}}', sInputText);
|
||||
}
|
||||
else
|
||||
{
|
||||
sSignature = sSignature.replace(/[\n]?{{BODY}}[\n]?/g, '{{BODY}}');
|
||||
sSignature = sSignature.replace(/{{BODY}}/g, '');
|
||||
|
||||
sSignature = bHtml ? sSignature : Utils.plainToHtml(sSignature, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sSignature = bHtml ? sSignature : Utils.plainToHtml(sSignature, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bData)
|
||||
{
|
||||
if (sSignature)
|
||||
{
|
||||
switch (sComposeType)
|
||||
{
|
||||
case Enums.ComposeType.Empty:
|
||||
sInputText = sInputText + '<br />' + sSignature;
|
||||
break;
|
||||
default:
|
||||
sInputText = sSignature + '<br />' + sInputText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sInputText = sSignature;
|
||||
}
|
||||
|
||||
return sInputText;
|
||||
};
|
||||
|
||||
ComposePopupView.prototype.editor = function (fOnInit)
|
||||
{
|
||||
if (fOnInit)
|
||||
|
|
@ -873,13 +732,11 @@
|
|||
var self = this;
|
||||
if (!this.oEditor && this.composeEditorArea())
|
||||
{
|
||||
_.delay(function () {
|
||||
self.oEditor = new HtmlEditor(self.composeEditorArea(), null, function () {
|
||||
fOnInit(self.oEditor);
|
||||
}, function (bHtml) {
|
||||
self.isHtml(!!bHtml);
|
||||
});
|
||||
}, 300);
|
||||
self.oEditor = new HtmlEditor(self.composeEditorArea(), null, function () {
|
||||
fOnInit(self.oEditor);
|
||||
}, function (bHtml) {
|
||||
self.isHtml(!!bHtml);
|
||||
});
|
||||
}
|
||||
else if (this.oEditor)
|
||||
{
|
||||
|
|
@ -888,6 +745,101 @@
|
|||
}
|
||||
};
|
||||
|
||||
ComposePopupView.prototype.converSignature = function (sSignature)
|
||||
{
|
||||
var
|
||||
iLimit = 10,
|
||||
oMatch = null,
|
||||
aMoments = [],
|
||||
oMomentRegx = /{{MOMENT:([^}]+)}}/g,
|
||||
sFrom = ''
|
||||
;
|
||||
|
||||
sSignature = sSignature.replace(/[\r]/g, '');
|
||||
|
||||
sFrom = this.oLastMessage ? this.emailArrayToStringLineHelper(this.oLastMessage.from, true) : '';
|
||||
if ('' !== sFrom)
|
||||
{
|
||||
sSignature = sSignature.replace(/{{FROM-FULL}}/g, sFrom);
|
||||
|
||||
if (-1 === sFrom.indexOf(' ') && 0 < sFrom.indexOf('@'))
|
||||
{
|
||||
sFrom = sFrom.replace(/@[\S]+/, '');
|
||||
}
|
||||
|
||||
sSignature = sSignature.replace(/{{FROM}}/g, sFrom);
|
||||
}
|
||||
|
||||
sSignature = sSignature.replace(/[\s]{1,2}{{FROM}}/g, '{{FROM}}');
|
||||
sSignature = sSignature.replace(/[\s]{1,2}{{FROM-FULL}}/g, '{{FROM-FULL}}');
|
||||
|
||||
sSignature = sSignature.replace(/{{FROM}}/g, '');
|
||||
sSignature = sSignature.replace(/{{FROM-FULL}}/g, '');
|
||||
|
||||
if (-1 < sSignature.indexOf('{{DATE}}'))
|
||||
{
|
||||
sSignature = sSignature.replace(/{{DATE}}/g, moment().format('llll'));
|
||||
}
|
||||
|
||||
if (-1 < sSignature.indexOf('{{TIME}}'))
|
||||
{
|
||||
sSignature = sSignature.replace(/{{TIME}}/g, moment().format('LT'));
|
||||
}
|
||||
if (-1 < sSignature.indexOf('{{MOMENT:'))
|
||||
{
|
||||
try
|
||||
{
|
||||
while ((oMatch = oMomentRegx.exec(sSignature)) !== null)
|
||||
{
|
||||
if (oMatch && oMatch[0] && oMatch[1])
|
||||
{
|
||||
aMoments.push([oMatch[0], oMatch[1]]);
|
||||
}
|
||||
|
||||
iLimit--;
|
||||
if (0 === iLimit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (aMoments && 0 < aMoments.length)
|
||||
{
|
||||
_.each(aMoments, function (aData) {
|
||||
sSignature = sSignature.replace(aData[0], moment().format(aData[1]));
|
||||
});
|
||||
}
|
||||
|
||||
sSignature = sSignature.replace(/{{MOMENT:[^}]+}}/g, '');
|
||||
}
|
||||
catch(e) {}
|
||||
}
|
||||
|
||||
return sSignature;
|
||||
};
|
||||
|
||||
ComposePopupView.prototype.setSignatureFromIdentity = function (oIdentity)
|
||||
{
|
||||
if (oIdentity)
|
||||
{
|
||||
var self = this;
|
||||
this.editor(function (oEditor) {
|
||||
var bHtml = false, sSignature = oIdentity.signature();
|
||||
if ('' !== sSignature)
|
||||
{
|
||||
if (':HTML:' === sSignature.substr(0, 6))
|
||||
{
|
||||
bHtml = true;
|
||||
sSignature = sSignature.substr(6);
|
||||
}
|
||||
}
|
||||
|
||||
oEditor.setSignature(self.converSignature(sSignature),
|
||||
bHtml, !!oIdentity.signatureInsertBefore());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string=} sType = Enums.ComposeType.Empty
|
||||
* @param {?MessageModel|Array=} oMessageOrArray = null
|
||||
|
|
@ -956,6 +908,28 @@
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array} aList
|
||||
* @param {boolean} bFriendly
|
||||
* @returns {string}
|
||||
*/
|
||||
ComposePopupView.prototype.emailArrayToStringLineHelper = function (aList, bFriendly)
|
||||
{
|
||||
var
|
||||
iIndex = 0,
|
||||
iLen = aList.length,
|
||||
aResult = []
|
||||
;
|
||||
|
||||
for (; iIndex < iLen; iIndex++)
|
||||
{
|
||||
aResult.push(aList[iIndex].toLine(!!bFriendly));
|
||||
}
|
||||
|
||||
return aResult.join(', ');
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string=} sType = Enums.ComposeType.Empty
|
||||
* @param {?MessageModel|Array=} oMessageOrArray = null
|
||||
|
|
@ -984,26 +958,10 @@
|
|||
oExcludeEmail = {},
|
||||
oIdentity = null,
|
||||
mEmail = AccountStore.email(),
|
||||
sSignature = AccountStore.signature(),
|
||||
aDownloads = [],
|
||||
aDraftInfo = null,
|
||||
oMessage = null,
|
||||
sComposeType = sType || Enums.ComposeType.Empty,
|
||||
fEmailArrayToStringLineHelper = function (aList, bFriendly) {
|
||||
|
||||
var
|
||||
iIndex = 0,
|
||||
iLen = aList.length,
|
||||
aResult = []
|
||||
;
|
||||
|
||||
for (; iIndex < iLen; iIndex++)
|
||||
{
|
||||
aResult.push(aList[iIndex].toLine(!!bFriendly));
|
||||
}
|
||||
|
||||
return aResult.join(', ');
|
||||
}
|
||||
sComposeType = sType || Enums.ComposeType.Empty
|
||||
;
|
||||
|
||||
oMessageOrArray = oMessageOrArray || null;
|
||||
|
|
@ -1013,39 +971,34 @@
|
|||
(!Utils.isArray(oMessageOrArray) ? oMessageOrArray : null);
|
||||
}
|
||||
|
||||
this.oLastMessage = oMessage;
|
||||
|
||||
if (null !== mEmail)
|
||||
{
|
||||
oExcludeEmail[mEmail] = true;
|
||||
}
|
||||
|
||||
this.reset();
|
||||
|
||||
oIdentity = this.findIdentityByMessage(sComposeType, oMessage);
|
||||
if (oIdentity)
|
||||
{
|
||||
oExcludeEmail[oIdentity.email()] = true;
|
||||
this.currentIdentityID(oIdentity.id());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currentIdentityID('');
|
||||
}
|
||||
|
||||
this.reset();
|
||||
|
||||
this.currentIdentityID.valueHasMutated(); // Populate BBC from Identity
|
||||
|
||||
if (Utils.isNonEmptyArray(aToEmails))
|
||||
{
|
||||
this.to(fEmailArrayToStringLineHelper(aToEmails));
|
||||
this.to(this.emailArrayToStringLineHelper(aToEmails));
|
||||
}
|
||||
|
||||
if (Utils.isNonEmptyArray(aCcEmails))
|
||||
{
|
||||
this.cc(fEmailArrayToStringLineHelper(aCcEmails));
|
||||
this.cc(this.emailArrayToStringLineHelper(aCcEmails));
|
||||
}
|
||||
|
||||
if (Utils.isNonEmptyArray(aBccEmails))
|
||||
{
|
||||
this.bcc(fEmailArrayToStringLineHelper(aBccEmails));
|
||||
this.bcc(this.emailArrayToStringLineHelper(aBccEmails));
|
||||
}
|
||||
|
||||
if ('' !== sComposeType && oMessage)
|
||||
|
|
@ -1074,7 +1027,7 @@
|
|||
break;
|
||||
|
||||
case Enums.ComposeType.Reply:
|
||||
this.to(fEmailArrayToStringLineHelper(oMessage.replyEmails(oExcludeEmail)));
|
||||
this.to(this.emailArrayToStringLineHelper(oMessage.replyEmails(oExcludeEmail)));
|
||||
this.subject(Utils.replySubjectAdd('Re', sSubject));
|
||||
this.prepearMessageAttachments(oMessage, sComposeType);
|
||||
this.aDraftInfo = ['reply', oMessage.uid, oMessage.folderFullNameRaw];
|
||||
|
|
@ -1084,8 +1037,8 @@
|
|||
|
||||
case Enums.ComposeType.ReplyAll:
|
||||
aResplyAllParts = oMessage.replyAllEmails(oExcludeEmail);
|
||||
this.to(fEmailArrayToStringLineHelper(aResplyAllParts[0]));
|
||||
this.cc(fEmailArrayToStringLineHelper(aResplyAllParts[1]));
|
||||
this.to(this.emailArrayToStringLineHelper(aResplyAllParts[0]));
|
||||
this.cc(this.emailArrayToStringLineHelper(aResplyAllParts[1]));
|
||||
this.subject(Utils.replySubjectAdd('Re', sSubject));
|
||||
this.prepearMessageAttachments(oMessage, sComposeType);
|
||||
this.aDraftInfo = ['reply', oMessage.uid, oMessage.folderFullNameRaw];
|
||||
|
|
@ -1110,10 +1063,10 @@
|
|||
break;
|
||||
|
||||
case Enums.ComposeType.Draft:
|
||||
this.to(fEmailArrayToStringLineHelper(oMessage.to));
|
||||
this.cc(fEmailArrayToStringLineHelper(oMessage.cc));
|
||||
this.bcc(fEmailArrayToStringLineHelper(oMessage.bcc));
|
||||
this.replyTo(fEmailArrayToStringLineHelper(oMessage.replyTo));
|
||||
this.to(this.emailArrayToStringLineHelper(oMessage.to));
|
||||
this.cc(this.emailArrayToStringLineHelper(oMessage.cc));
|
||||
this.bcc(this.emailArrayToStringLineHelper(oMessage.bcc));
|
||||
this.replyTo(this.emailArrayToStringLineHelper(oMessage.replyTo));
|
||||
|
||||
this.bFromDraft = true;
|
||||
|
||||
|
|
@ -1129,10 +1082,10 @@
|
|||
break;
|
||||
|
||||
case Enums.ComposeType.EditAsNew:
|
||||
this.to(fEmailArrayToStringLineHelper(oMessage.to));
|
||||
this.cc(fEmailArrayToStringLineHelper(oMessage.cc));
|
||||
this.bcc(fEmailArrayToStringLineHelper(oMessage.bcc));
|
||||
this.replyTo(fEmailArrayToStringLineHelper(oMessage.replyTo));
|
||||
this.to(this.emailArrayToStringLineHelper(oMessage.to));
|
||||
this.cc(this.emailArrayToStringLineHelper(oMessage.cc));
|
||||
this.bcc(this.emailArrayToStringLineHelper(oMessage.bcc));
|
||||
this.replyTo(this.emailArrayToStringLineHelper(oMessage.replyTo));
|
||||
|
||||
this.subject(sSubject);
|
||||
this.prepearMessageAttachments(oMessage, sComposeType);
|
||||
|
|
@ -1153,7 +1106,7 @@
|
|||
'EMAIL': sFrom
|
||||
});
|
||||
|
||||
sText = '<br /><br />' + sReplyTitle + ':' +
|
||||
sText = '<br />' + sReplyTitle + ':' +
|
||||
'<blockquote><p>' + sText + '</p></blockquote>';
|
||||
|
||||
break;
|
||||
|
|
@ -1162,7 +1115,7 @@
|
|||
sFrom = oMessage.fromToLine(false, true);
|
||||
sTo = oMessage.toToLine(false, true);
|
||||
sCc = oMessage.ccToLine(false, true);
|
||||
sText = '<br /><br /><br />' + Translator.i18n('COMPOSE/FORWARD_MESSAGE_TOP_TITLE') +
|
||||
sText = '<br /><br />' + Translator.i18n('COMPOSE/FORWARD_MESSAGE_TOP_TITLE') +
|
||||
'<br />' + Translator.i18n('COMPOSE/FORWARD_MESSAGE_TOP_FROM') + ': ' + sFrom +
|
||||
'<br />' + Translator.i18n('COMPOSE/FORWARD_MESSAGE_TOP_TO') + ': ' + sTo +
|
||||
(0 < sCc.length ? '<br />' + Translator.i18n('COMPOSE/FORWARD_MESSAGE_TOP_CC') + ': ' + sCc : '') +
|
||||
|
|
@ -1175,19 +1128,20 @@
|
|||
break;
|
||||
}
|
||||
|
||||
if ('' !== sSignature &&
|
||||
Enums.ComposeType.EditAsNew !== sComposeType && Enums.ComposeType.Draft !== sComposeType)
|
||||
{
|
||||
sText = this.convertSignature(sText, sSignature, fEmailArrayToStringLineHelper(oMessage.from, true), sComposeType);
|
||||
}
|
||||
|
||||
this.editor(function (oEditor) {
|
||||
|
||||
oEditor.setHtml(sText, false);
|
||||
|
||||
if (Enums.EditorDefaultType.PlainForced === self.editorDefaultType() ||
|
||||
(!oMessage.isHtml() && Enums.EditorDefaultType.HtmlForced !== self.editorDefaultType()))
|
||||
{
|
||||
oEditor.modeToggle(false);
|
||||
}
|
||||
|
||||
if (oIdentity)
|
||||
{
|
||||
self.setSignatureFromIdentity(oIdentity);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (Enums.ComposeType.Empty === sComposeType)
|
||||
|
|
@ -1195,18 +1149,21 @@
|
|||
this.subject(Utils.isNormal(sCustomSubject) ? '' + sCustomSubject : '');
|
||||
|
||||
sText = Utils.isNormal(sCustomPlainText) ? '' + sCustomPlainText : '';
|
||||
if ('' !== sSignature)
|
||||
{
|
||||
sText = this.convertSignature(Utils.plainToHtml(sText, true), sSignature, '', sComposeType);
|
||||
}
|
||||
|
||||
this.editor(function (oEditor) {
|
||||
|
||||
oEditor.setHtml(sText, false);
|
||||
|
||||
if (Enums.EditorDefaultType.Html !== self.editorDefaultType() &&
|
||||
Enums.EditorDefaultType.HtmlForced !== self.editorDefaultType())
|
||||
{
|
||||
oEditor.modeToggle(false);
|
||||
}
|
||||
|
||||
if (oIdentity)
|
||||
{
|
||||
self.setSignatureFromIdentity(oIdentity);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (Utils.isNonEmptyArray(oMessageOrArray))
|
||||
|
|
@ -1214,6 +1171,22 @@
|
|||
_.each(oMessageOrArray, function (oMessage) {
|
||||
self.addMessageAsAttachment(oMessage);
|
||||
});
|
||||
|
||||
this.editor(function (oEditor) {
|
||||
|
||||
oEditor.setHtml('', false);
|
||||
|
||||
if (Enums.EditorDefaultType.Html !== self.editorDefaultType() &&
|
||||
Enums.EditorDefaultType.HtmlForced !== self.editorDefaultType())
|
||||
{
|
||||
oEditor.modeToggle(false);
|
||||
}
|
||||
|
||||
if (oIdentity)
|
||||
{
|
||||
self.setSignatureFromIdentity(oIdentity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
aDownloads = this.getAttachmentsDownloadsForUpload();
|
||||
|
|
@ -1252,6 +1225,11 @@
|
|||
}, aDownloads);
|
||||
}
|
||||
|
||||
if (oIdentity)
|
||||
{
|
||||
this.currentIdentity(oIdentity);
|
||||
}
|
||||
|
||||
this.triggerForResize();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsIdentity');
|
||||
|
||||
var self = this;
|
||||
|
||||
this.id = '';
|
||||
this.edit = ko.observable(false);
|
||||
this.owner = ko.observable(false);
|
||||
|
|
@ -43,16 +45,32 @@
|
|||
this.bcc.focused = ko.observable(false);
|
||||
|
||||
this.signature = ko.observable('');
|
||||
this.signatureInsertBefore = ko.observable(false);
|
||||
|
||||
// this.email.subscribe(function () {
|
||||
// this.email.hasError(false);
|
||||
// }, this);
|
||||
this.showBcc = ko.observable(false);
|
||||
this.showReplyTo = ko.observable(false);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.bcc.subscribe(function (aValue) {
|
||||
if (false === self.showBcc() && 0 < aValue.length)
|
||||
{
|
||||
self.showBcc(true);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.replyTo.subscribe(function (aValue) {
|
||||
if (false === self.showReplyTo() && 0 < aValue.length)
|
||||
{
|
||||
self.showReplyTo(true);
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.addOrEditIdentityCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.populateSignatureFromEditor();
|
||||
|
||||
if (!this.email.hasError())
|
||||
{
|
||||
this.email.hasError('' === Utils.trim(this.email()));
|
||||
|
|
@ -102,7 +120,8 @@
|
|||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc());
|
||||
}, this), this.id, this.email(), this.name(), this.replyTo(), this.bcc(),
|
||||
this.signature(), this.signatureInsertBefore());
|
||||
|
||||
return true;
|
||||
|
||||
|
|
@ -126,17 +145,22 @@
|
|||
this.email('');
|
||||
this.replyTo('');
|
||||
this.bcc('');
|
||||
this.signature('');
|
||||
this.signatureInsertBefore(false);
|
||||
|
||||
this.email.hasError(false);
|
||||
this.replyTo.hasError(false);
|
||||
this.bcc.hasError(false);
|
||||
|
||||
this.showBcc(false);
|
||||
this.showReplyTo(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
|
||||
if (this.editor)
|
||||
{
|
||||
this.editor.clear(false);
|
||||
this.editor.setPlain('', false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -156,6 +180,8 @@
|
|||
this.email(oIdentity.email());
|
||||
this.replyTo(oIdentity.replyTo());
|
||||
this.bcc(oIdentity.bcc());
|
||||
this.signature(oIdentity.signature());
|
||||
this.signatureInsertBefore(oIdentity.signatureInsertBefore());
|
||||
|
||||
this.owner(this.id === '');
|
||||
}
|
||||
|
|
@ -185,15 +211,23 @@
|
|||
}
|
||||
};
|
||||
|
||||
IdentityPopupView.prototype.populateSignatureFromEditor = function ()
|
||||
{
|
||||
if (this.editor)
|
||||
{
|
||||
this.signature(
|
||||
(this.editor.isHtml() ? ':HTML:' : '') + this.editor.getData()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
IdentityPopupView.prototype.onFocus = function ()
|
||||
{
|
||||
if (!this.editor && this.signatureDom())
|
||||
{
|
||||
var self = this;
|
||||
this.editor = new HtmlEditor(self.signatureDom(), function () {
|
||||
self.signature(
|
||||
(self.editor.isHtml() ? ':HTML:' : '') + self.editor.getData()
|
||||
);
|
||||
self.populateSignatureFromEditor();
|
||||
}, function () {
|
||||
self.setSignature(self.signature());
|
||||
});
|
||||
|
|
|
|||
179
dev/View/Popup/Template.js
Normal file
179
dev/View/Popup/Template.js
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
Translator = require('Common/Translator'),
|
||||
HtmlEditor = require('Common/HtmlEditor'),
|
||||
|
||||
Remote = require('Storage/User/Remote'),
|
||||
|
||||
kn = require('Knoin/Knoin'),
|
||||
AbstractView = require('Knoin/AbstractView')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractView
|
||||
*/
|
||||
function TemplatePopupView()
|
||||
{
|
||||
AbstractView.call(this, 'Popups', 'PopupsTemplate');
|
||||
|
||||
this.editor = null;
|
||||
this.signatureDom = ko.observable(null);
|
||||
|
||||
this.id = ko.observable('');
|
||||
|
||||
this.name = ko.observable('');
|
||||
this.name.error = ko.observable(false);
|
||||
this.name.focus = ko.observable(false);
|
||||
|
||||
this.body = ko.observable('');
|
||||
this.body.error = ko.observable(false);
|
||||
|
||||
this.name.subscribe(function () {
|
||||
this.name.error(false);
|
||||
}, this);
|
||||
|
||||
this.body.subscribe(function () {
|
||||
this.body.error(false);
|
||||
}, this);
|
||||
|
||||
this.submitRequest = ko.observable(false);
|
||||
this.submitError = ko.observable('');
|
||||
|
||||
this.addTemplateCommand = Utils.createCommand(this, function () {
|
||||
|
||||
this.name.error('' === Utils.trim(this.name()));
|
||||
this.body.error('' === Utils.trim(this.body()) ||
|
||||
':HTML:' === Utils.trim(this.body()));
|
||||
|
||||
if (this.name.error() || this.body.error())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.templateSetup(_.bind(function (sResult, oData) {
|
||||
|
||||
this.submitRequest(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData)
|
||||
{
|
||||
if (oData.Result)
|
||||
{
|
||||
require('App/User').templates();
|
||||
this.cancelCommand();
|
||||
}
|
||||
else if (oData.ErrorCode)
|
||||
{
|
||||
this.submitError(Translator.getNotification(oData.ErrorCode));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.submitError(Translator.getNotification(Enums.Notification.UnknownError));
|
||||
}
|
||||
|
||||
}, this), this.id(), this.name(), this.body());
|
||||
|
||||
return true;
|
||||
|
||||
}, function () {
|
||||
return !this.submitRequest();
|
||||
});
|
||||
|
||||
kn.constructorEnd(this);
|
||||
}
|
||||
|
||||
kn.extendAsViewModel(['View/Popup/Template'], TemplatePopupView);
|
||||
_.extend(TemplatePopupView.prototype, AbstractView.prototype);
|
||||
|
||||
TemplatePopupView.prototype.clearPopup = function ()
|
||||
{
|
||||
this.id('');
|
||||
|
||||
this.name('');
|
||||
this.name.error(false);
|
||||
|
||||
this.body('');
|
||||
this.body.loading(false);
|
||||
this.body.error(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
};
|
||||
|
||||
TemplatePopupView.prototype.editorSetBody = function (sBody)
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
fEditorSetData = function (sBody) {
|
||||
if (self.editor)
|
||||
{
|
||||
if (':HTML:' === sBody.substr(0, 6))
|
||||
{
|
||||
self.editor.setHtml(sBody.substr(6), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.editor.setPlain(sBody, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
if (!this.editor && this.signatureDom())
|
||||
{
|
||||
this.editor = new HtmlEditor(self.signatureDom(), function () {
|
||||
self.body(
|
||||
(self.editor.isHtml() ? ':HTML:' : '') + self.editor.getData()
|
||||
);
|
||||
}, function () {
|
||||
fEditorSetData(sBody);
|
||||
});
|
||||
}
|
||||
else if (this.editor)
|
||||
{
|
||||
fEditorSetData(sBody);
|
||||
}
|
||||
};
|
||||
|
||||
TemplatePopupView.prototype.onShow = function (oTemplate)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.clearPopup();
|
||||
|
||||
if (oTemplate && oTemplate.id)
|
||||
{
|
||||
this.id(oTemplate.id);
|
||||
this.name(oTemplate.name);
|
||||
|
||||
this.body.loading(true);
|
||||
|
||||
Remote.templateGetById(function () {
|
||||
|
||||
self.body.loading(false);
|
||||
|
||||
self.editorSetBody('');
|
||||
|
||||
}, this.id());
|
||||
}
|
||||
};
|
||||
|
||||
TemplatePopupView.prototype.onFocus = function ()
|
||||
{
|
||||
this.name.focus(true);
|
||||
};
|
||||
|
||||
module.exports = TemplatePopupView;
|
||||
|
||||
}());
|
||||
|
|
@ -190,7 +190,7 @@
|
|||
this.viewDate = ko.observable('');
|
||||
this.viewSize = ko.observable('');
|
||||
this.viewMoment = ko.observable('');
|
||||
this.viewLineAsCcc = ko.observable('');
|
||||
this.viewLineAsCss = ko.observable('');
|
||||
this.viewViewLink = ko.observable('');
|
||||
this.viewDownloadLink = ko.observable('');
|
||||
this.viewUserPic = ko.observable(Consts.DataImages.UserDotPic);
|
||||
|
|
@ -272,7 +272,7 @@
|
|||
this.viewDate(oMessage.fullFormatDateValue());
|
||||
this.viewSize(oMessage.friendlySize());
|
||||
this.viewMoment(oMessage.momentDate());
|
||||
this.viewLineAsCcc(oMessage.lineAsCcc());
|
||||
this.viewLineAsCss(oMessage.lineAsCss());
|
||||
this.viewViewLink(oMessage.viewLink());
|
||||
this.viewDownloadLink(oMessage.downloadLink());
|
||||
this.viewIsImportant(oMessage.isImportant());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue