2013-11-16 06:21:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
import {window, _, $, key} from 'common';
|
|
|
|
import Globals from 'Common/Globals';
|
|
|
|
import * as Enums from 'Common/Enums';
|
|
|
|
import Utils from 'Common/Utils';
|
|
|
|
import Links from 'Common/Links';
|
|
|
|
import Events from 'Common/Events';
|
|
|
|
import Translator from 'Common/Translator';
|
|
|
|
import Settings from 'Storage/Settings';
|
|
|
|
|
|
|
|
import {AbstractBoot} from 'Knoin/AbstractBoot';
|
|
|
|
|
|
|
|
class AbstractApp extends AbstractBoot
|
|
|
|
{
|
|
|
|
googlePreviewSupportedCache = null;
|
|
|
|
isLocalAutocomplete = true;
|
|
|
|
iframe = null;
|
2014-05-30 09:42:22 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2014-09-02 08:15:31 +08:00
|
|
|
* @param {RemoteStorage|AdminRemoteStorage} Remote
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
constructor(Remote)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
super();
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
this.iframe = $('<iframe style="display:none" src="javascript:;" />').appendTo('body');
|
|
|
|
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$win.on('error', function (oEvent) {
|
2014-08-20 23:03:12 +08:00
|
|
|
if (oEvent && oEvent.originalEvent && oEvent.originalEvent.message &&
|
|
|
|
-1 === Utils.inArray(oEvent.originalEvent.message, [
|
|
|
|
'Script error.', 'Uncaught Error: Error calling method on NPObject.'
|
|
|
|
]))
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-22 23:08:56 +08:00
|
|
|
Remote.jsError(
|
2014-08-20 23:03:12 +08:00
|
|
|
Utils.emptyFunction,
|
|
|
|
oEvent.originalEvent.message,
|
|
|
|
oEvent.originalEvent.filename,
|
|
|
|
oEvent.originalEvent.lineno,
|
|
|
|
window.location && window.location.toString ? window.location.toString() : '',
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.attr('class'),
|
2015-04-02 02:18:15 +08:00
|
|
|
Utils.microtime() - Globals.startMicrotime
|
2014-08-20 23:03:12 +08:00
|
|
|
);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
|
|
|
|
2015-02-12 05:39:27 +08:00
|
|
|
Globals.$win.on('resize', function () {
|
|
|
|
Events.pub('window.resize');
|
|
|
|
});
|
|
|
|
|
|
|
|
Events.sub('window.resize', _.throttle(function () {
|
|
|
|
|
|
|
|
var
|
|
|
|
iH = Globals.$win.height(),
|
|
|
|
iW = Globals.$win.height()
|
|
|
|
;
|
|
|
|
|
|
|
|
if (Globals.$win.__sizes[0] !== iH || Globals.$win.__sizes[1] !== iW)
|
|
|
|
{
|
|
|
|
Globals.$win.__sizes[0] = iH;
|
|
|
|
Globals.$win.__sizes[1] = iW;
|
|
|
|
|
|
|
|
Events.pub('window.resize.real');
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 50));
|
|
|
|
|
2015-04-14 02:45:09 +08:00
|
|
|
// DEBUG
|
2015-02-12 05:39:27 +08:00
|
|
|
// Events.sub({
|
|
|
|
// 'window.resize': function () {
|
|
|
|
// window.console.log('window.resize');
|
|
|
|
// },
|
|
|
|
// 'window.resize.real': function () {
|
|
|
|
// window.console.log('window.resize.real');
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$doc.on('keydown', function (oEvent) {
|
2014-08-20 23:03:12 +08:00
|
|
|
if (oEvent && oEvent.ctrlKey)
|
|
|
|
{
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.addClass('rl-ctrl-key-pressed');
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
}).on('keyup', function (oEvent) {
|
|
|
|
if (oEvent && !oEvent.ctrlKey)
|
|
|
|
{
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.removeClass('rl-ctrl-key-pressed');
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
});
|
2015-02-19 03:52:52 +08:00
|
|
|
|
|
|
|
Globals.$doc.on('mousemove keypress click', _.debounce(function () {
|
|
|
|
Events.pub('rl.auto-logout-refresh');
|
|
|
|
}, 5000));
|
2015-03-16 05:58:50 +08:00
|
|
|
|
|
|
|
key('esc, enter', Enums.KeyState.All, _.bind(function () {
|
|
|
|
Utils.detectDropdownVisibility();
|
|
|
|
}, this));
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
remote() {
|
2014-08-22 23:08:56 +08:00
|
|
|
return null;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
data() {
|
2014-08-22 23:08:56 +08:00
|
|
|
return null;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-22 23:08:56 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} link
|
2014-08-20 23:03:12 +08:00
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
download(link) {
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-08-27 02:04:50 +08:00
|
|
|
if (Globals.sUserAgent && (Globals.sUserAgent.indexOf('chrome') > -1 || Globals.sUserAgent.indexOf('chrome') > -1))
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
const oLink = window.document.createElement('a');
|
|
|
|
oLink['href'] = link;
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
if (window.document['createEvent'])
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
const oE = window.document['createEvent']('MouseEvents');
|
2014-08-20 23:03:12 +08:00
|
|
|
if (oE && oE['initEvent'] && oLink['dispatchEvent'])
|
|
|
|
{
|
|
|
|
oE['initEvent']('click', true, true);
|
|
|
|
oLink['dispatchEvent'](oE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Globals.bMobileDevice)
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
window.open(link, '_self');
|
2014-08-20 23:03:12 +08:00
|
|
|
window.focus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
this.iframe.attr('src', link);
|
|
|
|
// window.document.location.href = link;
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-10-31 04:09:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
googlePreviewSupported() {
|
2014-10-31 04:09:53 +08:00
|
|
|
if (null === this.googlePreviewSupportedCache)
|
|
|
|
{
|
|
|
|
this.googlePreviewSupportedCache = !!Settings.settingsGet('AllowGoogleSocial') &&
|
|
|
|
!!Settings.settingsGet('AllowGoogleSocialPreview');
|
|
|
|
}
|
2014-11-01 01:25:02 +08:00
|
|
|
|
2014-10-31 04:09:53 +08:00
|
|
|
return this.googlePreviewSupportedCache;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-10-31 04:09:53 +08:00
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} title
|
2014-09-02 08:15:31 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
setWindowTitle(title) {
|
|
|
|
title = ((Utils.isNormal(title) && 0 < title.length) ? '' + title : '');
|
2015-10-15 02:28:58 +08:00
|
|
|
if (Settings.settingsGet('Title'))
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
title += (title ? ' - ' : '') + Settings.settingsGet('Title');
|
2015-10-15 02:28:58 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
window.document.title = title + ' ...';
|
|
|
|
window.document.title = title;
|
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
redirectToAdminPanel() {
|
|
|
|
_.delay(() => window.location.href = Links.rootAdmin(), 100);
|
|
|
|
}
|
2014-10-03 04:22:06 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
clearClientSideToken() {
|
2014-10-06 02:37:31 +08:00
|
|
|
if (window.__rlah_clear)
|
|
|
|
{
|
|
|
|
window.__rlah_clear();
|
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-10-06 02:37:31 +08:00
|
|
|
|
2015-05-06 00:41:15 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} key
|
2015-05-06 00:41:15 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
setClientSideToken(key) {
|
2015-05-06 00:41:15 +08:00
|
|
|
if (window.__rlah_set)
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
window.__rlah_set(key);
|
2015-05-06 00:41:15 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
require('Storage/Settings').settingsSet('AuthAccountHash', key);
|
2015-05-06 00:41:15 +08:00
|
|
|
require('Common/Links').populateAuthSuffix();
|
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2015-05-06 00:41:15 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {boolean=} admin = false
|
|
|
|
* @param {boolean=} logout = false
|
|
|
|
* @param {boolean=} close = false
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
loginAndLogoutReload(admin = false, logout = false, close = false) {
|
|
|
|
|
|
|
|
const
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
2015-11-19 01:32:29 +08:00
|
|
|
inIframe = !!Settings.settingsGet('InIframe')
|
2014-08-20 23:03:12 +08:00
|
|
|
;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
let customLogoutLink = Utils.pString(Settings.settingsGet('CustomLogoutLink'))
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
if (logout)
|
2014-10-06 02:37:31 +08:00
|
|
|
{
|
|
|
|
this.clearClientSideToken();
|
|
|
|
}
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
if (logout && close && window.close)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
window.close();
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
customLogoutLink = customLogoutLink || (admin ? Links.rootAdmin() : Links.rootUser());
|
2015-03-28 06:06:56 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
if (logout && window.location.href !== customLogoutLink)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
_.delay(() => {
|
|
|
|
if (inIframe && window.parent)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
window.parent.location.href = customLogoutLink;
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-19 01:32:29 +08:00
|
|
|
window.location.href = customLogoutLink;
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kn.routeOff();
|
2015-05-18 04:38:20 +08:00
|
|
|
kn.setHash(Links.root(), true);
|
2014-08-20 23:03:12 +08:00
|
|
|
kn.routeOff();
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
_.delay(() => {
|
|
|
|
if (inIframe && window.parent)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
window.parent.location.reload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
historyBack() {
|
2014-08-20 23:03:12 +08:00
|
|
|
window.history.back();
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
bootstart() {
|
|
|
|
|
|
|
|
// Utils.log('Ps' + 'ss, hac' + 'kers! The' + 're\'s not' + 'hing inte' + 'resting :' + ')');
|
2015-07-30 02:13:49 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
Events.pub('rl.bootstart');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
const
|
2014-10-29 06:05:50 +08:00
|
|
|
ssm = require('ssm'),
|
|
|
|
ko = require('ko')
|
|
|
|
;
|
|
|
|
|
2014-10-30 05:08:53 +08:00
|
|
|
ko.components.register('SaveTrigger', require('Component/SaveTrigger'));
|
|
|
|
ko.components.register('Input', require('Component/Input'));
|
|
|
|
ko.components.register('Select', require('Component/Select'));
|
|
|
|
ko.components.register('Radio', require('Component/Radio'));
|
2015-07-30 02:13:49 +08:00
|
|
|
ko.components.register('TextArea', require('Component/TextArea'));
|
2014-10-30 05:08:53 +08:00
|
|
|
|
2015-04-02 02:18:15 +08:00
|
|
|
ko.components.register('x-script', require('Component/Script'));
|
2015-07-30 02:13:49 +08:00
|
|
|
ko.components.register('svg-icon', require('Component/SvgIcon'));
|
2015-04-02 02:18:15 +08:00
|
|
|
|
2015-04-25 21:50:10 +08:00
|
|
|
if (/**false && /**/Settings.settingsGet('MaterialDesign') && Globals.bAnimationSupported)
|
2014-10-30 05:08:53 +08:00
|
|
|
{
|
|
|
|
ko.components.register('Checkbox', require('Component/MaterialDesign/Checkbox'));
|
2015-04-25 21:50:10 +08:00
|
|
|
ko.components.register('CheckboxSimple', require('Component/Checkbox'));
|
2014-10-30 05:08:53 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-06 03:40:20 +08:00
|
|
|
// ko.components.register('Checkbox', require('Component/Classic/Checkbox'));
|
2015-04-25 21:50:10 +08:00
|
|
|
// ko.components.register('CheckboxSimple', require('Component/Classic/Checkbox'));
|
2014-10-30 05:08:53 +08:00
|
|
|
ko.components.register('Checkbox', require('Component/Checkbox'));
|
2015-04-25 21:50:10 +08:00
|
|
|
ko.components.register('CheckboxSimple', require('Component/Checkbox'));
|
2014-10-30 05:08:53 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator.initOnStartOrLangChange(Translator.initNotificationLanguage, Translator);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-01-20 05:20:12 +08:00
|
|
|
_.delay(Utils.windowResizeCallback, 1000);
|
2014-08-20 23:03:12 +08:00
|
|
|
|
|
|
|
ssm.addState({
|
|
|
|
'id': 'mobile',
|
|
|
|
'maxWidth': 767,
|
2015-11-19 01:32:29 +08:00
|
|
|
'onEnter': () => {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.addClass('ssm-state-mobile');
|
2014-08-22 23:08:56 +08:00
|
|
|
Events.pub('ssm.mobile-enter');
|
2014-08-20 23:03:12 +08:00
|
|
|
},
|
2015-11-19 01:32:29 +08:00
|
|
|
'onLeave': () => {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.removeClass('ssm-state-mobile');
|
2014-08-22 23:08:56 +08:00
|
|
|
Events.pub('ssm.mobile-leave');
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
2013-12-13 07:23:47 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
ssm.addState({
|
|
|
|
'id': 'tablet',
|
|
|
|
'minWidth': 768,
|
|
|
|
'maxWidth': 999,
|
|
|
|
'onEnter': function() {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.addClass('ssm-state-tablet');
|
2014-08-20 23:03:12 +08:00
|
|
|
},
|
|
|
|
'onLeave': function() {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.removeClass('ssm-state-tablet');
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
});
|
2013-12-13 07:23:47 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
ssm.addState({
|
|
|
|
'id': 'desktop',
|
|
|
|
'minWidth': 1000,
|
|
|
|
'maxWidth': 1400,
|
2015-11-19 01:32:29 +08:00
|
|
|
'onEnter': () => {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.addClass('ssm-state-desktop');
|
2014-08-20 23:03:12 +08:00
|
|
|
},
|
2015-11-19 01:32:29 +08:00
|
|
|
'onLeave': () => {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.removeClass('ssm-state-desktop');
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
});
|
2013-12-13 07:23:47 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
ssm.addState({
|
|
|
|
'id': 'desktop-large',
|
|
|
|
'minWidth': 1400,
|
2015-11-19 01:32:29 +08:00
|
|
|
'onEnter': () => {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.addClass('ssm-state-desktop-large');
|
2014-08-20 23:03:12 +08:00
|
|
|
},
|
2015-11-19 01:32:29 +08:00
|
|
|
'onLeave': () => {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.removeClass('ssm-state-desktop-large');
|
2013-12-13 07:23:47 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
Events.sub('ssm.mobile-enter', () => {
|
2014-08-22 23:08:56 +08:00
|
|
|
Globals.leftPanelDisabled(true);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
2013-12-30 05:13:35 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
Events.sub('ssm.mobile-leave', () => {
|
2014-08-22 23:08:56 +08:00
|
|
|
Globals.leftPanelDisabled(false);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
Globals.leftPanelDisabled.subscribe((bValue) => {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.toggleClass('rl-left-panel-disabled', bValue);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
2014-04-27 08:54:22 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
Globals.leftPanelType.subscribe((sValue) => {
|
2015-05-20 06:05:54 +08:00
|
|
|
Globals.$html.toggleClass('rl-left-panel-none', 'none' === sValue);
|
|
|
|
Globals.$html.toggleClass('rl-left-panel-short', 'short' === sValue);
|
|
|
|
});
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
ssm.ready();
|
2015-01-27 05:06:00 +08:00
|
|
|
|
|
|
|
require('Stores/Language').populate();
|
|
|
|
require('Stores/Theme').populate();
|
|
|
|
require('Stores/Social').populate();
|
2014-08-20 23:03:12 +08:00
|
|
|
};
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-04-27 08:54:22 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
export {AbstractApp, AbstractApp as default};
|