2013-11-16 06:21:12 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-08-25 23:49:01 +08:00
|
|
|
|
|
|
|
'use strict';
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-05-30 09:42:22 +08:00
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
window = require('window'),
|
2014-09-02 08:15:31 +08:00
|
|
|
_ = require('_'),
|
|
|
|
$ = require('$'),
|
2015-03-16 05:58:50 +08:00
|
|
|
key = require('key'),
|
2014-08-25 23:49:01 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Globals = require('Common/Globals'),
|
2015-03-16 05:58:50 +08:00
|
|
|
Enums = require('Common/Enums'),
|
2014-09-05 06:49:03 +08:00
|
|
|
Utils = require('Common/Utils'),
|
2014-10-06 02:37:31 +08:00
|
|
|
Links = require('Common/Links'),
|
2014-09-05 06:49:03 +08:00
|
|
|
Events = require('Common/Events'),
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator = require('Common/Translator'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
Settings = require('Storage/Settings'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractBoot = require('Knoin/AbstractBoot')
|
2013-11-16 06:21:12 +08:00
|
|
|
;
|
2014-05-30 09:42:22 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
2014-09-02 08:15:31 +08:00
|
|
|
* @param {RemoteStorage|AdminRemoteStorage} Remote
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractBoot
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2014-08-22 23:08:56 +08:00
|
|
|
function AbstractApp(Remote)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractBoot.call(this);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
this.isLocalAutocomplete = true;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
_.extend(AbstractApp.prototype, AbstractBoot.prototype);
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
AbstractApp.prototype.remote = function ()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
AbstractApp.prototype.data = function ()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
|
|
|
* @param {string} sLink
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.download = function (sLink)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
var
|
|
|
|
oE = null,
|
|
|
|
oLink = null,
|
|
|
|
sUserAgent = window.navigator.userAgent.toLowerCase()
|
|
|
|
;
|
|
|
|
|
|
|
|
if (sUserAgent && (sUserAgent.indexOf('chrome') > -1 || sUserAgent.indexOf('chrome') > -1))
|
|
|
|
{
|
|
|
|
oLink = window.document.createElement('a');
|
|
|
|
oLink['href'] = sLink;
|
|
|
|
|
|
|
|
if (window.document['createEvent'])
|
|
|
|
{
|
|
|
|
oE = window.document['createEvent']('MouseEvents');
|
|
|
|
if (oE && oE['initEvent'] && oLink['dispatchEvent'])
|
|
|
|
{
|
|
|
|
oE['initEvent']('click', true, true);
|
|
|
|
oLink['dispatchEvent'](oE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Globals.bMobileDevice)
|
|
|
|
{
|
|
|
|
window.open(sLink, '_self');
|
|
|
|
window.focus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.iframe.attr('src', sLink);
|
|
|
|
// window.document.location.href = sLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2014-10-31 04:09:53 +08:00
|
|
|
AbstractApp.prototype.googlePreviewSupportedCache = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.googlePreviewSupported = function ()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
/**
|
|
|
|
* @param {string} sTitle
|
|
|
|
*/
|
2015-03-04 08:30:37 +08:00
|
|
|
AbstractApp.prototype.setWindowTitle = function (sTitle)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-20 23:03:12 +08:00
|
|
|
sTitle = ((Utils.isNormal(sTitle) && 0 < sTitle.length) ? sTitle + ' - ' : '') +
|
2014-08-27 23:59:44 +08:00
|
|
|
Settings.settingsGet('Title') || '';
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2014-10-03 04:22:06 +08:00
|
|
|
window.document.title = sTitle + ' ...';
|
2014-08-20 23:03:12 +08:00
|
|
|
window.document.title = sTitle;
|
|
|
|
};
|
|
|
|
|
2014-10-03 04:22:06 +08:00
|
|
|
AbstractApp.prototype.redirectToAdminPanel = function ()
|
|
|
|
{
|
|
|
|
_.delay(function () {
|
2014-10-06 02:37:31 +08:00
|
|
|
window.location.href = Links.rootAdmin();
|
2014-10-03 04:22:06 +08:00
|
|
|
}, 100);
|
|
|
|
};
|
|
|
|
|
2014-10-06 02:37:31 +08:00
|
|
|
AbstractApp.prototype.clearClientSideToken = function ()
|
|
|
|
{
|
|
|
|
if (window.__rlah_clear)
|
|
|
|
{
|
|
|
|
window.__rlah_clear();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-03-28 06:06:56 +08:00
|
|
|
* @param {boolean=} bAdmin = false
|
2014-08-20 23:03:12 +08:00
|
|
|
* @param {boolean=} bLogout = false
|
|
|
|
* @param {boolean=} bClose = false
|
|
|
|
*/
|
2015-03-28 06:06:56 +08:00
|
|
|
AbstractApp.prototype.loginAndLogoutReload = function (bAdmin, bLogout, bClose)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
var
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
2014-08-27 23:59:44 +08:00
|
|
|
sCustomLogoutLink = Utils.pString(Settings.settingsGet('CustomLogoutLink')),
|
|
|
|
bInIframe = !!Settings.settingsGet('InIframe')
|
2014-08-20 23:03:12 +08:00
|
|
|
;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
bLogout = Utils.isUnd(bLogout) ? false : !!bLogout;
|
|
|
|
bClose = Utils.isUnd(bClose) ? false : !!bClose;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-06 02:37:31 +08:00
|
|
|
if (bLogout)
|
|
|
|
{
|
|
|
|
this.clearClientSideToken();
|
|
|
|
}
|
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
if (bLogout && bClose && window.close)
|
|
|
|
{
|
|
|
|
window.close();
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-03-28 06:06:56 +08:00
|
|
|
sCustomLogoutLink = sCustomLogoutLink || (bAdmin ? Links.rootAdmin() : Links.rootUser());
|
|
|
|
|
2014-10-03 04:22:06 +08:00
|
|
|
if (bLogout && window.location.href !== sCustomLogoutLink)
|
2014-08-20 23:03:12 +08:00
|
|
|
{
|
|
|
|
_.delay(function () {
|
|
|
|
if (bInIframe && window.parent)
|
|
|
|
{
|
|
|
|
window.parent.location.href = sCustomLogoutLink;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.href = sCustomLogoutLink;
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kn.routeOff();
|
2014-10-06 02:37:31 +08:00
|
|
|
kn.setHash(Links.root(), true);
|
2014-08-20 23:03:12 +08:00
|
|
|
kn.routeOff();
|
|
|
|
|
|
|
|
_.delay(function () {
|
|
|
|
if (bInIframe && window.parent)
|
|
|
|
{
|
|
|
|
window.parent.location.reload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
AbstractApp.prototype.historyBack = function ()
|
|
|
|
{
|
|
|
|
window.history.back();
|
|
|
|
};
|
|
|
|
|
|
|
|
AbstractApp.prototype.bootstart = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-22 23:08:56 +08:00
|
|
|
Events.pub('rl.bootstart');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-10-29 06:05:50 +08:00
|
|
|
var
|
|
|
|
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('TextArea', require('Component/TextArea'));
|
|
|
|
ko.components.register('Radio', require('Component/Radio'));
|
|
|
|
|
2015-04-02 02:18:15 +08:00
|
|
|
ko.components.register('x-script', require('Component/Script'));
|
|
|
|
|
2014-11-01 01:25:02 +08:00
|
|
|
if (Settings.settingsGet('MaterialDesign') && Globals.bAnimationSupported)
|
2014-10-30 05:08:53 +08:00
|
|
|
{
|
|
|
|
ko.components.register('Checkbox', require('Component/MaterialDesign/Checkbox'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-06 03:40:20 +08:00
|
|
|
// ko.components.register('Checkbox', require('Component/Classic/Checkbox'));
|
2014-10-30 05:08:53 +08:00
|
|
|
ko.components.register('Checkbox', require('Component/Checkbox'));
|
|
|
|
}
|
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,
|
|
|
|
'onEnter': function() {
|
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
|
|
|
},
|
|
|
|
'onLeave': function() {
|
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,
|
|
|
|
'onEnter': function() {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.addClass('ssm-state-desktop');
|
2014-08-20 23:03:12 +08:00
|
|
|
},
|
|
|
|
'onLeave': function() {
|
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,
|
|
|
|
'onEnter': function() {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.addClass('ssm-state-desktop-large');
|
2014-08-20 23:03:12 +08:00
|
|
|
},
|
|
|
|
'onLeave': function() {
|
2014-09-02 00:05:32 +08:00
|
|
|
Globals.$html.removeClass('ssm-state-desktop-large');
|
2013-12-13 07:23:47 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
Events.sub('ssm.mobile-enter', function () {
|
|
|
|
Globals.leftPanelDisabled(true);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
2013-12-30 05:13:35 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
Events.sub('ssm.mobile-leave', function () {
|
|
|
|
Globals.leftPanelDisabled(false);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
Globals.leftPanelDisabled.subscribe(function (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
|
|
|
|
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
|
|
|
};
|
2014-04-27 08:54:22 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
module.exports = AbstractApp;
|
2014-04-27 08:54:22 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|