Code refactoring (Translator, Stores, ko)

This commit is contained in:
RainLoop Team 2015-01-26 03:09:22 +04:00
parent 929bffccef
commit b42ce01e7e
102 changed files with 6775 additions and 6511 deletions

View file

@ -9,7 +9,7 @@
ko = require('ko'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
Links = require('Common/Links'),
Data = require('Storage/User/Data'),
@ -24,7 +24,7 @@
this.accounts = Data.accounts;
this.processText = ko.computed(function () {
return Data.accountsLoading() ? Utils.i18n('SETTINGS_ACCOUNTS/LOADING_PROCESS') : '';
return Data.accountsLoading() ? Translator.i18n('SETTINGS_ACCOUNTS/LOADING_PROCESS') : '';
}, this);
this.visibility = ko.computed(function () {

View file

@ -9,6 +9,7 @@
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
Remote = require('Storage/User/Remote')
;
@ -53,7 +54,7 @@
if (this.newPassword() !== this.newPassword2())
{
this.passwordMismatch(true);
this.errorDescription(Utils.i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
this.errorDescription(Translator.i18n('SETTINGS_CHANGE_PASSWORD/ERROR_PASSWORD_MISMATCH'));
}
else
{
@ -112,7 +113,7 @@
this.passwordUpdateError(true);
this.errorDescription(oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) :
Utils.getNotification(Enums.Notification.CouldNotSaveNewPassword));
Translator.getNotification(Enums.Notification.CouldNotSaveNewPassword));
}
};

View file

@ -9,8 +9,9 @@
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
Data = require('Storage/User/Data'),
FilterStore = require('Stores/Filter'),
Remote = require('Storage/User/Remote')
;
@ -22,6 +23,9 @@
{
var self = this;
this.modules = FilterStore.modules;
this.filters = FilterStore.collection;
this.haveChanges = ko.observable(false);
this.processText = ko.observable('');
@ -29,22 +33,16 @@
this.visibility = ko.observable(false);
this.modules = Data.filterModules;
this.filters = ko.observableArray([]);
this.filters.loading = ko.observable(false).extend({'throttle': 200});
this.filters.saving = ko.observable(false).extend({'throttle': 200});
this.filters.subscribe(Utils.windowResizeCallback);
this.filterRaw = ko.observable('');
this.filterRaw.capa = ko.observable('');
this.filterRaw = FilterStore.raw;
this.filterRaw.capa = FilterStore.capa;
this.filterRaw.active = ko.observable(false);
this.filterRaw.allow = ko.observable(false);
this.filterRaw.error = ko.observable(false);
this.processText = ko.computed(function () {
return this.filters.loading() ? Utils.i18n('SETTINGS_FILTERS/LOADING_PROCESS') : '';
return this.filters.loading() ? Translator.i18n('SETTINGS_FILTERS/LOADING_PROCESS') : '';
}, this);
this.visibility = ko.computed(function () {
@ -78,8 +76,8 @@
}
else
{
self.saveErrorText(oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) :
Utils.getNotification(Enums.Notification.CantSaveFilters));
self.saveErrorText(oData && oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) :
Translator.getNotification(Enums.Notification.CantSaveFilters));
}
}, this.filters(), this.filterRaw(), this.filterRaw.active());
@ -173,7 +171,6 @@
require('Knoin/Knoin').showScreenPopup(
require('View/Popup/Filter'), [oNew, function () {
self.filters.push(oNew);
self.haveChanges(true);
self.filterRaw.active(false);
}, false]);
};

View file

@ -8,6 +8,7 @@
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
Settings = require('Storage/Settings'),
Data = require('Storage/User/Data'),
@ -34,19 +35,19 @@
if (bCreating)
{
return Utils.i18n('SETTINGS_FOLDERS/CREATING_PROCESS');
return Translator.i18n('SETTINGS_FOLDERS/CREATING_PROCESS');
}
else if (bDeleting)
{
return Utils.i18n('SETTINGS_FOLDERS/DELETING_PROCESS');
return Translator.i18n('SETTINGS_FOLDERS/DELETING_PROCESS');
}
else if (bRenaming)
{
return Utils.i18n('SETTINGS_FOLDERS/RENAMING_PROCESS');
return Translator.i18n('SETTINGS_FOLDERS/RENAMING_PROCESS');
}
else if (bLoading)
{
return Utils.i18n('SETTINGS_FOLDERS/LOADING_PROCESS');
return Translator.i18n('SETTINGS_FOLDERS/LOADING_PROCESS');
}
return '';
@ -105,7 +106,7 @@
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
Data.folderList.error(
oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_RENAME_FOLDER'));
oData && oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) : Translator.i18n('NOTIFICATIONS/CANT_RENAME_FOLDER'));
}
require('App/User').folders();
@ -176,7 +177,7 @@
if (Enums.StorageResultType.Success !== sResult || !oData || !oData.Result)
{
Data.folderList.error(
oData && oData.ErrorCode ? Utils.getNotification(oData.ErrorCode) : Utils.i18n('NOTIFICATIONS/CANT_DELETE_FOLDER'));
oData && oData.ErrorCode ? Translator.getNotification(oData.ErrorCode) : Translator.i18n('NOTIFICATIONS/CANT_DELETE_FOLDER'));
}
require('App/User').folders();
@ -188,7 +189,7 @@
}
else if (0 < oFolderToRemove.privateMessageCountAll())
{
Data.folderList.error(Utils.getNotification(Enums.Notification.CantDeleteNonEmptyFolder));
Data.folderList.error(Translator.getNotification(Enums.Notification.CantDeleteNonEmptyFolder));
}
};

View file

@ -11,6 +11,10 @@
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
UserSettingsStore = require('Stores/UserSettings'),
NotificationSettingsStore = require('Stores/NotificationSettings'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
@ -21,31 +25,28 @@
*/
function GeneralUserSettings()
{
this.mainLanguage = Data.mainLanguage;
this.mainMessagesPerPage = Data.mainMessagesPerPage;
this.mainMessagesPerPageArray = Consts.Defaults.MessagesPerPageArray;
this.editorDefaultType = Data.editorDefaultType;
this.language = UserSettingsStore.language;
this.messagesPerPage = UserSettingsStore.messagesPerPage;
this.messagesPerPageArray = Consts.Defaults.MessagesPerPageArray;
this.editorDefaultType = UserSettingsStore.editorDefaultType;
this.layout = UserSettingsStore.layout;
this.usePreviewPane = UserSettingsStore.usePreviewPane;
this.showImages = Data.showImages;
this.useDesktopNotifications = Data.useDesktopNotifications;
this.enableDesktopNotification = NotificationSettingsStore.enableDesktopNotification;
this.isDesktopNotificationSupported = NotificationSettingsStore.isDesktopNotificationSupported;
this.isDesktopNotificationDenied = NotificationSettingsStore.isDesktopNotificationDenied;
this.threading = Data.threading;
this.useThreads = Data.useThreads;
this.replySameFolder = Data.replySameFolder;
this.layout = Data.layout;
this.usePreviewPane = Data.usePreviewPane;
this.useCheckboxesInList = Data.useCheckboxesInList;
this.allowLanguagesOnSettings = Data.allowLanguagesOnSettings;
this.isDesktopNotificationsSupported = ko.computed(function () {
return Enums.DesktopNotifications.NotSupported !== Data.desktopNotificationsPermisions();
});
this.isDesktopNotificationsDenied = ko.computed(function () {
return Enums.DesktopNotifications.NotSupported === Data.desktopNotificationsPermisions() ||
Enums.DesktopNotifications.Denied === Data.desktopNotificationsPermisions();
});
this.mainLanguageFullName = ko.computed(function () {
return Utils.convertLangName(this.mainLanguage());
this.languageFullName = ko.computed(function () {
return Utils.convertLangName(this.language());
}, this);
this.languageTrigger = ko.observable(Enums.SaveSettingsStep.Idle).extend({'throttle': 100});
@ -57,21 +58,21 @@
this.isAnimationSupported = Globals.bAnimationSupported;
this.editorDefaultTypes = ko.computed(function () {
Globals.langChangeTrigger();
Translator.trigger();
return [
{'id': Enums.EditorDefaultType.Html, 'name': Utils.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML')},
{'id': Enums.EditorDefaultType.Plain, 'name': Utils.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN')},
{'id': Enums.EditorDefaultType.HtmlForced, 'name': Utils.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML_FORCED')},
{'id': Enums.EditorDefaultType.PlainForced, 'name': Utils.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN_FORCED')}
{'id': Enums.EditorDefaultType.Html, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML')},
{'id': Enums.EditorDefaultType.Plain, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN')},
{'id': Enums.EditorDefaultType.HtmlForced, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_HTML_FORCED')},
{'id': Enums.EditorDefaultType.PlainForced, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_EDITOR_PLAIN_FORCED')}
];
}, this);
this.layoutTypes = ko.computed(function () {
Globals.langChangeTrigger();
Translator.trigger();
return [
{'id': Enums.Layout.NoPreview, 'name': Utils.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_NO_SPLIT')},
{'id': Enums.Layout.SidePreview, 'name': Utils.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_VERTICAL_SPLIT')},
{'id': Enums.Layout.BottomPreview, 'name': Utils.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT')}
{'id': Enums.Layout.NoPreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_NO_SPLIT')},
{'id': Enums.Layout.SidePreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_VERTICAL_SPLIT')},
{'id': Enums.Layout.BottomPreview, 'name': Translator.i18n('SETTINGS_GENERAL/LABEL_LAYOUT_HORIZONTAL_SPLIT')}
];
}, this);
}
@ -96,11 +97,11 @@
}
;
Data.language.subscribe(function (sValue) {
self.language.subscribe(function (sValue) {
self.languageTrigger(Enums.SaveSettingsStep.Animate);
Utils.reloadLanguage(sValue,
Translator.reload(sValue,
fReloadLanguageHelper(Enums.SaveSettingsStep.TrueResult),
fReloadLanguageHelper(Enums.SaveSettingsStep.FalseResult));
@ -109,13 +110,13 @@
});
});
Data.editorDefaultType.subscribe(function (sValue) {
self.editorDefaultType.subscribe(function (sValue) {
Remote.saveSettings(f0, {
'EditorDefaultType': sValue
});
});
Data.messagesPerPage.subscribe(function (iValue) {
self.messagesPerPage.subscribe(function (iValue) {
Remote.saveSettings(f1, {
'MPP': iValue
});
@ -127,7 +128,7 @@
});
});
Data.useDesktopNotifications.subscribe(function (bValue) {
self.enableDesktopNotification.subscribe(function (bValue) {
Utils.timeOutAction('SaveDesktopNotifications', function () {
Remote.saveSettings(null, {
'DesktopNotifications': bValue ? '1' : '0'
@ -152,7 +153,7 @@
});
});
Data.layout.subscribe(function (nValue) {
self.layout.subscribe(function (nValue) {
Data.messageList([]);
@ -172,7 +173,7 @@
GeneralUserSettings.prototype.onShow = function ()
{
Data.desktopNotifications.valueHasMutated();
this.enableDesktopNotification.valueHasMutated();
};
GeneralUserSettings.prototype.selectLanguage = function ()

View file

@ -10,6 +10,7 @@
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
HtmlEditor = require('Common/HtmlEditor'),
Translator = require('Common/Translator'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
@ -74,7 +75,7 @@
}, this);
this.processText = ko.computed(function () {
return Data.identitiesLoading() ? Utils.i18n('SETTINGS_IDENTITIES/LOADING_PROCESS') : '';
return Data.identitiesLoading() ? Translator.i18n('SETTINGS_IDENTITIES/LOADING_PROCESS') : '';
}, this);
this.visibility = ko.computed(function () {

View file

@ -7,8 +7,8 @@
ko = require('ko'),
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
Remote = require('Storage/User/Remote')
;
@ -34,8 +34,8 @@
this.bFirst = true;
this.viewTwoFactorStatus = ko.computed(function () {
Globals.langChangeTrigger();
return Utils.i18n(
Translator.trigger();
return Translator.i18n(
this.twoFactorStatus() ?
'SETTINGS_SECURITY/TWO_FACTOR_SECRET_CONFIGURED_DESC' :
'SETTINGS_SECURITY/TWO_FACTOR_SECRET_NOT_CONFIGURED_DESC'

View file

@ -10,26 +10,29 @@
{
var
Utils = require('Common/Utils'),
Data = require('Storage/User/Data')
SocialStore = require('Stores/Social')
;
this.googleEnable = Data.googleEnable;
this.googleEnable = SocialStore.google.enabled;
this.googleEnableAuth = SocialStore.google.capa.auth;
this.googleEnableDrive = SocialStore.google.capa.drive;
this.googleEnablePreview = SocialStore.google.capa.preview;
this.googleActions = Data.googleActions;
this.googleLoggined = Data.googleLoggined;
this.googleUserName = Data.googleUserName;
this.googleActions = SocialStore.google.loading;
this.googleLoggined = SocialStore.google.loggined;
this.googleUserName = SocialStore.google.userName;
this.facebookEnable = Data.facebookEnable;
this.facebookEnable = SocialStore.facebook.enabled;
this.facebookActions = Data.facebookActions;
this.facebookLoggined = Data.facebookLoggined;
this.facebookUserName = Data.facebookUserName;
this.facebookActions = SocialStore.facebook.loading;
this.facebookLoggined = SocialStore.facebook.loggined;
this.facebookUserName = SocialStore.facebook.userName;
this.twitterEnable = Data.twitterEnable;
this.twitterEnable = SocialStore.twitter.enabled;
this.twitterActions = Data.twitterActions;
this.twitterLoggined = Data.twitterLoggined;
this.twitterUserName = Data.twitterUserName;
this.twitterActions = SocialStore.twitter.loading;
this.twitterLoggined = SocialStore.twitter.loggined;
this.twitterUserName = SocialStore.twitter.userName;
this.connectGoogle = Utils.createCommand(this, function () {
if (!this.googleLoggined())

View file

@ -12,6 +12,9 @@
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Links = require('Common/Links'),
Translator = require('Common/Translator'),
UserSettingsStore = require('Stores/UserSettings'),
Data = require('Storage/User/Data'),
Remote = require('Storage/User/Remote')
@ -22,12 +25,13 @@
*/
function ThemesUserSettings()
{
this.mainTheme = Data.mainTheme;
this.theme = UserSettingsStore.theme;
this.themes = UserSettingsStore.themes;
this.themesObjects = ko.observableArray([]);
this.background = {};
this.background.name = Data.themeBackgroundName;
this.background.hash = Data.themeBackgroundHash;
this.background.name = UserSettingsStore.themeBackgroundName;
this.background.hash = UserSettingsStore.themeBackgroundHash;
this.background.uploaderButton = ko.observable(null);
this.background.loading = ko.observable(false);
this.background.error = ko.observable('');
@ -39,7 +43,7 @@
this.iTimer = 0;
this.oThemeAjaxRequest = null;
Data.theme.subscribe(function (sValue) {
this.theme.subscribe(function (sValue) {
_.each(this.themesObjects(), function (oTheme) {
oTheme.selected(sValue === oTheme.name);
@ -54,14 +58,14 @@
}, this);
this.background.hash.subscribe(function (sValue) {
Utils.changeTheme(Data.theme(), sValue, this.themeTrigger, Links);
Utils.changeTheme(this.theme(), sValue, this.themeTrigger, Links);
}, this);
}
ThemesUserSettings.prototype.onBuild = function ()
{
var sCurrentTheme = Data.theme();
this.themesObjects(_.map(Data.themes(), function (sTheme) {
var sCurrentTheme = this.theme();
this.themesObjects(_.map(this.themes(), function (sTheme) {
return {
'name': sTheme,
'nameDisplay': Utils.convertThemeName(sTheme),
@ -135,10 +139,10 @@
switch (oData.ErrorCode)
{
case Enums.UploadErrorCode.FileIsTooBig:
sError = Utils.i18n('SETTINGS_THEMES/ERROR_FILE_IS_TOO_BIG');
sError = Translator.i18n('SETTINGS_THEMES/ERROR_FILE_IS_TOO_BIG');
break;
case Enums.UploadErrorCode.FileType:
sError = Utils.i18n('SETTINGS_THEMES/ERROR_FILE_TYPE_ERROR');
sError = Translator.i18n('SETTINGS_THEMES/ERROR_FILE_TYPE_ERROR');
break;
}
}
@ -148,7 +152,7 @@
sError = oData.ErrorMessage;
}
this.background.error(sError || Utils.i18n('SETTINGS_THEMES/ERROR_UNKNOWN'));
this.background.error(sError || Translator.i18n('SETTINGS_THEMES/ERROR_UNKNOWN'));
}
return true;