Code refactoring (4) (es5 -> es2015)

This commit is contained in:
RainLoop Team 2016-07-15 22:54:37 +03:00
parent e8df1cdb57
commit d7ab67a460
30 changed files with 164 additions and 173 deletions

View file

@ -1,5 +1,4 @@
/* global RL_COMMUNITY */
import window from 'window';
import _ from '_';
import $ from '$';

View file

@ -85,6 +85,15 @@ export function pBool(value)
return !!value;
}
/**
* @param {*} value
* @returns {string}
*/
export function boolToAjax(value)
{
return value ? '1' : '0';
}
/**
* @param {*} values
* @returns {boolean}

7
dev/External/ko.js vendored
View file

@ -1201,6 +1201,13 @@ ko.extenders.specialThrottle = function(oTarget, iOption)
return oTarget;
};
ko.extenders.idleTrigger = function(oTarget)
{
var Enums = require('Common/Enums');
oTarget.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
return oTarget;
};
// functions
ko.observable.fn.validateNone = function()

View file

@ -1,12 +1,20 @@
/* global RL_COMMUNITY */
import {addSettingsViewModel} from 'Knoin/Knoin';
import {runSettingsViewModelHooks} from 'Common/Plugins';
import {AbstractSettingsScreen} from 'Screen/AbstractSettings';
import App from 'App/Admin';
import {GeneralAdminSettings} from 'Settings/Admin/General';
import {LoginAdminSettings} from 'Settings/Admin/Login';
import {ContactsAdminSettings} from 'Settings/Admin/Contacts';
import {DomainsAdminSettings} from 'Settings/Admin/Domains';
import {SecurityAdminSettings} from 'Settings/Admin/Security';
import {SocialAdminSettings} from 'Settings/Admin/Social';
import {PluginsAdminSettings} from 'Settings/Admin/Plugins';
import {PackagesAdminSettings} from 'Settings/Admin/Packages';
// import {AboutAdminSettings} from 'Settings/Admin/About';
class SettingsAdminScreen extends AbstractSettingsScreen
{
constructor()
@ -21,49 +29,49 @@ class SettingsAdminScreen extends AbstractSettingsScreen
* @param {Function=} fCallback = null
*/
setupSettings(fCallback = null) {
addSettingsViewModel(require('Settings/Admin/General'),
addSettingsViewModel(GeneralAdminSettings,
'AdminSettingsGeneral', 'TABS_LABELS/LABEL_GENERAL_NAME', 'general', true);
addSettingsViewModel(require('Settings/Admin/Login'),
addSettingsViewModel(LoginAdminSettings,
'AdminSettingsLogin', 'TABS_LABELS/LABEL_LOGIN_NAME', 'login');
if (RL_COMMUNITY)
{
addSettingsViewModel(require('Settings/Admin/Branding'),
addSettingsViewModel(require('Settings/Admin/Branding').default,
'AdminSettingsBranding', 'TABS_LABELS/LABEL_BRANDING_NAME', 'branding');
}
else
{
addSettingsViewModel(require('Settings/Admin/Prem/Branding'),
addSettingsViewModel(require('Settings/Admin/Prem/Branding').default,
'AdminSettingsBranding', 'TABS_LABELS/LABEL_BRANDING_NAME', 'branding');
}
addSettingsViewModel(require('Settings/Admin/Contacts'),
addSettingsViewModel(ContactsAdminSettings,
'AdminSettingsContacts', 'TABS_LABELS/LABEL_CONTACTS_NAME', 'contacts');
addSettingsViewModel(require('Settings/Admin/Domains'),
addSettingsViewModel(DomainsAdminSettings,
'AdminSettingsDomains', 'TABS_LABELS/LABEL_DOMAINS_NAME', 'domains');
addSettingsViewModel(require('Settings/Admin/Security'),
addSettingsViewModel(SecurityAdminSettings,
'AdminSettingsSecurity', 'TABS_LABELS/LABEL_SECURITY_NAME', 'security');
addSettingsViewModel(require('Settings/Admin/Social'),
addSettingsViewModel(SocialAdminSettings,
'AdminSettingsSocial', 'TABS_LABELS/LABEL_INTEGRATION_NAME', 'integrations');
addSettingsViewModel(require('Settings/Admin/Plugins'),
addSettingsViewModel(PluginsAdminSettings,
'AdminSettingsPlugins', 'TABS_LABELS/LABEL_PLUGINS_NAME', 'plugins');
addSettingsViewModel(require('Settings/Admin/Packages'),
addSettingsViewModel(PackagesAdminSettings,
'AdminSettingsPackages', 'TABS_LABELS/LABEL_PACKAGES_NAME', 'packages');
if (!RL_COMMUNITY)
{
addSettingsViewModel(require('Settings/Admin/Prem/Licensing'),
addSettingsViewModel(require('Settings/Admin/Prem/Licensing').default,
'AdminSettingsLicensing', 'TABS_LABELS/LABEL_LICENSING_NAME', 'licensing');
}
addSettingsViewModel(require('Settings/Admin/About'),
'AdminSettingsAbout', 'TABS_LABELS/LABEL_ABOUT_NAME', 'about');
// addSettingsViewModel(AboutAdminSettings,
// 'AdminSettingsAbout', 'TABS_LABELS/LABEL_ABOUT_NAME', 'about');
runSettingsViewModelHooks(true);

View file

@ -13,6 +13,18 @@ import {addSettingsViewModel} from 'Knoin/Knoin';
import {AbstractSettingsScreen} from 'Screen/AbstractSettings';
import App from 'App/User';
import {GeneralUserSettings} from 'Settings/User/General';
import {ContactsUserSettings} from 'Settings/User/Contacts';
import {AccountsUserSettings} from 'Settings/User/Accounts';
import {FiltersUserSettings} from 'Settings/User/Filters';
import {SecurityUserSettings} from 'Settings/User/Security';
import {SocialUserSettings} from 'Settings/User/Social';
import {ChangePasswordUserSettings} from 'Settings/User/ChangePassword';
import {TemplatesUserSettings} from 'Settings/User/Templates';
import {FoldersUserSettings} from 'Settings/User/Folders';
import {ThemesUserSettings} from 'Settings/User/Themes';
import {OpenPgpUserSettings} from 'Settings/User/OpenPgp';
class SettingsUserScreen extends AbstractSettingsScreen
{
constructor()
@ -44,30 +56,30 @@ class SettingsUserScreen extends AbstractSettingsScreen
return false;
}
addSettingsViewModel(require('Settings/User/General'),
addSettingsViewModel(GeneralUserSettings,
'SettingsGeneral', 'SETTINGS_LABELS/LABEL_GENERAL_NAME', 'general', true);
if (AppStore.contactsIsAllowed())
{
addSettingsViewModel(require('Settings/User/Contacts'),
addSettingsViewModel(ContactsUserSettings,
'SettingsContacts', 'SETTINGS_LABELS/LABEL_CONTACTS_NAME', 'contacts');
}
if (Settings.capa(Capa.AdditionalAccounts) || Settings.capa(Capa.Identities))
{
addSettingsViewModel(require('Settings/User/Accounts'), 'SettingsAccounts',
addSettingsViewModel(AccountsUserSettings, 'SettingsAccounts',
Settings.capa(Capa.AdditionalAccounts) ? 'SETTINGS_LABELS/LABEL_ACCOUNTS_NAME' : 'SETTINGS_LABELS/LABEL_IDENTITIES_NAME', 'accounts');
}
if (Settings.capa(Capa.Sieve))
{
addSettingsViewModel(require('Settings/User/Filters'),
addSettingsViewModel(FiltersUserSettings,
'SettingsFilters', 'SETTINGS_LABELS/LABEL_FILTERS_NAME', 'filters');
}
if (Settings.capa(Capa.AutoLogout) || Settings.capa(Capa.TwoFactor))
{
addSettingsViewModel(require('Settings/User/Security'),
addSettingsViewModel(SecurityUserSettings,
'SettingsSecurity', 'SETTINGS_LABELS/LABEL_SECURITY_NAME', 'security');
}
@ -76,37 +88,37 @@ class SettingsUserScreen extends AbstractSettingsScreen
Settings.settingsGet('AllowFacebookSocial') ||
Settings.settingsGet('AllowTwitterSocial')))
{
addSettingsViewModel(require('Settings/User/Social'),
addSettingsViewModel(SocialUserSettings,
'SettingsSocial', 'SETTINGS_LABELS/LABEL_SOCIAL_NAME', 'social');
}
if (Settings.settingsGet('ChangePasswordIsAllowed'))
{
addSettingsViewModel(require('Settings/User/ChangePassword'),
addSettingsViewModel(ChangePasswordUserSettings,
'SettingsChangePassword', 'SETTINGS_LABELS/LABEL_CHANGE_PASSWORD_NAME', 'change-password');
}
if (Settings.capa(Capa.Templates))
{
addSettingsViewModel(require('Settings/User/Templates'),
addSettingsViewModel(TemplatesUserSettings,
'SettingsTemplates', 'SETTINGS_LABELS/LABEL_TEMPLATES_NAME', 'templates');
}
if (Settings.capa(Capa.Folders))
{
addSettingsViewModel(require('Settings/User/Folders'),
addSettingsViewModel(FoldersUserSettings,
'SettingsFolders', 'SETTINGS_LABELS/LABEL_FOLDERS_NAME', 'folders');
}
if (Settings.capa(Capa.Themes))
{
addSettingsViewModel(require('Settings/User/Themes'),
addSettingsViewModel(ThemesUserSettings,
'SettingsThemes', 'SETTINGS_LABELS/LABEL_THEMES_NAME', 'themes');
}
if (Settings.capa(Capa.OpenPGP))
{
addSettingsViewModel(require('Settings/User/OpenPgp'),
addSettingsViewModel(OpenPgpUserSettings,
'SettingsOpenPGP', 'SETTINGS_LABELS/LABEL_OPEN_PGP_NAME', 'openpgp');
}

View file

@ -1,6 +1,4 @@
/* global RL_COMMUNITY */
var
ko = require('ko'),
@ -91,4 +89,4 @@ AboutAdminSettings.prototype.updateCoreData = function()
}
};
module.exports = AboutAdminSettings;
export {AboutAdminSettings, AboutAdminSettings as default};

View file

@ -1,113 +0,0 @@
/* global RL_COMMUNITY */
var
_ = require('_'),
ko = require('ko'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator');
/**
* @constructor
*/
function BrandingAdminSettings()
{
var
Enums = require('Common/Enums'),
Settings = require('Storage/Settings'),
AppStore = require('Stores/Admin/App');
this.capa = AppStore.prem;
this.title = ko.observable(Settings.settingsGet('Title'));
this.title.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.loadingDesc = ko.observable(Settings.settingsGet('LoadingDescription'));
this.loadingDesc.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.faviconUrl = ko.observable(Settings.settingsGet('FaviconUrl'));
this.faviconUrl.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.loginLogo = ko.observable(Settings.settingsGet('LoginLogo') || '');
this.loginLogo.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.loginBackground = ko.observable(Settings.settingsGet('LoginBackground') || '');
this.loginBackground.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.userLogo = ko.observable(Settings.settingsGet('UserLogo') || '');
this.userLogo.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.userLogoMessage = ko.observable(Settings.settingsGet('UserLogoMessage') || '');
this.userLogoMessage.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.userIframeMessage = ko.observable(Settings.settingsGet('UserIframeMessage') || '');
this.userIframeMessage.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.userLogoTitle = ko.observable(Settings.settingsGet('UserLogoTitle') || '');
this.userLogoTitle.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.loginDescription = ko.observable(Settings.settingsGet('LoginDescription'));
this.loginDescription.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.loginCss = ko.observable(Settings.settingsGet('LoginCss'));
this.loginCss.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.userCss = ko.observable(Settings.settingsGet('UserCss'));
this.userCss.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.welcomePageUrl = ko.observable(Settings.settingsGet('WelcomePageUrl'));
this.welcomePageUrl.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.welcomePageDisplay = ko.observable(Settings.settingsGet('WelcomePageDisplay'));
this.welcomePageDisplay.trigger = ko.observable(Enums.SaveSettingsStep.Idle);
this.welcomePageDisplay.options = ko.computed(function() {
Translator.trigger();
return [
{'optValue': 'none', 'optText': Translator.i18n('TAB_BRANDING/OPTION_WELCOME_PAGE_DISPLAY_NONE')},
{'optValue': 'once', 'optText': Translator.i18n('TAB_BRANDING/OPTION_WELCOME_PAGE_DISPLAY_ONCE')},
{'optValue': 'always', 'optText': Translator.i18n('TAB_BRANDING/OPTION_WELCOME_PAGE_DISPLAY_ALWAYS')}
];
});
this.loginPowered = ko.observable(!!Settings.settingsGet('LoginPowered'));
this.community = RL_COMMUNITY || AppStore.community();
}
BrandingAdminSettings.prototype.onBuild = function()
{
var
self = this,
Remote = require('Remote/Admin/Ajax');
_.delay(function() {
var
f1 = Utils.settingsSaveHelperSimpleFunction(self.title.trigger, self),
f2 = Utils.settingsSaveHelperSimpleFunction(self.loadingDesc.trigger, self),
f3 = Utils.settingsSaveHelperSimpleFunction(self.faviconUrl.trigger, self);
self.title.subscribe(function(sValue) {
Remote.saveAdminConfig(f1, {
'Title': Utils.trim(sValue)
});
});
self.loadingDesc.subscribe(function(sValue) {
Remote.saveAdminConfig(f2, {
'LoadingDescription': Utils.trim(sValue)
});
});
self.faviconUrl.subscribe(function(sValue) {
Remote.saveAdminConfig(f3, {
'FaviconUrl': Utils.trim(sValue)
});
});
}, 50);
};
module.exports = BrandingAdminSettings;

View file

@ -0,0 +1,74 @@
import _ from '_';
import ko from 'ko';
import {settingsSaveHelperSimpleFunction, trim} from 'Common/Utils';
import {i18n, trigger as translatorTrigger} from 'Common/Translator';
import {settingsGet} from 'Storage/Settings';
class BrandingAdminSettings
{
constructor()
{
const AppStore = require('Stores/Admin/App');
this.capa = AppStore.prem;
this.title = ko.observable(settingsGet('Title')).extend({idleTrigger: true});
this.loadingDesc = ko.observable(settingsGet('LoadingDescription')).extend({idleTrigger: true});
this.faviconUrl = ko.observable(settingsGet('FaviconUrl')).extend({idleTrigger: true});
this.loginLogo = ko.observable(settingsGet('LoginLogo') || '').extend({idleTrigger: true});
this.loginBackground = ko.observable(settingsGet('LoginBackground') || '').extend({idleTrigger: true});
this.userLogo = ko.observable(settingsGet('UserLogo') || '').extend({idleTrigger: true});
this.userLogoMessage = ko.observable(settingsGet('UserLogoMessage') || '').extend({idleTrigger: true});
this.userIframeMessage = ko.observable(settingsGet('UserIframeMessage') || '').extend({idleTrigger: true});
this.userLogoTitle = ko.observable(settingsGet('UserLogoTitle') || '').extend({idleTrigger: true});
this.loginDescription = ko.observable(settingsGet('LoginDescription')).extend({idleTrigger: true});
this.loginCss = ko.observable(settingsGet('LoginCss')).extend({idleTrigger: true});
this.userCss = ko.observable(settingsGet('UserCss')).extend({idleTrigger: true});
this.welcomePageUrl = ko.observable(settingsGet('WelcomePageUrl')).extend({idleTrigger: true});
this.welcomePageDisplay = ko.observable(settingsGet('WelcomePageDisplay')).extend({idleTrigger: true});
this.welcomePageDisplay.options = ko.computed(() => {
translatorTrigger();
return [
{'optValue': 'none', 'optText': i18n('TAB_BRANDING/OPTION_WELCOME_PAGE_DISPLAY_NONE')},
{'optValue': 'once', 'optText': i18n('TAB_BRANDING/OPTION_WELCOME_PAGE_DISPLAY_ONCE')},
{'optValue': 'always', 'optText': i18n('TAB_BRANDING/OPTION_WELCOME_PAGE_DISPLAY_ALWAYS')}
];
});
this.loginPowered = ko.observable(!!settingsGet('LoginPowered'));
this.community = RL_COMMUNITY || AppStore.community();
}
onBuild() {
_.delay(() => {
const
Remote = require('Remote/Admin/Ajax'),
f1 = settingsSaveHelperSimpleFunction(this.title.trigger, this),
f2 = settingsSaveHelperSimpleFunction(this.loadingDesc.trigger, this),
f3 = settingsSaveHelperSimpleFunction(this.faviconUrl.trigger, this);
this.title.subscribe((value) => {
Remote.saveAdminConfig(f1, {
'Title': trim(value)
});
});
this.loadingDesc.subscribe((value) => {
Remote.saveAdminConfig(f2, {
'LoadingDescription': trim(value)
});
});
this.faviconUrl.subscribe((value) => {
Remote.saveAdminConfig(f3, {
'FaviconUrl': trim(value)
});
});
}, 50);
}
}
export {BrandingAdminSettings, BrandingAdminSettings as default};

View file

@ -231,4 +231,4 @@ ContactsAdminSettings.prototype.onBuild = function()
}, 50);
};
module.exports = ContactsAdminSettings;
export {ContactsAdminSettings, ContactsAdminSettings as default};

View file

@ -75,4 +75,4 @@ DomainsAdminSettings.prototype.onDomainListChangeRequest = function()
require('App/Admin').default.reloadDomainList();
};
module.exports = DomainsAdminSettings;
export {DomainsAdminSettings, DomainsAdminSettings as default};

View file

@ -199,4 +199,4 @@ GeneralAdminSettings.prototype.phpInfoLink = function()
return Links.phpInfo();
};
module.exports = GeneralAdminSettings;
export {GeneralAdminSettings, GeneralAdminSettings as default};

View file

@ -63,4 +63,4 @@ LoginAdminSettings.prototype.onBuild = function()
}, 50);
};
module.exports = LoginAdminSettings;
export {LoginAdminSettings, LoginAdminSettings as default};

View file

@ -103,4 +103,4 @@ PackagesAdminSettings.prototype.installPackage = function(oPackage)
}
};
module.exports = PackagesAdminSettings;
export {PackagesAdminSettings, PackagesAdminSettings as default};

View file

@ -1,6 +1,4 @@
/* global RL_COMMUNITY */
var
_ = require('_'),
ko = require('ko'),
@ -108,4 +106,4 @@ PluginsAdminSettings.prototype.onPluginDisableRequest = function(sResult, oData)
require('App/Admin').default.reloadPluginList();
};
module.exports = PluginsAdminSettings;
export {PluginsAdminSettings, PluginsAdminSettings as default};

View file

@ -179,4 +179,4 @@ SecurityAdminSettings.prototype.phpInfoLink = function()
return Links.phpInfo();
};
module.exports = SecurityAdminSettings;
export {SecurityAdminSettings, SecurityAdminSettings as default};

View file

@ -171,4 +171,4 @@ SocialAdminSettings.prototype.onBuild = function()
}, 50);
};
module.exports = SocialAdminSettings;
export {SocialAdminSettings, SocialAdminSettings as default};

View file

@ -151,4 +151,4 @@ AccountsUserSettings.prototype.onBuild = function(oDom)
});
};
module.exports = AccountsUserSettings;
export {AccountsUserSettings, AccountsUserSettings as default};

View file

@ -114,4 +114,4 @@ ChangePasswordUserSettings.prototype.onChangePasswordResponse = function(sResult
}
};
module.exports = ChangePasswordUserSettings;
export {ChangePasswordUserSettings, ChangePasswordUserSettings as default};

View file

@ -48,4 +48,4 @@ ContactsUserSettings.prototype.onBuild = function()
}, this);
};
module.exports = ContactsUserSettings;
export {ContactsUserSettings, ContactsUserSettings as default};

View file

@ -231,4 +231,4 @@ FiltersUserSettings.prototype.onShow = function()
this.updateList();
};
module.exports = FiltersUserSettings;
export {FiltersUserSettings, FiltersUserSettings as default};

View file

@ -189,4 +189,4 @@ FoldersUserSettings.prototype.checkableFalseFolder = function(oFolder)
oFolder.checkable(false);
};
module.exports = FoldersUserSettings;
export {FoldersUserSettings, FoldersUserSettings as default};

View file

@ -221,4 +221,4 @@ GeneralUserSettings.prototype.selectLanguage = function()
]);
};
module.exports = GeneralUserSettings;
export {GeneralUserSettings, GeneralUserSettings as default};

View file

@ -73,4 +73,4 @@ OpenPgpUserSettings.prototype.deleteOpenPgpKey = function(oOpenPgpKeyToRemove)
}
};
module.exports = OpenPgpUserSettings;
export {OpenPgpUserSettings, OpenPgpUserSettings as default};

View file

@ -65,4 +65,4 @@ SecurityUserSettings.prototype.onBuild = function()
}
};
module.exports = SecurityUserSettings;
export {SecurityUserSettings, SecurityUserSettings as default};

View file

@ -70,4 +70,4 @@ function SocialUserSettings()
});
}
module.exports = SocialUserSettings;
export {SocialUserSettings, SocialUserSettings as default};

View file

@ -95,4 +95,4 @@ TemplatesUserSettings.prototype.onBuild = function(oDom)
this.reloadTemplates();
};
module.exports = TemplatesUserSettings;
export {TemplatesUserSettings, TemplatesUserSettings as default};

View file

@ -174,4 +174,4 @@ ThemesUserSettings.prototype.initUploader = function()
}
};
module.exports = ThemesUserSettings;
export {ThemesUserSettings, ThemesUserSettings as default};

View file

@ -1,7 +1,6 @@
import ko from 'ko';
import * as Settings from 'Storage/Settings';
import {settingsGet} from 'Storage/Settings';
import {AbstractAppStore} from 'Stores/AbstractApp';
class AppAdminStore extends AbstractAppStore
@ -18,14 +17,13 @@ class AppAdminStore extends AbstractAppStore
}
populate() {
super.populate();
this.determineUserLanguage(!!Settings.settingsGet('DetermineUserLanguage'));
this.determineUserDomain(!!Settings.settingsGet('DetermineUserDomain'));
this.determineUserLanguage(!!settingsGet('DetermineUserLanguage'));
this.determineUserDomain(!!settingsGet('DetermineUserDomain'));
this.weakPassword(!!Settings.settingsGet('WeakPassword'));
this.useLocalProxyForExternalImages(!!Settings.settingsGet('UseLocalProxyForExternalImages'));
this.weakPassword(!!settingsGet('WeakPassword'));
this.useLocalProxyForExternalImages(!!settingsGet('UseLocalProxyForExternalImages'));
}
}

View file

@ -1,6 +1,4 @@
/* global RL_COMMUNITY */
var
_ = require('_'),
ko = require('ko'),

View file

@ -665,6 +665,7 @@ gulp.task('rainloop:owncloud:shortname', ['rainloop:owncloud:md5'], function(cal
gulp.task('js:pgp', ['js:openpgp', 'js:openpgpworker']);
gulp.task('default', ['js:libs', 'js:pgp', 'js:min', 'css:min', 'ckeditor', 'fontastic']);
gulp.task('default+', ['package:community-off', 'default']);
gulp.task('fast-', ['js:app', 'js:admin', 'css:main']);
gulp.task('fast', ['package:community-on', 'fast-']);
@ -708,6 +709,8 @@ gulp.task('build+', ['rainloop+']);
gulp.task('js:v', ['js:validate']);
gulp.task('v', ['js:v']);
gulp.task('d', ['default']);
gulp.task('d+', ['default+']);
gulp.task('w', ['watch']);
gulp.task('w+', ['watch+']);
gulp.task('f', ['fast']);