Code refactoring (3) (es5 -> es2015)

This commit is contained in:
RainLoop Team 2016-07-08 02:22:58 +03:00
parent 739ed215ea
commit e49f3c6692
11 changed files with 619 additions and 571 deletions

View file

@ -10,19 +10,24 @@ import {
sUserAgent, bMobileDevice, bAnimationSupported
} from 'Common/Globals';
import {
noop, isNormal, pString, inArray, microtime, timestamp,
detectDropdownVisibility, windowResizeCallback
} from 'Common/Utils';
import {KeyState} from 'Common/Enums';
import {noop, isNormal, pString, inArray, microtime, timestamp, detectDropdownVisibility, windowResizeCallback} from 'Common/Utils';
import * as Links from 'Common/Links';
import * as Settings from 'Storage/Settings';
import * as Events from 'Common/Events';
import {initOnStartOrLangChange, initNotificationLanguage} from 'Common/Translator';
import {toggle as toggleCmd} from 'Common/Cmd';
import {routeOff, setHash} from 'Knoin/Knoin';
import {AbstractBoot} from 'Knoin/AbstractBoot';
class AbstractApp extends AbstractBoot
{
/**
* @constructor
* @param {RemoteStorage|AdminRemoteStorage} Remote
*/
constructor(Remote)
@ -62,13 +67,12 @@ class AbstractApp extends AbstractBoot
}
});
$win.on('resize', function() {
$win.on('resize', () => {
Events.pub('window.resize');
});
Events.sub('window.resize', _.throttle(function() {
var
Events.sub('window.resize', _.throttle(() => {
const
iH = $win.height(),
iW = $win.height();
@ -79,7 +83,6 @@ class AbstractApp extends AbstractBoot
Events.pub('window.resize.real');
}
}, 50));
// DEBUG
@ -92,25 +95,29 @@ class AbstractApp extends AbstractBoot
// }
// });
$doc.on('keydown', function(oEvent) {
if (oEvent && oEvent.ctrlKey)
$doc.on('keydown', (event) => {
if (event && event.ctrlKey)
{
$html.addClass('rl-ctrl-key-pressed');
}
}).on('keyup', function(oEvent) {
if (oEvent && !oEvent.ctrlKey)
}).on('keyup', (event) => {
if (event && !event.ctrlKey)
{
$html.removeClass('rl-ctrl-key-pressed');
}
});
$doc.on('mousemove keypress click', _.debounce(function() {
$doc.on('mousemove keypress click', _.debounce(() => {
Events.pub('rl.auto-logout-refresh');
}, 5000));
key('esc, enter', KeyState.All, _.bind(function() {
key('esc, enter', KeyState.All, () => {
detectDropdownVisibility();
}, this));
});
key('ctrl+shift+`', KeyState.All, () => {
toggleCmd();
});
}
remote() {
@ -223,7 +230,6 @@ class AbstractApp extends AbstractBoot
loginAndLogoutReload(admin = false, logout = false, close = false) {
const
kn = require('Knoin/Knoin'),
mobile = Settings.appSettingsGet('mobile'),
inIframe = !!Settings.appSettingsGet('inIframe');
@ -256,9 +262,9 @@ class AbstractApp extends AbstractBoot
}
else
{
kn.routeOff();
kn.setHash(Links.root(), true);
kn.routeOff();
routeOff();
setHash(Links.root(), true);
routeOff();
_.delay(() => {
if (inIframe && window.parent)

View file

@ -22,8 +22,7 @@ import Remote from 'Remote/Admin/Ajax';
import {SettingsAdminScreen} from 'Screen/Admin/Settings';
import {LoginAdminScreen} from 'Screen/Admin/Login';
import kn from 'Knoin/Knoin';
import {hideLoading, routeOff, setHash, startScreens} from 'Knoin/Knoin';
import {AbstractApp} from 'App/Abstract';
class AdminApp extends AbstractApp
@ -222,13 +221,13 @@ class AdminApp extends AbstractApp
require('Stores/Admin/App').populate();
require('Stores/Admin/Capa').populate();
kn.hideLoading();
hideLoading();
if (!Settings.appSettingsGet('allowAdminPanel'))
{
kn.routeOff();
kn.setHash(Links.root(), true);
kn.routeOff();
routeOff();
setHash(Links.root(), true);
routeOff();
_.defer(() => {
window.location.href = '/';
@ -238,13 +237,13 @@ class AdminApp extends AbstractApp
{
if (Settings.settingsGet('Auth'))
{
kn.startScreens([
startScreens([
SettingsAdminScreen
]);
}
else
{
kn.startScreens([
startScreens([
LoginAdminScreen
]);
}

View file

@ -57,7 +57,10 @@ import {LoginUserScreen} from 'Screen/User/Login';
import {MailBoxUserScreen} from 'Screen/User/MailBox';
import {SettingsUserScreen} from 'Screen/User/Settings';
import kn from 'Knoin/Knoin';
import {
hideLoading, routeOff, routeOn, setHash,
startScreens, showScreenPopup
} from 'Knoin/Knoin';
import {AbstractApp} from 'App/Abstract';
@ -166,7 +169,7 @@ class AppUser extends AbstractApp
MessageStore.messageListPageBeforeThread(1);
iOffset = 0;
kn.setHash(Links.mailBox(
setHash(Links.mailBox(
FolderStore.currentFolderFullNameHash(),
MessageStore.messageListPage(),
MessageStore.messageListSearch(),
@ -364,12 +367,12 @@ class AppUser extends AbstractApp
if (!oMoveFolder && bUseFolder)
{
kn.showScreenPopup(require('View/Popup/FolderSystem'), [nSetSystemFoldersNotification]);
showScreenPopup(require('View/Popup/FolderSystem'), [nSetSystemFoldersNotification]);
}
else if (!bUseFolder || (FolderType.Trash === iDeleteType &&
(sFromFolderFullNameRaw === FolderStore.spamFolder() || sFromFolderFullNameRaw === FolderStore.trashFolder())))
{
kn.showScreenPopup(require('View/Popup/Ask'), [i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'), () => {
showScreenPopup(require('View/Popup/Ask'), [i18n('POPUPS_ASK/DESC_WANT_DELETE_MESSAGES'), () => {
this.messagesDeleteHelper(sFromFolderFullNameRaw, aUidForRemove);
MessageStore.removeMessagesFromList(sFromFolderFullNameRaw, aUidForRemove);
}]);
@ -1200,11 +1203,11 @@ class AppUser extends AbstractApp
}
bootstartTwoFactorScreen() {
kn.showScreenPopup(require('View/Popup/TwoFactorConfiguration'), [true]);
showScreenPopup(require('View/Popup/TwoFactorConfiguration'), [true]);
}
bootstartWelcomePopup(url) {
kn.showScreenPopup(require('View/Popup/WelcomePage'), [url]);
showScreenPopup(require('View/Popup/WelcomePage'), [url]);
}
bootstartLoginScreen() {
@ -1214,7 +1217,7 @@ class AppUser extends AbstractApp
const customLoginLink = pString(Settings.appSettingsGet('customLoginLink'));
if (!customLoginLink)
{
kn.startScreens([
startScreens([
LoginUserScreen
]);
@ -1223,9 +1226,9 @@ class AppUser extends AbstractApp
}
else
{
kn.routeOff();
kn.setHash(Links.root(), true);
kn.routeOff();
routeOff();
setHash(Links.root(), true);
routeOff();
_.defer(function() {
window.location.href = customLoginLink;
@ -1236,14 +1239,9 @@ class AppUser extends AbstractApp
bootend() {
if (progressJs)
{
kn.hideLoading();
progressJs.set(100).end();
}
else
{
kn.hideLoading();
}
hideLoading();
}
bootstart() {
@ -1299,9 +1297,9 @@ class AppUser extends AbstractApp
{
if ('' !== sStartupUrl)
{
kn.routeOff();
kn.setHash(Links.root(sStartupUrl), true);
kn.routeOn();
routeOff();
setHash(Links.root(sStartupUrl), true);
routeOn();
}
if (window.jassl && window.crypto && window.crypto.getRandomValues && Settings.capa(Capa.OpenPGP))
@ -1349,7 +1347,7 @@ class AppUser extends AbstractApp
PgpStore.capaOpenPGP(false);
}
kn.startScreens([
startScreens([
MailBoxUserScreen,
Settings.capa(Capa.Settings) ? SettingsUserScreen : null
// false ? AboutUserScreen : null
@ -1442,7 +1440,6 @@ class AppUser extends AbstractApp
{
this.logout();
}
});
// }); // require code splitting