Code refactoring

This commit is contained in:
RainLoop Team 2015-04-06 23:32:19 +04:00
parent ffde4f03a8
commit b7709c8117
21 changed files with 291 additions and 192 deletions

View file

@ -131,10 +131,42 @@
this.sendSuccessButSaveError = ko.observable(false);
this.savedError = ko.observable(false);
this.sendErrorDesc = ko.observable('');
this.savedErrorDesc = ko.observable('');
this.sendError.subscribe(function (bValue) {
if (!bValue)
{
this.sendErrorDesc('');
}
}, this);
this.savedError.subscribe(function (bValue) {
if (!bValue)
{
this.savedErrorDesc('');
}
}, this);
this.sendSuccessButSaveError.subscribe(function (bValue) {
if (!bValue)
{
this.savedErrorDesc('');
}
}, this);
this.savedTime = ko.observable(0);
this.savedOrSendingText = ko.observable('');
this.savedTimeText = ko.computed(function () {
return 0 < this.savedTime() ? Translator.i18n('COMPOSE/SAVED_TIME', {
'TIME': Momentor.format(this.savedTime() - 1, 'LT')
}) : '';
}, this);
this.emptyToError = ko.observable(false);
this.emptyToErrorTooltip = ko.computed(function () {
return this.emptyToError() ? Translator.i18n('COMPOSE/EMPTY_TO_ERROR_DESC') : '';
}, this);
this.attachmentsInProcessError = ko.observable(false);
this.attachmentsInErrorError = ko.observable(false);
@ -597,27 +629,25 @@
{
var
aIdentities = IdentityStore.identities(),
iResultIndex = 1000,
oResultIdentity = null,
oIdentitiesCache = {},
fFindHelper = function (oItem) {
if (oResultIdentity)
{
return true;
}
fEachHelper = function (oItem) {
if (!oResultIdentity && oItem && oItem.email && oIdentitiesCache[oItem.email])
if (oItem && oItem.email && oIdentitiesCache[oItem.email])
{
oResultIdentity = oIdentitiesCache[oItem.email];
return true;
if (!oResultIdentity || iResultIndex > oIdentitiesCache[oItem.email][1])
{
oResultIdentity = oIdentitiesCache[oItem.email][0];
iResultIndex = oIdentitiesCache[oItem.email][1];
}
}
return false;
}
;
_.each(aIdentities, function (oItem) {
oIdentitiesCache[oItem.email()] = oItem;
_.each(aIdentities, function (oItem, iIndex) {
oIdentitiesCache[oItem.email()] = [oItem, iIndex];
});
if (oMessage)
@ -630,10 +660,10 @@
case Enums.ComposeType.ReplyAll:
case Enums.ComposeType.Forward:
case Enums.ComposeType.ForwardAsAttachment:
_.find(_.union(oMessage.to, oMessage.cc, oMessage.bcc, oMessage.deliveredTo), fFindHelper);
_.each(_.union(oMessage.to, oMessage.cc, oMessage.bcc, oMessage.deliveredTo), fEachHelper);
break;
case Enums.ComposeType.Draft:
_.find(_.union(oMessage.from, oMessage.replyTo), fFindHelper);
_.each(_.union(oMessage.from, oMessage.replyTo), fEachHelper);
break;
}
}
@ -673,7 +703,7 @@
if (oData && Enums.Notification.CantSaveMessage === oData.ErrorCode)
{
this.sendSuccessButSaveError(true);
window.alert(Utils.trim(Translator.i18n('COMPOSE/SAVED_ERROR_ON_SEND')));
this.savedErrorDesc(Utils.trim(Translator.i18n('COMPOSE/SAVED_ERROR_ON_SEND')));
}
else
{
@ -681,7 +711,7 @@
oData && oData.ErrorMessage ? oData.ErrorMessage : '');
this.sendError(true);
window.alert(sMessage || Translator.getNotification(Enums.Notification.CantSendMessage));
this.sendErrorDesc(sMessage || Translator.getNotification(Enums.Notification.CantSendMessage));
}
}
@ -717,12 +747,6 @@
this.savedTime(window.Math.round((new window.Date()).getTime() / 1000));
this.savedOrSendingText(
0 < this.savedTime() ? Translator.i18n('COMPOSE/SAVED_TIME', {
'TIME': Momentor.format(this.savedTime() - 1, 'LT')
}) : ''
);
if (this.bFromDraft)
{
Cache.setFolderHash(this.draftFolder(), '');
@ -733,7 +757,7 @@
if (!bResult)
{
this.savedError(true);
this.savedOrSendingText(Translator.getNotification(Enums.Notification.CantSaveMessage));
this.savedErrorDesc(Translator.getNotification(Enums.Notification.CantSaveMessage));
}
this.reloadDraftFolder();
@ -1046,16 +1070,12 @@
oText = $(oMessage.body).clone();
if (oText)
{
oText.find('blockquote.rl-bq-switcher').each(function () {
$(this).removeClass('rl-bq-switcher hidden-bq');
});
oText.find('.rlBlockquoteSwitcher').each(function () {
$(this).remove();
});
}
oText.find('blockquote.rl-bq-switcher').removeClass('rl-bq-switcher hidden-bq');
oText.find('.rlBlockquoteSwitcher').off('.rlBlockquoteSwitcher').remove();
oText.find('[data-html-editor-font-wrapper]').removeAttr('data-html-editor-font-wrapper');
oText.find('[data-html-editor-font-wrapper]').removeAttr('data-html-editor-font-wrapper');
sText = oText.html();
sText = oText.html();
}
switch (sComposeType)
{
@ -2058,7 +2078,6 @@
this.sendSuccessButSaveError(false);
this.savedError(false);
this.savedTime(0);
this.savedOrSendingText('');
this.emptyToError(false);
this.attachmentsInProcessError(false);

View file

@ -11,7 +11,6 @@
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
HtmlEditor = require('Common/HtmlEditor'),
Remote = require('Remote/User/Ajax'),
@ -33,9 +32,6 @@
this.edit = ko.observable(false);
this.owner = ko.observable(false);
this.editor = null;
this.signatureDom = ko.observable(null);
this.email = ko.observable('').validateEmail();
this.email.focused = ko.observable(false);
this.name = ko.observable('');
@ -70,7 +66,10 @@
this.addOrEditIdentityCommand = Utils.createCommand(this, function () {
this.populateSignatureFromEditor();
if (this.signature && this.signature.__fetchEditorValue)
{
this.signature.__fetchEditorValue();
}
if (!this.email.hasError())
{
@ -158,36 +157,6 @@
this.submitRequest(false);
this.submitError('');
if (this.editor)
{
this.editor.setPlain('', false);
}
};
IdentityPopupView.prototype.populateSignatureFromEditor = function ()
{
if (this.editor)
{
this.signature(this.editor.getDataWithHtmlMark());
}
};
IdentityPopupView.prototype.editorSetSignature = function (sSignature)
{
if (!this.editor && this.signatureDom())
{
var self = this;
this.editor = new HtmlEditor(self.signatureDom(), function () {
self.populateSignatureFromEditor();
}, function () {
self.editor.setHtmlOrPlain(sSignature);
});
}
else
{
this.editor.setHtmlOrPlain(sSignature);
}
};
/**
@ -215,8 +184,6 @@
{
this.id = Utils.fakeMd5();
}
this.editorSetSignature(this.signature());
};
IdentityPopupView.prototype.onShowWithDelay = function ()

View file

@ -61,11 +61,17 @@
this.submitRequest(true);
_.delay(function () {
mKeyPair = PgpStore.openpgp.generateKeyPair({
'userId': sUserID,
'numBits': Utils.pInt(self.keyBitLength()),
'passphrase': Utils.trim(self.password())
});
mKeyPair = false;
try {
mKeyPair = PgpStore.openpgp.generateKeyPair({
'userId': sUserID,
'numBits': Utils.pInt(self.keyBitLength()),
'passphrase': Utils.trim(self.password())
});
} catch (e) {
// window.console.log(e);
}
if (mKeyPair && mKeyPair.privateKeyArmored)
{
@ -78,6 +84,7 @@
}
self.submitRequest(false);
}, 100);
return true;