Code refactoring

This commit is contained in:
RainLoop Team 2015-02-03 03:58:58 +04:00
parent 79233ad83c
commit 286ab567af
53 changed files with 618 additions and 581 deletions

View file

@ -6,7 +6,9 @@
var
ko = require('ko'),
Settings = require('Storage/Settings')
Settings = require('Storage/Settings'),
AppStore = require('Stores/App')
;
/**
@ -14,10 +16,7 @@
*/
function AppAdminStore()
{
// same
this.allowLanguagesOnSettings = ko.observable(true);
this.allowLanguagesOnLogin = ko.observable(true);
// ----
AppStore.call(this);
this.determineUserLanguage = ko.observable(false);
this.determineUserDomain = ko.observable(false);
@ -28,8 +27,7 @@
AppAdminStore.prototype.populate = function()
{
this.allowLanguagesOnLogin(!!Settings.settingsGet('AllowLanguagesOnLogin'));
this.allowLanguagesOnSettings(!!Settings.settingsGet('AllowLanguagesOnSettings'));
AppStore.prototype.populate.call(this);
this.determineUserLanguage(!!Settings.settingsGet('DetermineUserLanguage'));
this.determineUserDomain(!!Settings.settingsGet('DetermineUserDomain'));

View file

@ -12,8 +12,8 @@
*/
function DomainAdminStore()
{
this.collection = ko.observableArray([]);
this.collection.loading = ko.observable(false).extend({'throttle': 100});
this.domains = ko.observableArray([]);
this.domains.loading = ko.observable(false).extend({'throttle': 100});
}
module.exports = new DomainAdminStore();

View file

@ -10,15 +10,15 @@
/**
* @constructor
*/
function PluginAdminStore()
function PackageAdminStore()
{
this.collection = ko.observableArray([]);
this.collection.loading = ko.observable(false).extend({'throttle': 100});
this.packages = ko.observableArray([]);
this.packages.loading = ko.observable(false).extend({'throttle': 100});
this.packagesReal = ko.observable(true);
this.packagesMainUpdatable = ko.observable(true);
}
module.exports = new PluginAdminStore();
module.exports = new PackageAdminStore();
}());

View file

@ -12,9 +12,9 @@
*/
function PluginAdminStore()
{
this.collection = ko.observableArray([]);
this.collection.loading = ko.observable(false).extend({'throttle': 100});
this.collection.error = ko.observable('');
this.plugins = ko.observableArray([]);
this.plugins.loading = ko.observable(false).extend({'throttle': 100});
this.plugins.error = ko.observable('');
}
module.exports = new PluginAdminStore();

42
dev/Stores/App.js Normal file
View file

@ -0,0 +1,42 @@
(function () {
'use strict';
var
ko = require('ko'),
Globals = require('Common/Globals'),
Settings = require('Storage/Settings')
;
/**
* @constructor
*/
function AppStore()
{
this.allowLanguagesOnSettings = ko.observable(true);
this.allowLanguagesOnLogin = ko.observable(true);
this.interfaceAnimation = ko.observable(true);
this.interfaceAnimation.subscribe(function (bValue) {
var bAnim = Globals.bMobileDevice || !bValue;
Globals.$html.toggleClass('rl-anim', !bAnim).toggleClass('no-rl-anim', bAnim);
});
this.interfaceAnimation.valueHasMutated();
}
AppStore.prototype.populate = function()
{
this.allowLanguagesOnLogin(!!Settings.settingsGet('AllowLanguagesOnLogin'));
this.allowLanguagesOnSettings(!!Settings.settingsGet('AllowLanguagesOnSettings'));
this.interfaceAnimation(!!Settings.settingsGet('InterfaceAnimation'));
};
module.exports = AppStore;
}());

View file

@ -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();
}());

View file

@ -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();

View file

@ -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
View 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();
}());

View file

@ -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}