mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Code refactoring
This commit is contained in:
parent
79233ad83c
commit
286ab567af
53 changed files with 618 additions and 581 deletions
|
|
@ -7,6 +7,8 @@
|
|||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
|
||||
Remote = require('Storage/User/Remote')
|
||||
;
|
||||
|
||||
|
|
@ -15,6 +17,15 @@
|
|||
*/
|
||||
function AccountUserStore()
|
||||
{
|
||||
this.email = ko.observable('');
|
||||
// this.incLogin = ko.observable('');
|
||||
// this.outLogin = ko.observable('');
|
||||
|
||||
this.displayName = ko.observable('');
|
||||
this.replyTo = ko.observable('');
|
||||
this.signature = ko.observable('');
|
||||
this.signatureToAll = ko.observable(false);
|
||||
|
||||
this.accounts = ko.observableArray([]);
|
||||
this.accounts.loading = ko.observable(false).extend({'throttle': 100});
|
||||
|
||||
|
|
@ -42,18 +53,30 @@
|
|||
|
||||
var iResult = 0;
|
||||
|
||||
_.each(this.accounts(), function (oItem) {
|
||||
if (oItem)
|
||||
{
|
||||
iResult += oItem.count();
|
||||
}
|
||||
});
|
||||
// _.each(this.accounts(), function (oItem) {
|
||||
// if (oItem)
|
||||
// {
|
||||
// iResult += oItem.count();
|
||||
// }
|
||||
// });
|
||||
|
||||
return iResult;
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
AccountUserStore.prototype.populate = function ()
|
||||
{
|
||||
this.email(Settings.settingsGet('Email'));
|
||||
// this.incLogin(Settings.settingsGet('IncLogin'));
|
||||
// this.outLogin(Settings.settingsGet('OutLogin'));
|
||||
|
||||
this.displayName(Settings.settingsGet('DisplayName'));
|
||||
this.replyTo(Settings.settingsGet('ReplyTo'));
|
||||
this.signature(Settings.settingsGet('Signature'));
|
||||
this.signatureToAll(!!Settings.settingsGet('SignatureToAll'));
|
||||
};
|
||||
|
||||
module.exports = new AccountUserStore();
|
||||
|
||||
}());
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
var
|
||||
ko = require('ko'),
|
||||
|
||||
Globals = require('Common/Globals'),
|
||||
|
||||
Settings = require('Storage/Settings')
|
||||
Settings = require('Storage/Settings'),
|
||||
|
||||
AppStore = require('Stores/App')
|
||||
;
|
||||
|
||||
/**
|
||||
|
|
@ -16,40 +16,31 @@
|
|||
*/
|
||||
function AppUserStore()
|
||||
{
|
||||
// same
|
||||
this.allowLanguagesOnSettings = ko.observable(true);
|
||||
this.allowLanguagesOnLogin = ko.observable(true);
|
||||
// ----
|
||||
AppStore.call(this);
|
||||
|
||||
this.projectHash = ko.observable('');
|
||||
this.threadsAllowed = ko.observable(false);
|
||||
|
||||
this.contactsAutosave = ko.observable(false);
|
||||
this.useLocalProxyForExternalImages = ko.observable(false);
|
||||
|
||||
this.contactsIsAllowed = ko.observable(false);
|
||||
|
||||
this.interfaceAnimation = ko.observable(true);
|
||||
|
||||
this.interfaceAnimation.subscribe(function (bValue) {
|
||||
if (Globals.bMobileDevice || !bValue)
|
||||
{
|
||||
Globals.$html.removeClass('rl-anim').addClass('no-rl-anim');
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals.$html.removeClass('no-rl-anim').addClass('rl-anim');
|
||||
}
|
||||
});
|
||||
|
||||
this.interfaceAnimation.valueHasMutated();
|
||||
this.devEmail = '';
|
||||
this.devPassword = '';
|
||||
}
|
||||
|
||||
AppUserStore.prototype.populate = function()
|
||||
{
|
||||
this.allowLanguagesOnLogin(!!Settings.settingsGet('AllowLanguagesOnLogin'));
|
||||
this.allowLanguagesOnSettings(!!Settings.settingsGet('AllowLanguagesOnSettings'));
|
||||
AppStore.prototype.populate.call(this);
|
||||
|
||||
this.projectHash(Settings.settingsGet('ProjectHash'));
|
||||
|
||||
this.useLocalProxyForExternalImages(!!Settings.settingsGet('UseLocalProxyForExternalImages'));
|
||||
this.contactsIsAllowed(!!Settings.settingsGet('ContactsIsAllowed'));
|
||||
this.interfaceAnimation(!!Settings.settingsGet('InterfaceAnimation'));
|
||||
|
||||
this.devEmail = Settings.settingsGet('DevEmail');
|
||||
this.devPassword = Settings.settingsGet('DevPassword');
|
||||
};
|
||||
|
||||
module.exports = new AppUserStore();
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@
|
|||
this.capa = ko.observable('');
|
||||
this.modules = ko.observable({});
|
||||
|
||||
this.collection = ko.observableArray([]);
|
||||
this.filters = ko.observableArray([]);
|
||||
|
||||
this.collection.loading = ko.observable(false).extend({'throttle': 200});
|
||||
this.collection.saving = ko.observable(false).extend({'throttle': 200});
|
||||
this.filters.loading = ko.observable(false).extend({'throttle': 200});
|
||||
this.filters.saving = ko.observable(false).extend({'throttle': 200});
|
||||
|
||||
this.raw = ko.observable('');
|
||||
}
|
||||
|
|
|
|||
75
dev/Stores/User/Folder.js
Normal file
75
dev/Stores/User/Folder.js
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Consts = require('Common/Consts'),
|
||||
|
||||
Cache = require('Storage/User/Cache')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FolderUserStore()
|
||||
{
|
||||
this.sentFolder = ko.observable('');
|
||||
this.draftFolder = ko.observable('');
|
||||
this.spamFolder = ko.observable('');
|
||||
this.trashFolder = ko.observable('');
|
||||
this.archiveFolder = ko.observable('');
|
||||
|
||||
this.computed();
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
FolderUserStore.prototype.computed = function ()
|
||||
{
|
||||
this.draftFolderNotEnabled = ko.computed(function () {
|
||||
return '' === this.draftFolder() || Consts.Values.UnuseOptionValue === this.draftFolder();
|
||||
}, this);
|
||||
};
|
||||
|
||||
FolderUserStore.prototype.subscribe = function ()
|
||||
{
|
||||
var
|
||||
fRemoveSystemFolderType = function (observable) {
|
||||
return function () {
|
||||
var oFolder = Cache.getFolderFromCacheList(observable());
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.type(Enums.FolderType.User);
|
||||
}
|
||||
};
|
||||
},
|
||||
fSetSystemFolderType = function (iType) {
|
||||
return function (sValue) {
|
||||
var oFolder = Cache.getFolderFromCacheList(sValue);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.type(iType);
|
||||
}
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
this.sentFolder.subscribe(fRemoveSystemFolderType(this.sentFolder), this, 'beforeChange');
|
||||
this.draftFolder.subscribe(fRemoveSystemFolderType(this.draftFolder), this, 'beforeChange');
|
||||
this.spamFolder.subscribe(fRemoveSystemFolderType(this.spamFolder), this, 'beforeChange');
|
||||
this.trashFolder.subscribe(fRemoveSystemFolderType(this.trashFolder), this, 'beforeChange');
|
||||
this.archiveFolder.subscribe(fRemoveSystemFolderType(this.archiveFolder), this, 'beforeChange');
|
||||
|
||||
this.sentFolder.subscribe(fSetSystemFolderType(Enums.FolderType.SentItems), this);
|
||||
this.draftFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Draft), this);
|
||||
this.spamFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Spam), this);
|
||||
this.trashFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Trash), this);
|
||||
this.archiveFolder.subscribe(fSetSystemFolderType(Enums.FolderType.Archive), this);
|
||||
};
|
||||
|
||||
module.exports = new FolderUserStore();
|
||||
|
||||
}());
|
||||
|
|
@ -2,96 +2,108 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
// var
|
||||
// window = require('window')
|
||||
// ;
|
||||
var
|
||||
ko = require('ko')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function PgpUserStore()
|
||||
{
|
||||
this.capaOpenPGP = ko.observable(false);
|
||||
|
||||
this.openpgp = null;
|
||||
this.keyring = [];
|
||||
|
||||
this.openpgpkeys = ko.observableArray([]);
|
||||
this.openpgpKeyring = null;
|
||||
|
||||
this.openpgpkeysPublic = this.openpgpkeys.filter(function (oItem) {
|
||||
return !!(oItem && !oItem.isPrivate);
|
||||
});
|
||||
|
||||
this.openpgpkeysPrivate = this.openpgpkeys.filter(function (oItem) {
|
||||
return !!(oItem && oItem.isPrivate);
|
||||
});
|
||||
}
|
||||
|
||||
PgpUserStore.prototype.sign = function (sText, oPrivateKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.openpgp.signClearMessage([oPrivateKey], sText);
|
||||
}
|
||||
catch (oExc) {}
|
||||
|
||||
return sText;
|
||||
};
|
||||
|
||||
PgpUserStore.prototype.encrypt = function (sText, aPublicKeys)
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.openpgp.encryptMessage(aPublicKeys, sText);
|
||||
}
|
||||
catch (oExc) {}
|
||||
|
||||
return sText;
|
||||
};
|
||||
|
||||
PgpUserStore.prototype.signAndEncrypt = function (sText, aPublicKeys, oPrivateKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, sText);
|
||||
}
|
||||
catch (oExc) {}
|
||||
|
||||
return sText;
|
||||
};
|
||||
|
||||
/**/
|
||||
|
||||
PgpUserStore.prototype.verify = function (sText, aPublicKeys)
|
||||
{
|
||||
var
|
||||
mPgpMessage = null
|
||||
;
|
||||
|
||||
try
|
||||
{
|
||||
mPgpMessage = this.openpgp.cleartext.readArmored(sText);
|
||||
if (mPgpMessage && mPgpMessage.getText)
|
||||
{
|
||||
mPgpMessage.verify(aPublicKeys);
|
||||
}
|
||||
}
|
||||
catch (oExc) {}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
PgpUserStore.prototype.decryptAndVerify = function (sEnctyptedText, aPublicKeys, oPivateKey)
|
||||
{
|
||||
var
|
||||
mPgpMessageDecrypted = null,
|
||||
mPgpMessage = null
|
||||
;
|
||||
|
||||
try
|
||||
{
|
||||
mPgpMessage = this.openpgp.message.readArmored(sEnctyptedText);
|
||||
if (mPgpMessage && oPivateKey && mPgpMessage.decrypt)
|
||||
{
|
||||
mPgpMessageDecrypted = mPgpMessage.decrypt(oPivateKey);
|
||||
if (mPgpMessageDecrypted)
|
||||
{
|
||||
mPgpMessageDecrypted.verify(aPublicKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (oExc) {}
|
||||
|
||||
return false;
|
||||
};
|
||||
// PgpUserStore.prototype.sign = function (sText, oPrivateKey)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// return this.openpgp.signClearMessage([oPrivateKey], sText);
|
||||
// }
|
||||
// catch (oExc) {}
|
||||
//
|
||||
// return sText;
|
||||
// };
|
||||
//
|
||||
// PgpUserStore.prototype.encrypt = function (sText, aPublicKeys)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// return this.openpgp.encryptMessage(aPublicKeys, sText);
|
||||
// }
|
||||
// catch (oExc) {}
|
||||
//
|
||||
// return sText;
|
||||
// };
|
||||
//
|
||||
// PgpUserStore.prototype.signAndEncrypt = function (sText, aPublicKeys, oPrivateKey)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// return this.openpgp.signAndEncryptMessage(aPublicKeys, oPrivateKey, sText);
|
||||
// }
|
||||
// catch (oExc) {}
|
||||
//
|
||||
// return sText;
|
||||
// };
|
||||
//
|
||||
// /**/
|
||||
//
|
||||
// PgpUserStore.prototype.verify = function (sText, aPublicKeys)
|
||||
// {
|
||||
// var
|
||||
// mPgpMessage = null
|
||||
// ;
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// mPgpMessage = this.openpgp.cleartext.readArmored(sText);
|
||||
// if (mPgpMessage && mPgpMessage.getText)
|
||||
// {
|
||||
// mPgpMessage.verify(aPublicKeys);
|
||||
// }
|
||||
// }
|
||||
// catch (oExc) {}
|
||||
//
|
||||
// return false;
|
||||
// };
|
||||
//
|
||||
// PgpUserStore.prototype.decryptAndVerify = function (sEnctyptedText, aPublicKeys, oPivateKey)
|
||||
// {
|
||||
// var
|
||||
// mPgpMessageDecrypted = null,
|
||||
// mPgpMessage = null
|
||||
// ;
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// mPgpMessage = this.openpgp.message.readArmored(sEnctyptedText);
|
||||
// if (mPgpMessage && oPivateKey && mPgpMessage.decrypt)
|
||||
// {
|
||||
// mPgpMessageDecrypted = mPgpMessage.decrypt(oPivateKey);
|
||||
// if (mPgpMessageDecrypted)
|
||||
// {
|
||||
// mPgpMessageDecrypted.verify(aPublicKeys);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (oExc) {}
|
||||
//
|
||||
// return false;
|
||||
// };
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue