mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 21:49:21 +03:00
Code refactoring (Translator, Stores, ko)
This commit is contained in:
parent
929bffccef
commit
b42ce01e7e
102 changed files with 6775 additions and 6511 deletions
28
dev/Stores/Filter.js
Normal file
28
dev/Stores/Filter.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FilterStore()
|
||||
{
|
||||
this.capa = ko.observable('');
|
||||
this.modules = ko.observable({});
|
||||
|
||||
this.collection = ko.observableArray([]);
|
||||
|
||||
this.collection.loading = ko.observable(false).extend({'throttle': 200});
|
||||
this.collection.saving = ko.observable(false).extend({'throttle': 200});
|
||||
|
||||
this.raw = ko.observable('');
|
||||
}
|
||||
|
||||
module.exports = new FilterStore();
|
||||
|
||||
}());
|
||||
152
dev/Stores/NotificationSettings.js
Normal file
152
dev/Stores/NotificationSettings.js
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
window = require('window'),
|
||||
ko = require('ko'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
|
||||
Settings = require('Storage/Settings')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function NotificationSettings()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.allowDesktopNotification = ko.observable(false);
|
||||
|
||||
this.desktopNotificationPermisions = ko.computed(function () {
|
||||
|
||||
this.allowDesktopNotification();
|
||||
|
||||
var
|
||||
NotificationClass = this.notificationClass(),
|
||||
iResult = Enums.DesktopNotification.NotSupported
|
||||
;
|
||||
|
||||
if (NotificationClass && NotificationClass.permission)
|
||||
{
|
||||
switch (NotificationClass.permission.toLowerCase())
|
||||
{
|
||||
case 'granted':
|
||||
iResult = Enums.DesktopNotification.Allowed;
|
||||
break;
|
||||
case 'denied':
|
||||
iResult = Enums.DesktopNotification.Denied;
|
||||
break;
|
||||
case 'default':
|
||||
iResult = Enums.DesktopNotification.NotAllowed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (window.webkitNotifications && window.webkitNotifications.checkPermission)
|
||||
{
|
||||
iResult = window.webkitNotifications.checkPermission();
|
||||
}
|
||||
|
||||
return iResult;
|
||||
|
||||
}, this);
|
||||
|
||||
this.enableDesktopNotification = ko.computed({
|
||||
'owner': this,
|
||||
'read': function () {
|
||||
return this.allowDesktopNotification() &&
|
||||
Enums.DesktopNotification.Allowed === this.desktopNotificationPermisions();
|
||||
},
|
||||
'write': function (bValue) {
|
||||
if (bValue)
|
||||
{
|
||||
var
|
||||
NotificationClass = this.notificationClass(),
|
||||
iPermission = this.desktopNotificationPermisions()
|
||||
;
|
||||
|
||||
if (NotificationClass && Enums.DesktopNotification.Allowed === iPermission)
|
||||
{
|
||||
this.allowDesktopNotification(true);
|
||||
}
|
||||
else if (NotificationClass && Enums.DesktopNotification.NotAllowed === iPermission)
|
||||
{
|
||||
NotificationClass.requestPermission(function () {
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
if (Enums.DesktopNotification.Allowed === self.desktopNotificationPermisions())
|
||||
{
|
||||
if (self.allowDesktopNotification())
|
||||
{
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
}
|
||||
else
|
||||
{
|
||||
self.allowDesktopNotification(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self.allowDesktopNotification())
|
||||
{
|
||||
self.allowDesktopNotification(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.allowDesktopNotification(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.allowDesktopNotification(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.enableDesktopNotification.valueHasMutated)
|
||||
{
|
||||
this.enableDesktopNotification.valueHasMutated = function () {
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
};
|
||||
}
|
||||
|
||||
this.computedProperies();
|
||||
}
|
||||
|
||||
NotificationSettings.prototype.computedProperies = function ()
|
||||
{
|
||||
this.isDesktopNotificationSupported = ko.computed(function () {
|
||||
return Enums.DesktopNotification.NotSupported !== this.desktopNotificationPermisions();
|
||||
}, this);
|
||||
|
||||
this.isDesktopNotificationDenied = ko.computed(function () {
|
||||
return Enums.DesktopNotification.NotSupported === this.desktopNotificationPermisions() ||
|
||||
Enums.DesktopNotification.Denied === this.desktopNotificationPermisions();
|
||||
}, this);
|
||||
};
|
||||
|
||||
NotificationSettings.prototype.populate = function ()
|
||||
{
|
||||
this.enableDesktopNotification(!!Settings.settingsGet('DesktopNotifications'));
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {*|null}
|
||||
*/
|
||||
NotificationSettings.prototype.notificationClass = function ()
|
||||
{
|
||||
return window.Notification && window.Notification.requestPermission ? window.Notification : null;
|
||||
};
|
||||
|
||||
module.exports = new NotificationSettings();
|
||||
|
||||
}());
|
||||
43
dev/Stores/Quota.js
Normal file
43
dev/Stores/Quota.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
window = require('window'),
|
||||
ko = require('ko')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function QuotaStore()
|
||||
{
|
||||
this.quota = ko.observable(0);
|
||||
this.usage = ko.observable(0);
|
||||
|
||||
this.percentage = ko.computed(function () {
|
||||
|
||||
var
|
||||
iQuota = this.quota(),
|
||||
iUsed = this.usage()
|
||||
;
|
||||
|
||||
return 0 < iQuota ? window.Math.ceil((iUsed / iQuota) * 100) : 0;
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} iQuota
|
||||
* @param {number} iUsage
|
||||
*/
|
||||
QuotaStore.prototype.populateData = function(iQuota, iUsage)
|
||||
{
|
||||
this.quota(iQuota * 1024);
|
||||
this.usage(iUsage * 1024);
|
||||
};
|
||||
|
||||
module.exports = new QuotaStore();
|
||||
|
||||
}());
|
||||
110
dev/Stores/Social.js
Normal file
110
dev/Stores/Social.js
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function SocialStore()
|
||||
{
|
||||
// TODO
|
||||
this.google = {};
|
||||
this.twitter = {};
|
||||
this.facebook = {};
|
||||
this.dropbox = {};
|
||||
|
||||
// Google
|
||||
this.google.enabled = ko.observable(false);
|
||||
|
||||
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.loggined = ko.computed(function () {
|
||||
return '' !== this.google.userName();
|
||||
}, this);
|
||||
|
||||
this.google.capa = {};
|
||||
this.google.capa.auth = 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.apiKeySettings = ko.computed(function () {
|
||||
return this.google.enabled() && this.google.capa.drive();
|
||||
}, this);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Dropbox
|
||||
this.dropbox.enabled = ko.observable(false);
|
||||
this.dropbox.apiKey = ko.observable('');
|
||||
}
|
||||
|
||||
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.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();
|
||||
|
||||
}());
|
||||
80
dev/Stores/UserSettings.js
Normal file
80
dev/Stores/UserSettings.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko'),
|
||||
|
||||
Consts = require('Common/Consts'),
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
Settings = require('Storage/Settings')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function UserSettingsStore()
|
||||
{
|
||||
this.layout = ko.observable(Enums.Layout.SidePreview)
|
||||
.extend({'limitedList': [
|
||||
Enums.Layout.SidePreview, Enums.Layout.BottomPreview, Enums.Layout.NoPreview
|
||||
]});
|
||||
|
||||
this.editorDefaultType = ko.observable(Enums.EditorDefaultType.Html)
|
||||
.extend({'limitedList': [
|
||||
Enums.EditorDefaultType.Html, Enums.EditorDefaultType.Plain,
|
||||
Enums.EditorDefaultType.HtmlForced, Enums.EditorDefaultType.PlainForced
|
||||
]});
|
||||
|
||||
this.languages = ko.observableArray([]);
|
||||
|
||||
this.language = ko.observable('')
|
||||
.extend({'limitedList': this.languages});
|
||||
|
||||
this.themes = ko.observableArray([]);
|
||||
this.themeBackgroundName = ko.observable('');
|
||||
this.themeBackgroundHash = ko.observable('');
|
||||
|
||||
this.theme = ko.observable('')
|
||||
.extend({'limitedList': this.themes});
|
||||
|
||||
this.messagesPerPage = ko.observable(Consts.Defaults.MessagesPerPage)
|
||||
.extend({'limitedList': Consts.Defaults.MessagesPerPageArray});
|
||||
|
||||
this.computedProperies();
|
||||
}
|
||||
|
||||
UserSettingsStore.prototype.computedProperies = function ()
|
||||
{
|
||||
this.usePreviewPane = ko.computed(function () {
|
||||
return Enums.Layout.NoPreview !== this.layout();
|
||||
}, this);
|
||||
};
|
||||
|
||||
UserSettingsStore.prototype.populate = function ()
|
||||
{
|
||||
var
|
||||
aLanguages = Settings.settingsGet('Languages'),
|
||||
aThemes = Settings.settingsGet('Themes')
|
||||
;
|
||||
|
||||
this.layout(Utils.pInt(Settings.settingsGet('Layout')));
|
||||
this.editorDefaultType(Settings.settingsGet('EditorDefaultType'));
|
||||
|
||||
this.languages(Utils.isArray(aLanguages) ? aLanguages : []);
|
||||
this.language(Settings.settingsGet('Language'));
|
||||
|
||||
this.themes(Utils.isArray(aThemes) ? aThemes : []);
|
||||
this.theme(Settings.settingsGet('Theme'));
|
||||
this.themeBackgroundName(Settings.settingsGet('UserBackgroundName'));
|
||||
this.themeBackgroundHash(Settings.settingsGet('UserBackgroundHash'));
|
||||
|
||||
this.messagesPerPage(Settings.settingsGet('MPP'));
|
||||
};
|
||||
|
||||
module.exports = new UserSettingsStore();
|
||||
|
||||
}());
|
||||
Loading…
Add table
Add a link
Reference in a new issue