es5 -> es2015 (last stage)

Signature plugin fixes
Add view decorator
A large number of fixes
This commit is contained in:
RainLoop Team 2016-08-17 01:01:20 +03:00
parent e88c193334
commit 17669b7be0
153 changed files with 21193 additions and 21115 deletions

View file

@ -11,9 +11,9 @@ class AbstractAppStore
this.interfaceAnimation = ko.observable(true);
this.interfaceAnimation.subscribe(function(bValue) {
const bAnim = bMobileDevice || !bValue;
$html.toggleClass('rl-anim', !bAnim).toggleClass('no-rl-anim', bAnim);
this.interfaceAnimation.subscribe((value) => {
const anim = bMobileDevice || !value;
$html.toggleClass('rl-anim', !anim).toggleClass('no-rl-anim', anim);
});
this.interfaceAnimation.valueHasMutated();

View file

@ -1,44 +1,39 @@
var
ko = require('ko'),
import ko from 'ko';
import {Capa} from 'Common/Enums';
import * as Settings from 'Storage/Settings';
Enums = require('Common/Enums'),
Settings = require('Storage/Settings');
/**
* @constructor
*/
function CapaAdminStore()
class CapaAdminStore
{
this.additionalAccounts = ko.observable(false);
this.identities = ko.observable(false);
this.gravatar = ko.observable(false);
this.attachmentThumbnails = ko.observable(false);
this.sieve = ko.observable(false);
this.filters = ko.observable(false);
this.themes = ko.observable(true);
this.userBackground = ko.observable(false);
this.openPGP = ko.observable(false);
this.twoFactorAuth = ko.observable(false);
this.twoFactorAuthForce = ko.observable(false);
this.templates = ko.observable(false);
constructor() {
this.additionalAccounts = ko.observable(false);
this.identities = ko.observable(false);
this.gravatar = ko.observable(false);
this.attachmentThumbnails = ko.observable(false);
this.sieve = ko.observable(false);
this.filters = ko.observable(false);
this.themes = ko.observable(true);
this.userBackground = ko.observable(false);
this.openPGP = ko.observable(false);
this.twoFactorAuth = ko.observable(false);
this.twoFactorAuthForce = ko.observable(false);
this.templates = ko.observable(false);
}
populate() {
this.additionalAccounts(Settings.capa(Capa.AdditionalAccounts));
this.identities(Settings.capa(Capa.Identities));
this.gravatar(Settings.capa(Capa.Gravatar));
this.attachmentThumbnails(Settings.capa(Capa.AttachmentThumbnails));
this.sieve(Settings.capa(Capa.Sieve));
this.filters(Settings.capa(Capa.Filters));
this.themes(Settings.capa(Capa.Themes));
this.userBackground(Settings.capa(Capa.UserBackground));
this.openPGP(Settings.capa(Capa.OpenPGP));
this.twoFactorAuth(Settings.capa(Capa.TwoFactor));
this.twoFactorAuthForce(Settings.capa(Capa.TwoFactorForce));
this.templates(Settings.capa(Capa.Templates));
}
}
CapaAdminStore.prototype.populate = function()
{
this.additionalAccounts(Settings.capa(Enums.Capa.AdditionalAccounts));
this.identities(Settings.capa(Enums.Capa.Identities));
this.gravatar(Settings.capa(Enums.Capa.Gravatar));
this.attachmentThumbnails(Settings.capa(Enums.Capa.AttachmentThumbnails));
this.sieve(Settings.capa(Enums.Capa.Sieve));
this.filters(Settings.capa(Enums.Capa.Filters));
this.themes(Settings.capa(Enums.Capa.Themes));
this.userBackground(Settings.capa(Enums.Capa.UserBackground));
this.openPGP(Settings.capa(Enums.Capa.OpenPGP));
this.twoFactorAuth(Settings.capa(Enums.Capa.TwoFactor));
this.twoFactorAuthForce(Settings.capa(Enums.Capa.TwoFactorForce));
this.templates(Settings.capa(Enums.Capa.Templates));
};
module.exports = new CapaAdminStore();

View file

@ -1,23 +1,22 @@
var ko = require('ko');
import ko from 'ko';
/**
* @constructor
*/
function CoreAdminStore()
class CoreAdminStore
{
this.coreReal = ko.observable(true);
this.coreChannel = ko.observable('stable');
this.coreType = ko.observable('stable');
this.coreUpdatable = ko.observable(true);
this.coreAccess = ko.observable(true);
this.coreWarning = ko.observable(false);
this.coreChecking = ko.observable(false).extend({'throttle': 100});
this.coreUpdating = ko.observable(false).extend({'throttle': 100});
this.coreVersion = ko.observable('');
this.coreRemoteVersion = ko.observable('');
this.coreRemoteRelease = ko.observable('');
this.coreVersionCompare = ko.observable(-2);
constructor() {
this.coreReal = ko.observable(true);
this.coreChannel = ko.observable('stable');
this.coreType = ko.observable('stable');
this.coreUpdatable = ko.observable(true);
this.coreAccess = ko.observable(true);
this.coreWarning = ko.observable(false);
this.coreChecking = ko.observable(false).extend({throttle: 100});
this.coreUpdating = ko.observable(false).extend({throttle: 100});
this.coreVersion = ko.observable('');
this.coreRemoteVersion = ko.observable('');
this.coreRemoteRelease = ko.observable('');
this.coreVersionCompare = ko.observable(-2);
}
}
module.exports = new CoreAdminStore();

View file

@ -1,17 +1,13 @@
var ko = require('ko');
import ko from 'ko';
/**
* @constructor
*/
function DomainAdminStore()
class DomainAdminStore
{
this.domains = ko.observableArray([]);
this.domains.loading = ko.observable(false).extend({'throttle': 100});
this.domainsWithoutAliases = this.domains.filter(function(oItem) {
return oItem && !oItem.alias;
});
constructor() {
this.domains = ko.observableArray([]);
this.domains.loading = ko.observable(false).extend({'throttle': 100});
this.domainsWithoutAliases = this.domains.filter((item) => item && !item.alias);
}
}
module.exports = new DomainAdminStore();

View file

@ -1,18 +1,17 @@
var ko = require('ko');
import ko from 'ko';
/**
* @constructor
*/
function LicenseAdminStore()
class LicenseAdminStore
{
this.licensing = ko.observable(false);
this.licensingProcess = ko.observable(false);
this.licenseValid = ko.observable(false);
this.licenseExpired = ko.observable(0);
this.licenseError = ko.observable('');
constructor() {
this.licensing = ko.observable(false);
this.licensingProcess = ko.observable(false);
this.licenseValid = ko.observable(false);
this.licenseExpired = ko.observable(0);
this.licenseError = ko.observable('');
this.licenseTrigger = ko.observable(false);
this.licenseTrigger = ko.observable(false);
}
}
module.exports = new LicenseAdminStore();

View file

@ -1,16 +1,15 @@
var ko = require('ko');
import ko from 'ko';
/**
* @constructor
*/
function PackageAdminStore()
class PackageAdminStore
{
this.packages = ko.observableArray([]);
this.packages.loading = ko.observable(false).extend({'throttle': 100});
constructor() {
this.packages = ko.observableArray([]);
this.packages.loading = ko.observable(false).extend({throttle: 100});
this.packagesReal = ko.observable(true);
this.packagesMainUpdatable = ko.observable(true);
this.packagesReal = ko.observable(true);
this.packagesMainUpdatable = ko.observable(true);
}
}
module.exports = new PackageAdminStore();

View file

@ -1,14 +1,13 @@
var ko = require('ko');
import ko from 'ko';
/**
* @constructor
*/
function PluginAdminStore()
class PluginAdminStore
{
this.plugins = ko.observableArray([]);
this.plugins.loading = ko.observable(false).extend({'throttle': 100});
this.plugins.error = ko.observable('');
constructor() {
this.plugins = ko.observableArray([]);
this.plugins.loading = ko.observable(false).extend({throttle: 100});
this.plugins.error = ko.observable('');
}
}
module.exports = new PluginAdminStore();

View file

@ -1,45 +1,40 @@
var
ko = require('ko'),
import ko from 'ko';
import {isArray} from 'Common/Utils';
import * as Settings from 'Storage/Settings';
Utils = require('Common/Utils'),
Settings = require('Storage/Settings');
/**
* @constructor
*/
function LanguageStore()
class LanguageStore
{
this.languages = ko.observableArray([]);
this.languagesAdmin = ko.observableArray([]);
constructor() {
this.languages = ko.observableArray([]);
this.languagesAdmin = ko.observableArray([]);
this.language = ko.observable('')
.extend({'limitedList': this.languages})
.extend({'reversible': true});
this.language = ko.observable('')
.extend({limitedList: this.languages})
.extend({reversible: true});
this.languageAdmin = ko.observable('')
.extend({'limitedList': this.languagesAdmin})
.extend({'reversible': true});
this.languageAdmin = ko.observable('')
.extend({limitedList: this.languagesAdmin})
.extend({reversible: true});
this.userLanguage = ko.observable('');
this.userLanguageAdmin = ko.observable('');
this.userLanguage = ko.observable('');
this.userLanguageAdmin = ko.observable('');
}
populate() {
const
aLanguages = Settings.appSettingsGet('languages'),
aLanguagesAdmin = Settings.appSettingsGet('languagesAdmin');
this.languages(isArray(aLanguages) ? aLanguages : []);
this.languagesAdmin(isArray(aLanguagesAdmin) ? aLanguagesAdmin : []);
this.language(Settings.settingsGet('Language'));
this.languageAdmin(Settings.settingsGet('LanguageAdmin'));
this.userLanguage(Settings.settingsGet('UserLanguage'));
this.userLanguageAdmin(Settings.settingsGet('UserLanguageAdmin'));
}
}
LanguageStore.prototype.populate = function()
{
var
aLanguages = Settings.appSettingsGet('languages'),
aLanguagesAdmin = Settings.appSettingsGet('languagesAdmin');
this.languages(Utils.isArray(aLanguages) ? aLanguages : []);
this.languagesAdmin(Utils.isArray(aLanguagesAdmin) ? aLanguagesAdmin : []);
this.language(Settings.settingsGet('Language'));
this.languageAdmin(Settings.settingsGet('LanguageAdmin'));
this.userLanguage(Settings.settingsGet('UserLanguage'));
this.userLanguageAdmin(Settings.settingsGet('UserLanguageAdmin'));
};
module.exports = new LanguageStore();

View file

@ -1,103 +1,103 @@
var ko = require('ko');
import window from 'window';
import ko from 'ko';
import $ from '$';
import * as Settings from 'Storage/Settings';
/**
* @constructor
*/
function SocialStore()
class SocialStore
{
this.google = {};
this.twitter = {};
this.facebook = {};
this.dropbox = {};
constructor() {
this.google = {};
this.twitter = {};
this.facebook = {};
this.dropbox = {};
// Google
this.google.enabled = ko.observable(false);
// Google
this.google.enabled = ko.observable(false);
this.google.clientID = ko.observable('');
this.google.clientSecret = ko.observable('');
this.google.apiKey = ko.observable('');
this.google.clientID = ko.observable('');
this.google.clientSecret = ko.observable('');
this.google.apiKey = ko.observable('');
this.google.loading = ko.observable(false);
this.google.userName = ko.observable('');
this.google.loading = ko.observable(false);
this.google.userName = ko.observable('');
this.google.loggined = ko.computed(function() {
return '' !== this.google.userName();
}, this);
this.google.loggined = ko.computed(() => '' !== this.google.userName());
this.google.capa = {};
this.google.capa.auth = ko.observable(false);
this.google.capa.authFast = ko.observable(false);
this.google.capa.drive = ko.observable(false);
this.google.capa.preview = ko.observable(false);
this.google.capa = {};
this.google.capa.auth = ko.observable(false);
this.google.capa.authFast = ko.observable(false);
this.google.capa.drive = ko.observable(false);
this.google.capa.preview = ko.observable(false);
this.google.require = {};
this.google.require.clientSettings = ko.computed(function() {
return this.google.enabled() && (this.google.capa.auth() || this.google.capa.drive());
}, this);
this.google.require = {};
this.google.require.clientSettings = ko.computed(
() => this.google.enabled() && (this.google.capa.auth() || this.google.capa.drive()));
this.google.require.apiKeySettings = ko.computed(function() {
return this.google.enabled() && this.google.capa.drive();
}, this);
this.google.require.apiKeySettings = ko.computed(() => this.google.enabled() && this.google.capa.drive());
// Facebook
this.facebook.enabled = ko.observable(false);
this.facebook.appID = ko.observable('');
this.facebook.appSecret = ko.observable('');
this.facebook.loading = ko.observable(false);
this.facebook.userName = ko.observable('');
this.facebook.supported = ko.observable(false);
// Facebook
this.facebook.enabled = ko.observable(false);
this.facebook.appID = ko.observable('');
this.facebook.appSecret = ko.observable('');
this.facebook.loading = ko.observable(false);
this.facebook.userName = ko.observable('');
this.facebook.supported = ko.observable(false);
this.facebook.loggined = ko.computed(function() {
return '' !== this.facebook.userName();
}, this);
this.facebook.loggined = ko.computed(() => '' !== this.facebook.userName());
// Twitter
this.twitter.enabled = ko.observable(false);
this.twitter.consumerKey = ko.observable('');
this.twitter.consumerSecret = ko.observable('');
this.twitter.loading = ko.observable(false);
this.twitter.userName = ko.observable('');
// Twitter
this.twitter.enabled = ko.observable(false);
this.twitter.consumerKey = ko.observable('');
this.twitter.consumerSecret = ko.observable('');
this.twitter.loading = ko.observable(false);
this.twitter.userName = ko.observable('');
this.twitter.loggined = ko.computed(function() {
return '' !== this.twitter.userName();
}, this);
this.twitter.loggined = ko.computed(() => '' !== this.twitter.userName());
// Dropbox
this.dropbox.enabled = ko.observable(false);
this.dropbox.apiKey = ko.observable('');
// Dropbox
this.dropbox.enabled = ko.observable(false);
this.dropbox.apiKey = ko.observable('');
}
populate() {
this.google.enabled(!!Settings.settingsGet('AllowGoogleSocial'));
this.google.clientID(Settings.settingsGet('GoogleClientID'));
this.google.clientSecret(Settings.settingsGet('GoogleClientSecret'));
this.google.apiKey(Settings.settingsGet('GoogleApiKey'));
this.google.capa.auth(!!Settings.settingsGet('AllowGoogleSocialAuth'));
this.google.capa.authFast(!!Settings.settingsGet('AllowGoogleSocialAuthFast'));
this.google.capa.drive(!!Settings.settingsGet('AllowGoogleSocialDrive'));
this.google.capa.preview(!!Settings.settingsGet('AllowGoogleSocialPreview'));
this.facebook.enabled(!!Settings.settingsGet('AllowFacebookSocial'));
this.facebook.appID(Settings.settingsGet('FacebookAppID'));
this.facebook.appSecret(Settings.settingsGet('FacebookAppSecret'));
this.facebook.supported(!!Settings.settingsGet('SupportedFacebookSocial'));
this.twitter.enabled = ko.observable(!!Settings.settingsGet('AllowTwitterSocial'));
this.twitter.consumerKey = ko.observable(Settings.settingsGet('TwitterConsumerKey'));
this.twitter.consumerSecret = ko.observable(Settings.settingsGet('TwitterConsumerSecret'));
this.dropbox.enabled(!!Settings.settingsGet('AllowDropboxSocial'));
this.dropbox.apiKey(Settings.settingsGet('DropboxApiKey'));
}
appendDropbox() {
if (!window.Dropbox && this.dropbox.enabled() && this.dropbox.apiKey())
{
if (!window.document.getElementById('dropboxjs'))
{
const script = window.document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://www.dropbox.com/static/api/2/dropins.js';
$(script).attr('id', 'dropboxjs').attr('data-app-key', this.dropbox.apiKey());
window.document.body.appendChild(script);
}
}
}
}
SocialStore.prototype.google = {};
SocialStore.prototype.twitter = {};
SocialStore.prototype.facebook = {};
SocialStore.prototype.dropbox = {};
SocialStore.prototype.populate = function()
{
var Settings = require('Storage/Settings');
this.google.enabled(!!Settings.settingsGet('AllowGoogleSocial'));
this.google.clientID(Settings.settingsGet('GoogleClientID'));
this.google.clientSecret(Settings.settingsGet('GoogleClientSecret'));
this.google.apiKey(Settings.settingsGet('GoogleApiKey'));
this.google.capa.auth(!!Settings.settingsGet('AllowGoogleSocialAuth'));
this.google.capa.authFast(!!Settings.settingsGet('AllowGoogleSocialAuthFast'));
this.google.capa.drive(!!Settings.settingsGet('AllowGoogleSocialDrive'));
this.google.capa.preview(!!Settings.settingsGet('AllowGoogleSocialPreview'));
this.facebook.enabled(!!Settings.settingsGet('AllowFacebookSocial'));
this.facebook.appID(Settings.settingsGet('FacebookAppID'));
this.facebook.appSecret(Settings.settingsGet('FacebookAppSecret'));
this.facebook.supported(!!Settings.settingsGet('SupportedFacebookSocial'));
this.twitter.enabled = ko.observable(!!Settings.settingsGet('AllowTwitterSocial'));
this.twitter.consumerKey = ko.observable(Settings.settingsGet('TwitterConsumerKey'));
this.twitter.consumerSecret = ko.observable(Settings.settingsGet('TwitterConsumerSecret'));
this.dropbox.enabled(!!Settings.settingsGet('AllowDropboxSocial'));
this.dropbox.apiKey(Settings.settingsGet('DropboxApiKey'));
};
module.exports = new SocialStore();

View file

@ -1,32 +1,26 @@
var
ko = require('ko'),
import ko from 'ko';
import {isArray} from 'Common/Utils';
import * as Settings from 'Storage/Settings';
Utils = require('Common/Utils'),
Settings = require('Storage/Settings');
/**
* @constructor
*/
function ThemeStore()
class ThemeStore
{
this.themes = ko.observableArray([]);
this.themeBackgroundName = ko.observable('');
this.themeBackgroundHash = ko.observable('');
constructor() {
this.themes = ko.observableArray([]);
this.themeBackgroundName = ko.observable('');
this.themeBackgroundHash = ko.observable('');
this.theme = ko.observable('')
.extend({'limitedList': this.themes});
this.theme = ko.observable('').extend({limitedList: this.themes});
}
populate() {
const themes = Settings.appSettingsGet('themes');
this.themes(isArray(themes) ? themes : []);
this.theme(Settings.settingsGet('Theme'));
this.themeBackgroundName(Settings.settingsGet('UserBackgroundName'));
this.themeBackgroundHash(Settings.settingsGet('UserBackgroundHash'));
}
}
ThemeStore.prototype.populate = function()
{
var aThemes = Settings.appSettingsGet('themes');
this.themes(Utils.isArray(aThemes) ? aThemes : []);
this.theme(Settings.settingsGet('Theme'));
this.themeBackgroundName(Settings.settingsGet('UserBackgroundName'));
this.themeBackgroundHash(Settings.settingsGet('UserBackgroundHash'));
};
module.exports = new ThemeStore();

View file

@ -1,64 +1,50 @@
var
_ = require('_'),
ko = require('ko'),
import ko from 'ko';
import _ from '_';
import * as Settings from 'Storage/Settings';
Settings = require('Storage/Settings');
/**
* @constructor
*/
function AccountUserStore()
class AccountUserStore
{
this.email = ko.observable('');
this.parentEmail = ko.observable('');
// this.incLogin = ko.observable('');
// this.outLogin = ko.observable('');
constructor() {
this.email = ko.observable('');
this.parentEmail = ko.observable('');
this.signature = ko.observable('');
this.signature = ko.observable('');
this.accounts = ko.observableArray([]);
this.accounts.loading = ko.observable(false).extend({'throttle': 100});
this.accounts = ko.observableArray([]);
this.accounts.loading = ko.observable(false).extend({throttle: 100});
this.computers();
}
this.computers();
}
AccountUserStore.prototype.computers = function()
{
this.accountsEmails = ko.computed(function() {
return _.compact(_.map(this.accounts(), function(oItem) {
return oItem ? oItem.email : null;
}));
}, this);
computers() {
this.accountsEmails = ko.computed(
() => _.compact(_.map(this.accounts(), (item) => (item ? item.email : null))));
this.accountsUnreadCount = ko.computed(function() {
var iResult = 0;
// _.each(this.accounts(), function(oItem) {
// if (oItem)
this.accountsUnreadCount = ko.computed(() => 0);
// this.accountsUnreadCount = ko.computed(() => {
// let result = 0;
// _.each(this.accounts(), (item) => {
// if (item)
// {
// iResult += oItem.count();
// result += item.count();
// }
// });
// return result;
// });
}
return iResult;
populate() {
this.email(Settings.settingsGet('Email'));
this.parentEmail(Settings.settingsGet('ParentEmail'));
}
}, this);
};
AccountUserStore.prototype.populate = function()
{
this.email(Settings.settingsGet('Email'));
this.parentEmail(Settings.settingsGet('ParentEmail'));
};
/**
* @returns {boolean}
*/
AccountUserStore.prototype.isRootAccount = function()
{
return '' === this.parentEmail();
};
/**
* @returns {boolean}
*/
isRootAccount() {
return '' === this.parentEmail();
}
}
module.exports = new AccountUserStore();

View file

@ -16,8 +16,7 @@ class AppUserStore extends AbstractAppStore
this.focusedState = ko.observable(Focused.None);
this.focusedState.subscribe(function(value) {
this.focusedState.subscribe((value) => {
switch (value)
{
case Focused.MessageList:
@ -32,8 +31,7 @@ class AppUserStore extends AbstractAppStore
default:
break;
}
}, this);
});
this.projectHash = ko.observable('');
this.threadsAllowed = ko.observable(false);

View file

@ -1,36 +1,32 @@
var
ko = require('ko'),
import ko from 'ko';
import * as Settings from 'Storage/Settings';
Settings = require('Storage/Settings');
/**
* @constructor
*/
function ContactUserStore()
class ContactUserStore
{
this.contacts = ko.observableArray([]);
this.contacts.loading = ko.observable(false).extend({'throttle': 200});
this.contacts.importing = ko.observable(false).extend({'throttle': 200});
this.contacts.syncing = ko.observable(false).extend({'throttle': 200});
this.contacts.exportingVcf = ko.observable(false).extend({'throttle': 200});
this.contacts.exportingCsv = ko.observable(false).extend({'throttle': 200});
constructor() {
this.contacts = ko.observableArray([]);
this.contacts.loading = ko.observable(false).extend({'throttle': 200});
this.contacts.importing = ko.observable(false).extend({'throttle': 200});
this.contacts.syncing = ko.observable(false).extend({'throttle': 200});
this.contacts.exportingVcf = ko.observable(false).extend({'throttle': 200});
this.contacts.exportingCsv = ko.observable(false).extend({'throttle': 200});
this.allowContactsSync = ko.observable(false);
this.enableContactsSync = ko.observable(false);
this.contactsSyncUrl = ko.observable('');
this.contactsSyncUser = ko.observable('');
this.contactsSyncPass = ko.observable('');
this.allowContactsSync = ko.observable(false);
this.enableContactsSync = ko.observable(false);
this.contactsSyncUrl = ko.observable('');
this.contactsSyncUser = ko.observable('');
this.contactsSyncPass = ko.observable('');
}
populate() {
this.allowContactsSync(!!Settings.settingsGet('ContactsSyncIsAllowed'));
this.enableContactsSync(!!Settings.settingsGet('EnableContactsSync'));
this.contactsSyncUrl(Settings.settingsGet('ContactsSyncUrl'));
this.contactsSyncUser(Settings.settingsGet('ContactsSyncUser'));
this.contactsSyncPass(Settings.settingsGet('ContactsSyncPassword'));
}
}
ContactUserStore.prototype.populate = function()
{
this.allowContactsSync(!!Settings.settingsGet('ContactsSyncIsAllowed'));
this.enableContactsSync(!!Settings.settingsGet('EnableContactsSync'));
this.contactsSyncUrl(Settings.settingsGet('ContactsSyncUrl'));
this.contactsSyncUser(Settings.settingsGet('ContactsSyncUser'));
this.contactsSyncPass(Settings.settingsGet('ContactsSyncPassword'));
};
module.exports = new ContactUserStore();

View file

@ -1,20 +1,19 @@
var ko = require('ko');
import ko from 'ko';
/**
* @constructor
*/
function FilterUserStore()
class FilterUserStore
{
this.capa = ko.observable('');
this.modules = ko.observable({});
constructor() {
this.capa = ko.observable('');
this.modules = ko.observable({});
this.filters = ko.observableArray([]);
this.filters = ko.observableArray([]);
this.filters.loading = ko.observable(false).extend({throttle: 200});
this.filters.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('');
this.raw = ko.observable('');
}
}
module.exports = new FilterUserStore();

View file

@ -1,247 +1,223 @@
var
_ = require('_'),
ko = require('ko'),
import ko from 'ko';
import _ from '_';
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils'),
import {FolderType} from 'Common/Enums';
import {UNUSED_OPTION_VALUE} from 'Common/Consts';
import {isArray, folderListOptionsBuilder} from 'Common/Utils';
import {getFolderInboxName, getFolderFromCacheList} from 'Common/Cache';
Cache = require('Common/Cache');
/**
* @constructor
*/
function FolderUserStore()
class FolderUserStore
{
this.displaySpecSetting = ko.observable(true);
constructor() {
this.displaySpecSetting = ko.observable(true);
this.sentFolder = ko.observable('');
this.draftFolder = ko.observable('');
this.spamFolder = ko.observable('');
this.trashFolder = ko.observable('');
this.archiveFolder = ko.observable('');
this.sentFolder = ko.observable('');
this.draftFolder = ko.observable('');
this.spamFolder = ko.observable('');
this.trashFolder = ko.observable('');
this.archiveFolder = ko.observable('');
this.namespace = '';
this.namespace = '';
this.folderList = ko.observableArray([]);
this.folderList.optimized = ko.observable(false);
this.folderList.error = ko.observable('');
this.folderList = ko.observableArray([]);
this.folderList.optimized = ko.observable(false);
this.folderList.error = ko.observable('');
this.foldersLoading = ko.observable(false);
this.foldersCreating = ko.observable(false);
this.foldersDeleting = ko.observable(false);
this.foldersRenaming = ko.observable(false);
this.foldersLoading = ko.observable(false);
this.foldersCreating = ko.observable(false);
this.foldersDeleting = ko.observable(false);
this.foldersRenaming = ko.observable(false);
this.foldersInboxUnreadCount = ko.observable(0);
this.foldersInboxUnreadCount = ko.observable(0);
this.currentFolder = ko.observable(null).extend({toggleSubscribe: [
null,
function(oPrev) {
if (oPrev) {
oPrev.selected(false);
this.currentFolder = ko.observable(null).extend({toggleSubscribe: [
null,
(prev) => {
if (prev) {
prev.selected(false);
}
},
(next) => {
if (next) {
next.selected(true);
}
}
},
function(oNext) {
if (oNext) {
oNext.selected(true);
}
}
]});
]});
this.computers();
this.subscribers();
this.computers();
this.subscribers();
}
computers() {
this.draftFolderNotEnabled = ko.computed(
() => ('' === this.draftFolder() || UNUSED_OPTION_VALUE === this.draftFolder())
);
this.foldersListWithSingleInboxRootFolder = ko.computed(
() => !_.find(this.folderList(), (folder) => (folder && !folder.isSystemFolder() && folder.visible()))
);
this.currentFolderFullNameRaw = ko.computed(
() => (this.currentFolder() ? this.currentFolder().fullNameRaw : '')
);
this.currentFolderFullName = ko.computed(() => (this.currentFolder() ? this.currentFolder().fullName : ''));
this.currentFolderFullNameHash = ko.computed(() => (this.currentFolder() ? this.currentFolder().fullNameHash : ''));
this.foldersChanging = ko.computed(() => {
const
loading = this.foldersLoading(),
creating = this.foldersCreating(),
deleting = this.foldersDeleting(),
renaming = this.foldersRenaming();
return loading || creating || deleting || renaming;
});
this.folderListSystemNames = ko.computed(() => {
const
list = [getFolderInboxName()],
folders = this.folderList(),
sentFolder = this.sentFolder(),
draftFolder = this.draftFolder(),
spamFolder = this.spamFolder(),
trashFolder = this.trashFolder(),
archiveFolder = this.archiveFolder();
if (isArray(folders) && 0 < folders.length)
{
if ('' !== sentFolder && UNUSED_OPTION_VALUE !== sentFolder)
{
list.push(sentFolder);
}
if ('' !== draftFolder && UNUSED_OPTION_VALUE !== draftFolder)
{
list.push(draftFolder);
}
if ('' !== spamFolder && UNUSED_OPTION_VALUE !== spamFolder)
{
list.push(spamFolder);
}
if ('' !== trashFolder && UNUSED_OPTION_VALUE !== trashFolder)
{
list.push(trashFolder);
}
if ('' !== archiveFolder && UNUSED_OPTION_VALUE !== archiveFolder)
{
list.push(archiveFolder);
}
}
return list;
});
this.folderListSystem = ko.computed(
() => _.compact(_.map(this.folderListSystemNames(), (name) => getFolderFromCacheList(name)))
);
this.folderMenuForMove = ko.computed(
() => folderListOptionsBuilder(
this.folderListSystem(), this.folderList(),
[this.currentFolderFullNameRaw()], null, null, null, null, (item) => (item ? item.localName() : ''))
);
this.folderMenuForFilters = ko.computed(
() => folderListOptionsBuilder(
this.folderListSystem(), this.folderList(),
['INBOX'], [['', '']], null, null, null, (item) => (item ? item.localName() : ''))
);
}
subscribers() {
const
fRemoveSystemFolderType = (observable) => () => {
const folder = getFolderFromCacheList(observable());
if (folder)
{
folder.type(FolderType.User);
}
},
fSetSystemFolderType = (type) => (value) => {
const folder = getFolderFromCacheList(value);
if (folder)
{
folder.type(type);
}
};
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(FolderType.SentItems), this);
this.draftFolder.subscribe(fSetSystemFolderType(FolderType.Draft), this);
this.spamFolder.subscribe(fSetSystemFolderType(FolderType.Spam), this);
this.trashFolder.subscribe(fSetSystemFolderType(FolderType.Trash), this);
this.archiveFolder.subscribe(fSetSystemFolderType(FolderType.Archive), this);
}
/**
* @returns {Array}
*/
getNextFolderNames() {
const
result = [],
limit = 5,
utc = require('Common/Momentor').momentNowUnix(),
timeout = utc - 60 * 5,
timeouts = [],
inboxFolderName = getFolderInboxName(),
fSearchFunction = (list) => {
_.each(list, (folder) => {
if (folder && inboxFolderName !== folder.fullNameRaw &&
folder.selectable && folder.existen && timeout > folder.interval &&
(folder.isSystemFolder() || (folder.subScribed() && folder.checkable()))
)
{
timeouts.push([folder.interval, folder.fullNameRaw]);
}
if (folder && 0 < folder.subFolders().length)
{
fSearchFunction(folder.subFolders());
}
});
};
fSearchFunction(this.folderList());
timeouts.sort((a, b) => {
if (a[0] < b[0])
{
return -1;
}
else if (a[0] > b[0])
{
return 1;
}
return 0;
});
_.find(timeouts, (aItem) => {
const folder = getFolderFromCacheList(aItem[1]);
if (folder)
{
folder.interval = utc;
result.push(aItem[1]);
}
return limit <= result.length;
});
return _.uniq(result);
}
}
FolderUserStore.prototype.computers = function()
{
this.draftFolderNotEnabled = ko.computed(function() {
return '' === this.draftFolder() || Consts.UNUSED_OPTION_VALUE === this.draftFolder();
}, this);
this.foldersListWithSingleInboxRootFolder = ko.computed(function() {
return !_.find(this.folderList(), function(oFolder) {
return oFolder && !oFolder.isSystemFolder() && oFolder.visible();
});
}, this);
this.currentFolderFullNameRaw = ko.computed(function() {
return this.currentFolder() ? this.currentFolder().fullNameRaw : '';
}, this);
this.currentFolderFullName = ko.computed(function() {
return this.currentFolder() ? this.currentFolder().fullName : '';
}, this);
this.currentFolderFullNameHash = ko.computed(function() {
return this.currentFolder() ? this.currentFolder().fullNameHash : '';
}, this);
this.foldersChanging = ko.computed(function() {
var
bLoading = this.foldersLoading(),
bCreating = this.foldersCreating(),
bDeleting = this.foldersDeleting(),
bRenaming = this.foldersRenaming();
return bLoading || bCreating || bDeleting || bRenaming;
}, this);
this.folderListSystemNames = ko.computed(function() {
var
aList = [Cache.getFolderInboxName()],
aFolders = this.folderList(),
sSentFolder = this.sentFolder(),
sDraftFolder = this.draftFolder(),
sSpamFolder = this.spamFolder(),
sTrashFolder = this.trashFolder(),
sArchiveFolder = this.archiveFolder();
if (Utils.isArray(aFolders) && 0 < aFolders.length)
{
if ('' !== sSentFolder && Consts.UNUSED_OPTION_VALUE !== sSentFolder)
{
aList.push(sSentFolder);
}
if ('' !== sDraftFolder && Consts.UNUSED_OPTION_VALUE !== sDraftFolder)
{
aList.push(sDraftFolder);
}
if ('' !== sSpamFolder && Consts.UNUSED_OPTION_VALUE !== sSpamFolder)
{
aList.push(sSpamFolder);
}
if ('' !== sTrashFolder && Consts.UNUSED_OPTION_VALUE !== sTrashFolder)
{
aList.push(sTrashFolder);
}
if ('' !== sArchiveFolder && Consts.UNUSED_OPTION_VALUE !== sArchiveFolder)
{
aList.push(sArchiveFolder);
}
}
return aList;
}, this);
this.folderListSystem = ko.computed(function() {
return _.compact(_.map(this.folderListSystemNames(), function(sName) {
return Cache.getFolderFromCacheList(sName);
}));
}, this);
this.folderMenuForMove = ko.computed(function() {
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(), [
this.currentFolderFullNameRaw()
], null, null, null, null, function(oItem) {
return oItem ? oItem.localName() : '';
});
}, this);
this.folderMenuForFilters = ko.computed(function() {
return Utils.folderListOptionsBuilder(this.folderListSystem(), this.folderList(),
['INBOX'], [['', '']], null, null, null, function(oItem) {
return oItem ? oItem.localName() : '';
}
);
}, this);
};
FolderUserStore.prototype.subscribers = 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);
};
/**
* @returns {Array}
*/
FolderUserStore.prototype.getNextFolderNames = function()
{
var
aResult = [],
iLimit = 5,
iUtc = require('Common/Momentor').momentNowUnix(),
iTimeout = iUtc - 60 * 5,
aTimeouts = [],
sInboxFolderName = Cache.getFolderInboxName(),
fSearchFunction = function(aList) {
_.each(aList, function(oFolder) {
if (oFolder && sInboxFolderName !== oFolder.fullNameRaw &&
oFolder.selectable && oFolder.existen &&
iTimeout > oFolder.interval &&
(oFolder.isSystemFolder() || (oFolder.subScribed() && oFolder.checkable()))
)
{
aTimeouts.push([oFolder.interval, oFolder.fullNameRaw]);
}
if (oFolder && 0 < oFolder.subFolders().length)
{
fSearchFunction(oFolder.subFolders());
}
});
};
fSearchFunction(this.folderList());
aTimeouts.sort(function(a, b) {
if (a[0] < b[0])
{
return -1;
}
else if (a[0] > b[0])
{
return 1;
}
return 0;
});
_.find(aTimeouts, function(aItem) {
var oFolder = Cache.getFolderFromCacheList(aItem[1]);
if (oFolder)
{
oFolder.interval = iUtc;
aResult.push(aItem[1]);
}
return iLimit <= aResult.length;
});
aResult = _.uniq(aResult);
return aResult;
};
module.exports = new FolderUserStore();

View file

@ -8,7 +8,8 @@ class IdentityUserStore
this.identities = ko.observableArray([]);
this.identities.loading = ko.observable(false).extend({throttle: 100});
this.identitiesIDS = ko.computed(() => _.compact(_.map(this.identities(), (item) => (item ? item.id : null))));
this.identitiesIDS = ko.computed(
() => _.compact(_.map(this.identities(), (item) => (item ? item.id : null))));
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,220 +1,207 @@
var
window = require('window'),
ko = require('ko'),
import window from 'window';
import ko from 'ko';
Enums = require('Common/Enums'),
Events = require('Common/Events'),
Audio = require('Common/Audio'),
import {DesktopNotification, Magics} from 'Common/Enums';
import * as Events from 'Common/Events';
import Audio from 'Common/Audio';
Settings = require('Storage/Settings');
import * as Settings from 'Storage/Settings';
/**
* @constructor
*/
function NotificationUserStore()
class NotificationUserStore
{
var self = this;
constructor() {
this.enableSoundNotification = ko.observable(false);
this.soundNotificationIsSupported = ko.observable(false);
this.enableSoundNotification = ko.observable(false);
this.soundNotificationIsSupported = ko.observable(false);
this.allowDesktopNotification = ko.observable(false);
this.allowDesktopNotification = ko.observable(false);
this.desktopNotificationPermissions = ko.computed(() => {
this.desktopNotificationPermissions = ko.computed(function() {
this.allowDesktopNotification();
this.allowDesktopNotification();
let result = DesktopNotification.NotSupported;
var
NotificationClass = this.notificationClass(),
iResult = Enums.DesktopNotification.NotSupported;
if (NotificationClass && NotificationClass.permission)
{
switch (NotificationClass.permission.toLowerCase())
const NotificationClass = this.notificationClass();
if (NotificationClass && NotificationClass.permission)
{
case 'granted':
iResult = Enums.DesktopNotification.Allowed;
break;
case 'denied':
iResult = Enums.DesktopNotification.Denied;
break;
case 'default':
iResult = Enums.DesktopNotification.NotAllowed;
break;
// no default
}
}
else if (window.webkitNotifications && window.webkitNotifications.checkPermission)
{
iResult = window.webkitNotifications.checkPermission();
}
return iResult;
}, this).extend({'notify': 'always'});
this.enableDesktopNotification = ko.computed({
'owner': this,
'read': function() {
return this.allowDesktopNotification() &&
Enums.DesktopNotification.Allowed === this.desktopNotificationPermissions();
},
'write': function(bValue) {
if (bValue)
{
var
NotificationClass = this.notificationClass(),
iPermission = this.desktopNotificationPermissions();
if (NotificationClass && Enums.DesktopNotification.Allowed === iPermission)
switch (NotificationClass.permission.toLowerCase())
{
this.allowDesktopNotification(true);
case 'granted':
result = DesktopNotification.Allowed;
break;
case 'denied':
result = DesktopNotification.Denied;
break;
case 'default':
result = DesktopNotification.NotAllowed;
break;
// no default
}
else if (NotificationClass && Enums.DesktopNotification.NotAllowed === iPermission)
}
else if (window.webkitNotifications && window.webkitNotifications.checkPermission)
{
result = window.webkitNotifications.checkPermission();
}
return result;
}).extend({notify: 'always'});
this.enableDesktopNotification = ko.computed({
read: () => this.allowDesktopNotification() && DesktopNotification.Allowed === this.desktopNotificationPermissions(),
write: (value) => {
if (value)
{
NotificationClass.requestPermission(function() {
self.allowDesktopNotification.valueHasMutated();
if (Enums.DesktopNotification.Allowed === self.desktopNotificationPermissions())
{
if (self.allowDesktopNotification())
const
NotificationClass = this.notificationClass(),
permission = this.desktopNotificationPermissions();
if (NotificationClass && DesktopNotification.Allowed === permission)
{
this.allowDesktopNotification(true);
}
else if (NotificationClass && DesktopNotification.NotAllowed === permission)
{
NotificationClass.requestPermission(() => {
this.allowDesktopNotification.valueHasMutated();
if (DesktopNotification.Allowed === this.desktopNotificationPermissions())
{
self.allowDesktopNotification.valueHasMutated();
if (this.allowDesktopNotification())
{
this.allowDesktopNotification.valueHasMutated();
}
else
{
this.allowDesktopNotification(true);
}
}
else
{
self.allowDesktopNotification(true);
if (this.allowDesktopNotification())
{
this.allowDesktopNotification(false);
}
else
{
this.allowDesktopNotification.valueHasMutated();
}
}
}
else
{
if (self.allowDesktopNotification())
{
self.allowDesktopNotification(false);
}
else
{
self.allowDesktopNotification.valueHasMutated();
}
}
});
});
}
else
{
this.allowDesktopNotification(false);
}
}
else
{
this.allowDesktopNotification(false);
}
}
else
{
this.allowDesktopNotification(false);
}
}
}).extend({'notify': 'always'});
}).extend({notify: 'always'});
if (!this.enableDesktopNotification.valueHasMutated)
{
this.enableDesktopNotification.valueHasMutated = function() {
self.allowDesktopNotification.valueHasMutated();
};
if (!this.enableDesktopNotification.valueHasMutated)
{
this.enableDesktopNotification.valueHasMutated = () => {
this.allowDesktopNotification.valueHasMutated();
};
}
this.computers();
this.initNotificationPlayer();
}
this.computers();
computers() {
this.isDesktopNotificationSupported = ko.computed(
() => DesktopNotification.NotSupported !== this.desktopNotificationPermissions()
);
this.initNotificationPlayer();
this.isDesktopNotificationDenied = ko.computed(
() => DesktopNotification.NotSupported === this.desktopNotificationPermissions() ||
DesktopNotification.Denied === this.desktopNotificationPermissions()
);
}
initNotificationPlayer() {
if (Audio && Audio.supportedNotification)
{
this.soundNotificationIsSupported(true);
}
else
{
this.enableSoundNotification(false);
this.soundNotificationIsSupported(false);
}
}
playSoundNotification(skipSetting) {
if (Audio && Audio.supportedNotification && (skipSetting ? true : this.enableSoundNotification()))
{
Audio.playNotification();
}
}
displayDesktopNotification(imageSrc, title, text, nessageData) {
if (this.enableDesktopNotification())
{
const
NotificationClass = this.notificationClass(),
notification = NotificationClass ? new NotificationClass(title, {
body: text,
icon: imageSrc
}) : null;
if (notification)
{
if (notification.show)
{
notification.show();
}
if (nessageData)
{
notification.onclick = () => {
window.focus();
if (nessageData.Folder && nessageData.Uid)
{
Events.pub('mailbox.message.show', [nessageData.Folder, nessageData.Uid]);
}
};
}
window.setTimeout((function(localNotifications) {
return () => {
if (localNotifications.cancel)
{
localNotifications.cancel();
}
else if (localNotifications.close)
{
localNotifications.close();
}
};
}(notification)), Magics.Time7s);
}
}
}
populate() {
this.enableSoundNotification(!!Settings.settingsGet('SoundNotification'));
this.enableDesktopNotification(!!Settings.settingsGet('DesktopNotifications'));
}
/**
* @returns {*|null}
*/
notificationClass() {
return window.Notification && window.Notification.requestPermission ? window.Notification : null;
}
}
NotificationUserStore.prototype.computers = function()
{
this.isDesktopNotificationSupported = ko.computed(function() {
return Enums.DesktopNotification.NotSupported !== this.desktopNotificationPermissions();
}, this);
this.isDesktopNotificationDenied = ko.computed(function() {
return Enums.DesktopNotification.NotSupported === this.desktopNotificationPermissions() ||
Enums.DesktopNotification.Denied === this.desktopNotificationPermissions();
}, this);
};
NotificationUserStore.prototype.initNotificationPlayer = function()
{
if (Audio && Audio.supportedNotification)
{
this.soundNotificationIsSupported(true);
}
else
{
this.enableSoundNotification(false);
this.soundNotificationIsSupported(false);
}
};
NotificationUserStore.prototype.playSoundNotification = function(bSkipSetting)
{
if (Audio && Audio.supportedNotification && (bSkipSetting ? true : this.enableSoundNotification()))
{
Audio.playNotification();
}
};
NotificationUserStore.prototype.displayDesktopNotification = function(sImageSrc, sTitle, sText, oMessageData)
{
if (this.enableDesktopNotification())
{
var
NotificationClass = this.notificationClass(),
oNotification = NotificationClass ? new NotificationClass(sTitle, {
'body': sText,
'icon': sImageSrc
}) : null;
if (oNotification)
{
if (oNotification.show)
{
oNotification.show();
}
if (oMessageData)
{
oNotification.onclick = function() {
window.focus();
if (oMessageData.Folder && oMessageData.Uid)
{
Events.pub('mailbox.message.show', [oMessageData.Folder, oMessageData.Uid]);
}
};
}
window.setTimeout((function(oLocalNotifications) {
return function() {
if (oLocalNotifications.cancel)
{
oLocalNotifications.cancel();
}
else if (oLocalNotifications.close)
{
oLocalNotifications.close();
}
};
}(oNotification)), Enums.Magics.Time7s);
}
}
};
NotificationUserStore.prototype.populate = function()
{
this.enableSoundNotification(!!Settings.settingsGet('SoundNotification'));
this.enableDesktopNotification(!!Settings.settingsGet('DesktopNotifications'));
};
/**
* @returns {*|null}
*/
NotificationUserStore.prototype.notificationClass = function()
{
return window.Notification && window.Notification.requestPermission ? window.Notification : null;
};
module.exports = new NotificationUserStore();

View file

@ -1,485 +1,403 @@
var
_ = require('_'),
ko = require('ko'),
$ = require('$'),
kn = require('Knoin/Knoin'),
import ko from 'ko';
import _ from '_';
import $ from '$';
Translator = require('Common/Translator'),
Settings = require('Storage/Settings'),
import {showScreenPopup} from 'Knoin/Knoin';
Utils = require('Common/Utils');
import {i18n} from 'Common/Translator';
import {log, isArray, isNonEmptyArray, pString, isUnd, trim} from 'Common/Utils';
/**
* @constructor
*/
function PgpUserStore()
class PgpUserStore
{
this.capaOpenPGP = ko.observable(false);
constructor() {
this.capaOpenPGP = ko.observable(false);
this.openpgp = null;
this.openpgp = null;
this.openpgpkeys = ko.observableArray([]);
this.openpgpKeyring = null;
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);
});
}
/**
* @returns {boolean}
*/
PgpUserStore.prototype.isSupported = function()
{
return !!this.openpgp;
};
PgpUserStore.prototype.findKeyByHex = function(aKeys, sHash)
{
return _.find(aKeys, function(oItem) {
return sHash && oItem && (sHash === oItem.id || -1 < oItem.ids.indexOf(sHash));
});
};
PgpUserStore.prototype.findPublicKeyByHex = function(sHash)
{
return this.findKeyByHex(this.openpgpkeysPublic(), sHash);
};
PgpUserStore.prototype.findPrivateKeyByHex = function(sHash)
{
return this.findKeyByHex(this.openpgpkeysPrivate(), sHash);
};
PgpUserStore.prototype.findPublicKeysByEmail = function(sEmail)
{
return _.compact(_.flatten(_.map(this.openpgpkeysPublic(), function(oItem) {
var oKey = oItem && -1 < oItem.emails.indexOf(sEmail) ? oItem : null;
return oKey ? oKey.getNativeKeys() : [null];
}), true));
};
PgpUserStore.prototype.findPublicKeysBySigningKeyIds = function(aSigningKeyIds)
{
var self = this;
return _.compact(_.flatten(_.map(aSigningKeyIds, function(oId) {
var oKey = oId && oId.toHex ? self.findPublicKeyByHex(oId.toHex()) : null;
return oKey ? oKey.getNativeKeys() : [null];
}), true));
};
PgpUserStore.prototype.findPrivateKeysByEncryptionKeyIds = function(aEncryptionKeyIds, aRecipients, bReturnWrapKeys)
{
var
self = this,
aResult = Utils.isArray(aEncryptionKeyIds) ? _.compact(_.flatten(_.map(aEncryptionKeyIds, function(oId) {
var oKey = oId && oId.toHex ? self.findPrivateKeyByHex(oId.toHex()) : null;
return oKey ? (bReturnWrapKeys ? [oKey] : oKey.getNativeKeys()) : [null];
}), true)) : [];
if (0 === aResult.length && Utils.isNonEmptyArray(aRecipients))
{
aResult = _.uniq(_.compact(_.flatten(_.map(aRecipients, function(sEmail) {
var aKeys = sEmail ? self.findAllPrivateKeysByEmailNotNative(sEmail) : null;
return aKeys ? (bReturnWrapKeys ? aKeys : _.flatten(_.map(aKeys, function(oKey) {
return oKey.getNativeKeys();
}), true)) : [null];
}), true)), function(oKey) {return oKey.id;});
this.openpgpkeysPublic = this.openpgpkeys.filter((item) => !!(item && !item.isPrivate));
this.openpgpkeysPrivate = this.openpgpkeys.filter((item) => !!(item && item.isPrivate));
}
return aResult;
};
/**
* @returns {boolean}
*/
isSupported() {
return !!this.openpgp;
}
/**
* @param {string} sEmail
* @returns {?}
*/
PgpUserStore.prototype.findPublicKeyByEmailNotNative = function(sEmail)
{
return _.find(this.openpgpkeysPublic(), function(oItem) {
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
findKeyByHex(keys, hash) {
return _.find(keys, (item) => (hash && item && (hash === item.id || -1 < item.ids.indexOf(hash))));
}
/**
* @param {string} sEmail
* @returns {?}
*/
PgpUserStore.prototype.findPrivateKeyByEmailNotNative = function(sEmail)
{
return _.find(this.openpgpkeysPrivate(), function(oItem) {
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
findPublicKeyByHex(hash) {
return this.findKeyByHex(this.openpgpkeysPublic(), hash);
}
/**
* @param {string} sEmail
* @returns {?}
*/
PgpUserStore.prototype.findAllPublicKeysByEmailNotNative = function(sEmail)
{
return _.filter(this.openpgpkeysPublic(), function(oItem) {
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
findPrivateKeyByHex(hash) {
return this.findKeyByHex(this.openpgpkeysPrivate(), hash);
}
/**
* @param {string} sEmail
* @returns {?}
*/
PgpUserStore.prototype.findAllPrivateKeysByEmailNotNative = function(sEmail)
{
return _.filter(this.openpgpkeysPrivate(), function(oItem) {
return oItem && -1 < oItem.emails.indexOf(sEmail);
}) || null;
};
findPublicKeysByEmail(email) {
return _.compact(_.flatten(_.map(this.openpgpkeysPublic(), (item) => {
const key = item && -1 < item.emails.indexOf(email) ? item : null;
return key ? key.getNativeKeys() : [null];
}), true));
}
/**
* @param {string} sEmail
* @param {string=} sPassword
* @returns {?}
*/
PgpUserStore.prototype.findPrivateKeyByEmail = function(sEmail, sPassword)
{
var
oPrivateKey = null,
oKey = _.find(this.openpgpkeysPrivate(), function(oItem) {
return oItem && -1 < oItem.emails.indexOf(sEmail);
});
findPublicKeysBySigningKeyIds(signingKeyIds) {
return _.compact(_.flatten(_.map(signingKeyIds, (id) => {
const key = id && id.toHex ? this.findPublicKeyByHex(id.toHex()) : null;
return key ? key.getNativeKeys() : [null];
}), true));
}
if (oKey)
{
try
findPrivateKeysByEncryptionKeyIds(encryptionKeyIds, recipients, returnWrapKeys) {
let
result = isArray(encryptionKeyIds) ? _.compact(_.flatten(_.map(encryptionKeyIds, (id) => {
const key = id && id.toHex ? this.findPrivateKeyByHex(id.toHex()) : null;
return key ? (returnWrapKeys ? [key] : key.getNativeKeys()) : [null];
}), true)) : [];
if (0 === result.length && isNonEmptyArray(recipients))
{
oPrivateKey = oKey.getNativeKeys()[0] || null;
if (oPrivateKey)
result = _.uniq(_.compact(_.flatten(_.map(recipients, (sEmail) => {
const keys = sEmail ? this.findAllPrivateKeysByEmailNotNative(sEmail) : null;
return keys ? (returnWrapKeys ? keys : _.flatten(_.map(keys, (key) => key.getNativeKeys()), true)) : [null];
}), true)), (key) => key.id);
}
return result;
}
/**
* @param {string} email
* @returns {?}
*/
findPublicKeyByEmailNotNative(email) {
return _.find(this.openpgpkeysPublic(), (item) => (item && -1 < item.emails.indexOf(email))) || null;
}
/**
* @param {string} email
* @returns {?}
*/
findPrivateKeyByEmailNotNative(email) {
return _.find(this.openpgpkeysPrivate(), (item) => (item && -1 < item.emails.indexOf(email))) || null;
}
/**
* @param {string} email
* @returns {?}
*/
findAllPublicKeysByEmailNotNative(email) {
return _.filter(this.openpgpkeysPublic(), (item) => (item && -1 < item.emails.indexOf(email))) || null;
}
/**
* @param {string} email
* @returns {?}
*/
findAllPrivateKeysByEmailNotNative(email) {
return _.filter(this.openpgpkeysPrivate(), (item) => (item && -1 < item.emails.indexOf(email))) || null;
}
/**
* @param {string} email
* @param {string=} password
* @returns {?}
*/
findPrivateKeyByEmail(email, password) {
let privateKey = null;
const key = _.find(this.openpgpkeysPrivate(), (item) => (item && -1 < item.emails.indexOf(email)));
if (key)
{
try
{
oPrivateKey.decrypt(Utils.pString(sPassword));
privateKey = key.getNativeKeys()[0] || null;
if (privateKey)
{
privateKey.decrypt(pString(password));
}
}
catch (e)
{
privateKey = null;
}
}
catch (e)
{
oPrivateKey = null;
}
return privateKey;
}
return oPrivateKey;
};
/**
* @param {string=} password
* @returns {?}
*/
findSelfPrivateKey(password) {
return this.findPrivateKeyByEmail(require('Stores/User/Account').email(), password);
}
/**
* @param {string=} sPassword
* @returns {?}
*/
PgpUserStore.prototype.findSelfPrivateKey = function(sPassword)
{
return this.findPrivateKeyByEmail(require('Stores/User/Account').email(), sPassword);
};
PgpUserStore.prototype.decryptMessage = function(oMessage, aRecipients, fCallback)
{
if (oMessage && oMessage.getEncryptionKeyIds)
{
var self = this,
aPrivateKeys = this.findPrivateKeysByEncryptionKeyIds(oMessage.getEncryptionKeyIds(), aRecipients, true);
if (aPrivateKeys && 0 < aPrivateKeys.length)
decryptMessage(message, recipients, fCallback) {
if (message && message.getEncryptionKeyIds)
{
kn.showScreenPopup(require('View/Popup/MessageOpenPgp'), [function(oDecryptedKey) {
const privateKeys = this.findPrivateKeysByEncryptionKeyIds(message.getEncryptionKeyIds(), recipients, true);
if (privateKeys && 0 < privateKeys.length)
{
showScreenPopup(require('View/Popup/MessageOpenPgp'), [(decryptedKey) => {
if (oDecryptedKey)
{
oMessage.decrypt(oDecryptedKey).then(function(oDecryptedMessage) {
var oPrivateKey = null;
if (oDecryptedMessage)
{
oPrivateKey = self.findPrivateKeyByHex(oDecryptedKey.primaryKey.keyid.toHex());
if (oPrivateKey)
if (decryptedKey)
{
message.decrypt(decryptedKey).then((decryptedMessage) => {
let privateKey = null;
if (decryptedMessage)
{
self.verifyMessage(oDecryptedMessage, function(oValidKey, aSigningKeyIds) {
fCallback(oPrivateKey, oDecryptedMessage, oValidKey || null, aSigningKeyIds || null);
});
privateKey = this.findPrivateKeyByHex(decryptedKey.primaryKey.keyid.toHex());
if (privateKey)
{
this.verifyMessage(decryptedMessage, (oValidKey, aSigningKeyIds) => {
fCallback(privateKey, decryptedMessage, oValidKey || null, aSigningKeyIds || null);
});
}
else
{
fCallback(privateKey, decryptedMessage);
}
}
else
{
fCallback(oPrivateKey, oDecryptedMessage);
fCallback(privateKey, decryptedMessage);
}
}
else
{
fCallback(oPrivateKey, oDecryptedMessage);
}
}, function() {
fCallback(null, null);
});
}
else
{
fCallback(null, null);
}
}, aPrivateKeys]);
return false;
}
}
fCallback(null, null);
return false;
};
PgpUserStore.prototype.findKeyExternal = function(sEmail, fCallback)
{
if (this.openpgp.HKP && Settings.appSettingsGet('openpgpPublicKeyServer'))
{
var oHkp = new this.openpgp.HKP(Settings.appSettingsGet('openpgpPublicKeyServer').replace(/\/$/, ''));
oHkp.lookup({query: sEmail}).then(function(sKey) {
fCallback(sKey);
}, function() {
fCallback(null);
});
}
else
{
fCallback(null);
}
};
PgpUserStore.prototype.verifyMessage = function(oMessage, fCallback)
{
if (oMessage && oMessage.getSigningKeyIds)
{
var aSigningKeyIds = oMessage.getSigningKeyIds();
if (aSigningKeyIds && 0 < aSigningKeyIds.length)
{
var aPublicKeys = this.findPublicKeysBySigningKeyIds(aSigningKeyIds);
if (aPublicKeys && 0 < aPublicKeys.length)
{
try
{
var
aResult = oMessage.verify(aPublicKeys),
oValid = _.find(_.isArray(aResult) ? aResult : [], function(oItem) {
return oItem && oItem.valid && oItem.keyid;
}, () => {
fCallback(null, null);
});
if (oValid && oValid.keyid && oValid.keyid && oValid.keyid.toHex)
{
fCallback(this.findPublicKeyByHex(oValid.keyid.toHex()));
return true;
}
}
catch (e)
{
Utils.log(e);
}
}
fCallback(null, aSigningKeyIds);
return false;
}
}
fCallback(null);
return false;
};
/**
* @param {*} mDom
*/
PgpUserStore.prototype.controlsHelper = function(mDom, oVerControl, bSuccess, sTitle, sText)
{
if (bSuccess)
{
mDom.removeClass('error').addClass('success').attr('title', sTitle);
oVerControl.removeClass('error').addClass('success').attr('title', sTitle);
}
else
{
mDom.removeClass('success').addClass('error').attr('title', sTitle);
oVerControl.removeClass('success').addClass('error').attr('title', sTitle);
}
if (!Utils.isUnd(sText))
{
mDom.text(Utils.trim(sText.replace(/(\u200C|\u0002)/g, '')));
}
};
/**
* @static
*/
PgpUserStore.domControlEncryptedClickHelper = function(store, mDom, sArmoredMessage, aRecipients)
{
return function() {
var
message = null,
$this = $(this);
if ($this.hasClass('success'))
{
return false;
}
try
{
message = store.openpgp.message.readArmored(sArmoredMessage);
}
catch (e)
{
Utils.log(e);
}
if (message && message.getText && message.verify && message.decrypt)
{
store.decryptMessage(message, aRecipients, function(oValidPrivateKey, oDecryptedMessage, oValidPublicKey, aSigningKeyIds) {
if (oDecryptedMessage)
{
if (oValidPublicKey)
{
store.controlsHelper(mDom, $this, true, Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': oValidPublicKey.user + ' (' + oValidPublicKey.id + ')'
}), oDecryptedMessage.getText());
}
else if (oValidPrivateKey)
{
var
aKeyIds = Utils.isNonEmptyArray(aSigningKeyIds) ? aSigningKeyIds : null,
sAdditional = aKeyIds ? _.compact(_.map(aKeyIds, function(oItem) {
return oItem && oItem.toHex ? oItem.toHex() : null;
})).join(', ') : '';
store.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') +
(sAdditional ? ' (' + sAdditional + ')' : ''),
oDecryptedMessage.getText());
}
else
{
store.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
fCallback(null, null);
}
}, privateKeys]);
return false;
}
}
fCallback(null, null);
return false;
}
verifyMessage(message, fCallback) {
if (message && message.getSigningKeyIds)
{
const signingKeyIds = message.getSigningKeyIds();
if (signingKeyIds && 0 < signingKeyIds.length)
{
const publicKeys = this.findPublicKeysBySigningKeyIds(signingKeyIds);
if (publicKeys && 0 < publicKeys.length)
{
try
{
const
result = message.verify(publicKeys),
valid = _.find(_.isArray(result) ? result : [], (item) => (item && item.valid && item.keyid));
if (valid && valid.keyid && valid.keyid && valid.keyid.toHex)
{
fCallback(this.findPublicKeyByHex(valid.keyid.toHex()));
return true;
}
}
catch (e)
{
log(e);
}
}
else
{
store.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
}
});
return false;
}
store.controlsHelper(mDom, $this, false, Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
};
};
/**
* @static
*/
PgpUserStore.domControlSignedClickHelper = function(store, mDom, sArmoredMessage)
{
return function() {
var
message = null,
$this = $(this);
if ($this.hasClass('success') || $this.hasClass('error'))
{
return false;
}
try
{
message = store.openpgp.cleartext.readArmored(sArmoredMessage);
}
catch (e)
{
Utils.log(e);
}
if (message && message.getText && message.verify)
{
store.verifyMessage(message, function(oValidKey, aSigningKeyIds) {
if (oValidKey)
{
store.controlsHelper(mDom, $this, true, Translator.i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': oValidKey.user + ' (' + oValidKey.id + ')'
}), message.getText());
}
else
{
var
aKeyIds = Utils.isNonEmptyArray(aSigningKeyIds) ? aSigningKeyIds : null,
sAdditional = aKeyIds ? _.compact(_.map(aKeyIds, function(oItem) {
return oItem && oItem.toHex ? oItem.toHex() : null;
})).join(', ') : '';
store.controlsHelper(mDom, $this, false,
Translator.i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') +
(sAdditional ? ' (' + sAdditional + ')' : ''));
}
});
return false;
}
store.controlsHelper(mDom, $this, false, Translator.i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
};
};
/**
* @param {*} mDom
* @param {MessageModel} oRainLoopMessage
*/
PgpUserStore.prototype.initMessageBodyControls = function(mDom, oRainLoopMessage)
{
if (mDom && !mDom.hasClass('inited'))
{
mDom.addClass('inited');
var
bEncrypted = mDom.hasClass('encrypted'),
bSigned = mDom.hasClass('signed'),
oVerControl = null,
aRecipients = oRainLoopMessage ? oRainLoopMessage.getEmails(['from', 'to', 'cc']) : [],
sData = '';
if (bEncrypted || bSigned)
{
sData = mDom.text();
mDom.data('openpgp-original', sData);
if (bEncrypted)
{
oVerControl = $('<div class="b-openpgp-control"><i class="icon-lock"></i></div>')
.attr('title', Translator.i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC'))
.on('click', PgpUserStore.domControlEncryptedClickHelper(this, mDom, sData, aRecipients));
fCallback(null, signingKeyIds);
return false;
}
else if (bSigned)
}
fCallback(null);
return false;
}
controlsHelper(dom, verControl, success, title, text) {
if (success)
{
dom.removeClass('error').addClass('success').attr('title', title);
verControl.removeClass('error').addClass('success').attr('title', title);
}
else
{
dom.removeClass('success').addClass('error').attr('title', title);
verControl.removeClass('success').addClass('error').attr('title', title);
}
if (!isUnd(text))
{
dom.text(trim(text));
}
}
static domControlEncryptedClickHelper(store, dom, armoredMessage, recipients) {
return function() {
let message = null;
const $this = $(this); // eslint-disable-line no-invalid-this
if ($this.hasClass('success'))
{
oVerControl = $('<div class="b-openpgp-control"><i class="icon-lock"></i></div>')
.attr('title', Translator.i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC'))
.on('click', PgpUserStore.domControlSignedClickHelper(this, mDom, sData));
return false;
}
if (oVerControl)
try
{
mDom.before(oVerControl).before('<div></div>');
message = store.openpgp.message.readArmored(armoredMessage);
}
catch (e)
{
log(e);
}
if (message && message.getText && message.verify && message.decrypt)
{
store.decryptMessage(message, recipients, (validPrivateKey, decryptedMessage, validPublicKey, signingKeyIds) => {
if (decryptedMessage)
{
if (validPublicKey)
{
store.controlsHelper(dom, $this, true, i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': validPublicKey.user + ' (' + validPublicKey.id + ')'
}), decryptedMessage.getText());
}
else if (validPrivateKey)
{
const
keyIds = isNonEmptyArray(signingKeyIds) ? signingKeyIds : null,
additional = keyIds ? _.compact(_.map(keyIds,
(item) => (item && item.toHex ? item.toHex() : null))).join(', ') : '';
store.controlsHelper(dom, $this, false, i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') +
(additional ? ' (' + additional + ')' : ''), decryptedMessage.getText());
}
else
{
store.controlsHelper(dom, $this, false, i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
}
}
else
{
store.controlsHelper(dom, $this, false, i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
}
});
return false;
}
store.controlsHelper(dom, $this, false, i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
};
}
static domControlSignedClickHelper(store, dom, armoredMessage) {
return function() {
let message = null;
const $this = $(this); // eslint-disable-line no-invalid-this
if ($this.hasClass('success') || $this.hasClass('error'))
{
return false;
}
try
{
message = store.openpgp.cleartext.readArmored(armoredMessage);
}
catch (e)
{
log(e);
}
if (message && message.getText && message.verify)
{
store.verifyMessage(message, (validKey, signingKeyIds) => {
if (validKey)
{
store.controlsHelper(dom, $this, true, i18n('PGP_NOTIFICATIONS/GOOD_SIGNATURE', {
'USER': validKey.user + ' (' + validKey.id + ')'
}), message.getText());
}
else
{
const
keyIds = isNonEmptyArray(signingKeyIds) ? signingKeyIds : null,
additional = keyIds ? _.compact(_.map(keyIds, (item) => (item && item.toHex ? item.toHex() : null))).join(', ') : '';
store.controlsHelper(dom, $this, false,
i18n('PGP_NOTIFICATIONS/UNVERIFIRED_SIGNATURE') + (additional ? ' (' + additional + ')' : ''));
}
});
return false;
}
store.controlsHelper(dom, $this, false, i18n('PGP_NOTIFICATIONS/DECRYPTION_ERROR'));
return false;
};
}
/**
* @param {*} dom
* @param {MessageModel} rainLoopMessage
*/
initMessageBodyControls(dom, rainLoopMessage) {
if (dom && !dom.hasClass('inited'))
{
dom.addClass('inited');
const
encrypted = dom.hasClass('encrypted'),
signed = dom.hasClass('signed'),
recipients = rainLoopMessage ? rainLoopMessage.getEmails(['from', 'to', 'cc']) : [];
let verControl = null;
if (encrypted || signed)
{
const domText = dom.text();
dom.data('openpgp-original', domText);
if (encrypted)
{
verControl = $('<div class="b-openpgp-control"><i class="icon-lock"></i></div>')
.attr('title', i18n('MESSAGE/PGP_ENCRYPTED_MESSAGE_DESC'))
.on('click', PgpUserStore.domControlEncryptedClickHelper(this, dom, domText, recipients));
}
else if (signed)
{
verControl = $('<div class="b-openpgp-control"><i class="icon-lock"></i></div>')
.attr('title', i18n('MESSAGE/PGP_SIGNED_MESSAGE_DESC'))
.on('click', PgpUserStore.domControlSignedClickHelper(this, dom, domText));
}
if (verControl)
{
dom.before(verControl).before('<div></div>');
}
}
}
}
};
}
module.exports = new PgpUserStore();

View file

@ -1,35 +1,32 @@
var
window = require('window'),
ko = require('ko');
import window from 'window';
import ko from 'ko';
/**
* @constructor
*/
function QuotaUserStore()
class QuotaUserStore
{
this.quota = ko.observable(0);
this.usage = ko.observable(0);
constructor() {
this.quota = ko.observable(0);
this.usage = ko.observable(0);
this.percentage = ko.computed(function() {
this.percentage = ko.computed(() => {
var
iQuota = this.quota(),
iUsed = this.usage();
const
quota = this.quota(),
usage = this.usage();
return 0 < iQuota ? window.Math.ceil((iUsed / iQuota) * 100) : 0;
return 0 < quota ? window.Math.ceil((usage / quota) * 100) : 0;
}, this);
});
}
/**
* @param {number} quota
* @param {number} usage
*/
populateData(quota, usage) {
this.quota(quota * 1024);
this.usage(usage * 1024);
}
}
/**
* @param {number} iQuota
* @param {number} iUsage
*/
QuotaUserStore.prototype.populateData = function(iQuota, iUsage)
{
this.quota(iQuota * 1024);
this.usage(iUsage * 1024);
};
module.exports = new QuotaUserStore();

View file

@ -1,93 +1,81 @@
var
window = require('window'),
ko = require('ko'),
import window from 'window';
import ko from 'ko';
Consts = require('Common/Consts'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Events = require('Common/Events'),
import {MESSAGES_PER_PAGE, MESSAGES_PER_PAGE_VALUES} from 'Common/Consts';
import {Layout, EditorDefaultType, Magics} from 'Common/Enums';
import {$html} from 'Common/Globals';
import {pInt} from 'Common/Utils';
import * as Events from 'Common/Events';
Settings = require('Storage/Settings');
import * as Settings from 'Storage/Settings';
/**
* @constructor
*/
function SettingsUserStore()
class SettingsUserStore
{
this.iAutoLogoutTimer = 0;
constructor() {
this.layout = ko.observable(Enums.Layout.SidePreview)
.extend({'limitedList': [
Enums.Layout.SidePreview, Enums.Layout.BottomPreview, Enums.Layout.NoPreview
]});
this.iAutoLogoutTimer = 0;
this.editorDefaultType = ko.observable(Enums.EditorDefaultType.Html)
.extend({'limitedList': [
Enums.EditorDefaultType.Html, Enums.EditorDefaultType.Plain,
Enums.EditorDefaultType.HtmlForced, Enums.EditorDefaultType.PlainForced
]});
this.layout = ko.observable(Layout.SidePreview)
.extend({limitedList: [Layout.SidePreview, Layout.BottomPreview, Layout.NoPreview]});
this.messagesPerPage = ko.observable(Consts.MESSAGES_PER_PAGE)
.extend({'limitedList': Consts.MESSAGES_PER_PAGE_VALUES});
this.editorDefaultType = ko.observable(EditorDefaultType.Html)
.extend({limitedList: [
EditorDefaultType.Html, EditorDefaultType.Plain,
EditorDefaultType.HtmlForced, EditorDefaultType.PlainForced
]});
this.showImages = ko.observable(false);
this.useCheckboxesInList = ko.observable(true);
this.useThreads = ko.observable(false);
this.replySameFolder = ko.observable(false);
this.messagesPerPage = ko.observable(MESSAGES_PER_PAGE)
.extend({limitedList: MESSAGES_PER_PAGE_VALUES});
this.autoLogout = ko.observable(30);
this.showImages = ko.observable(false);
this.useCheckboxesInList = ko.observable(true);
this.useThreads = ko.observable(false);
this.replySameFolder = ko.observable(false);
this.computers();
this.subscribers();
this.autoLogout = ko.observable(30);
this.computers();
this.subscribers();
}
computers() {
this.usePreviewPane = ko.computed(() => Layout.NoPreview !== this.layout());
}
subscribers() {
this.layout.subscribe((nValue) => {
$html.toggleClass('rl-no-preview-pane', Layout.NoPreview === nValue);
$html.toggleClass('rl-side-preview-pane', Layout.SidePreview === nValue);
$html.toggleClass('rl-bottom-preview-pane', Layout.BottomPreview === nValue);
Events.pub('layout', [nValue]);
});
}
populate() {
this.layout(pInt(Settings.settingsGet('Layout')));
this.editorDefaultType(Settings.settingsGet('EditorDefaultType'));
this.autoLogout(pInt(Settings.settingsGet('AutoLogout')));
this.messagesPerPage(Settings.settingsGet('MPP'));
this.showImages(!!Settings.settingsGet('ShowImages'));
this.useCheckboxesInList(!!Settings.settingsGet('UseCheckboxesInList'));
this.useThreads(!!Settings.settingsGet('UseThreads'));
this.replySameFolder(!!Settings.settingsGet('ReplySameFolder'));
Events.sub('rl.auto-logout-refresh', () => {
window.clearTimeout(this.iAutoLogoutTimer);
if (0 < this.autoLogout() && !Settings.settingsGet('AccountSignMe'))
{
this.iAutoLogoutTimer = window.setTimeout(() => {
Events.pub('rl.auto-logout');
}, this.autoLogout() * Magics.Time1m);
}
});
Events.pub('rl.auto-logout-refresh');
}
}
SettingsUserStore.prototype.computers = function()
{
this.usePreviewPane = ko.computed(function() {
return Enums.Layout.NoPreview !== this.layout();
}, this);
};
SettingsUserStore.prototype.subscribers = function()
{
this.layout.subscribe(function(nValue) {
Globals.$html.toggleClass('rl-no-preview-pane', Enums.Layout.NoPreview === nValue);
Globals.$html.toggleClass('rl-side-preview-pane', Enums.Layout.SidePreview === nValue);
Globals.$html.toggleClass('rl-bottom-preview-pane', Enums.Layout.BottomPreview === nValue);
Events.pub('layout', [nValue]);
});
};
SettingsUserStore.prototype.populate = function()
{
this.layout(Utils.pInt(Settings.settingsGet('Layout')));
this.editorDefaultType(Settings.settingsGet('EditorDefaultType'));
this.autoLogout(Utils.pInt(Settings.settingsGet('AutoLogout')));
this.messagesPerPage(Settings.settingsGet('MPP'));
this.showImages(!!Settings.settingsGet('ShowImages'));
this.useCheckboxesInList(!!Settings.settingsGet('UseCheckboxesInList'));
this.useThreads(!!Settings.settingsGet('UseThreads'));
this.replySameFolder(!!Settings.settingsGet('ReplySameFolder'));
var self = this;
Events.sub('rl.auto-logout-refresh', function() {
window.clearTimeout(self.iAutoLogoutTimer);
if (0 < self.autoLogout() && !Settings.settingsGet('AccountSignMe'))
{
self.iAutoLogoutTimer = window.setTimeout(function() {
Events.pub('rl.auto-logout');
}, self.autoLogout() * Enums.Magics.Time1m);
}
});
Events.pub('rl.auto-logout-refresh');
};
module.exports = new SettingsUserStore();

View file

@ -1,33 +1,28 @@
var
_ = require('_'),
ko = require('ko');
import ko from 'ko';
import _ from '_';
// Remote = require('Remote/User/Ajax');
/**
* @constructor
*/
function TemplateUserStore()
class TemplateUserStore
{
this.templates = ko.observableArray([]);
this.templates.loading = ko.observable(false).extend({'throttle': 100});
constructor() {
this.templates = ko.observableArray([]);
this.templates.loading = ko.observable(false).extend({throttle: 100});
this.templatesNames = ko.observableArray([]).extend({'throttle': 1000});
this.templatesNames.skipFirst = true;
this.templatesNames = ko.observableArray([]).extend({throttle: 1000});
this.templatesNames.skipFirst = true;
this.subscribers();
}
this.subscribers();
}
TemplateUserStore.prototype.subscribers = function()
{
this.templates.subscribe(function(aList) {
this.templatesNames(_.compact(_.map(aList, function(oItem) {
return oItem ? oItem.name : null;
})));
}, this);
subscribers() {
// this.templatesNames.subscribe(function(aList) {
this.templates.subscribe((list) => {
this.templatesNames(_.compact(_.map(list, (item) => (item ? item.name : null))));
});
// this.templatesNames.subscribe((aList) => {
// if (this.templatesNames.skipFirst)
// {
// this.templatesNames.skipFirst = false;
@ -36,7 +31,8 @@ TemplateUserStore.prototype.subscribers = function()
// {
// Remote.templatesSortOrder(null, aList);
// }
// }, this);
};
// });
}
}
module.exports = new TemplateUserStore();