2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractBoot
|
|
|
|
*/
|
|
|
|
function AbstractApp()
|
|
|
|
{
|
|
|
|
KnoinAbstractBoot.call(this);
|
|
|
|
|
|
|
|
this.oSettings = null;
|
|
|
|
this.oPlugins = null;
|
|
|
|
this.oLocal = null;
|
2013-12-13 07:23:47 +08:00
|
|
|
this.oLink = null;
|
|
|
|
this.oSubs = {};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
this.isLocalAutocomplete = true;
|
|
|
|
|
2014-03-21 00:05:35 +08:00
|
|
|
this.popupVisibilityNames = ko.observableArray([]);
|
|
|
|
|
|
|
|
this.popupVisibility = ko.computed(function () {
|
|
|
|
return 0 < this.popupVisibilityNames().length;
|
|
|
|
}, this);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
this.iframe = $('<iframe style="display:none" src="javascript:;" />').appendTo('body');
|
|
|
|
|
|
|
|
$window.on('error', function (oEvent) {
|
|
|
|
if (RL && oEvent && oEvent.originalEvent && oEvent.originalEvent.message &&
|
|
|
|
-1 === Utils.inArray(oEvent.originalEvent.message, [
|
|
|
|
'Script error.', 'Uncaught Error: Error calling method on NPObject.'
|
|
|
|
]))
|
|
|
|
{
|
|
|
|
RL.remote().jsError(
|
|
|
|
Utils.emptyFunction,
|
|
|
|
oEvent.originalEvent.message,
|
|
|
|
oEvent.originalEvent.filename,
|
|
|
|
oEvent.originalEvent.lineno,
|
|
|
|
location && location.toString ? location.toString() : '',
|
|
|
|
$html.attr('class'),
|
|
|
|
Utils.microtime() - Globals.now
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_.extend(AbstractApp.prototype, KnoinAbstractBoot.prototype);
|
|
|
|
|
|
|
|
AbstractApp.prototype.oSettings = null;
|
2013-12-13 07:23:47 +08:00
|
|
|
AbstractApp.prototype.oPlugins = null;
|
|
|
|
AbstractApp.prototype.oLocal = null;
|
2013-11-16 06:21:12 +08:00
|
|
|
AbstractApp.prototype.oLink = null;
|
2013-12-13 07:23:47 +08:00
|
|
|
AbstractApp.prototype.oSubs = {};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sLink
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.download = function (sLink)
|
|
|
|
{
|
|
|
|
var
|
|
|
|
oLink = null,
|
|
|
|
oE = null,
|
|
|
|
sUserAgent = navigator.userAgent.toLowerCase()
|
|
|
|
;
|
|
|
|
|
|
|
|
if (sUserAgent && (sUserAgent.indexOf('chrome') > -1 || sUserAgent.indexOf('chrome') > -1))
|
|
|
|
{
|
|
|
|
oLink = document.createElement('a');
|
|
|
|
oLink['href'] = sLink;
|
|
|
|
|
|
|
|
if (document['createEvent'])
|
|
|
|
{
|
|
|
|
oE = 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {LinkBuilder}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.link = function ()
|
|
|
|
{
|
|
|
|
if (null === this.oLink)
|
|
|
|
{
|
|
|
|
this.oLink = new LinkBuilder();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.oLink;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {LocalStorage}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.local = function ()
|
|
|
|
{
|
|
|
|
if (null === this.oLocal)
|
|
|
|
{
|
|
|
|
this.oLocal = new LocalStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.oLocal;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sName
|
|
|
|
* @return {?}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.settingsGet = function (sName)
|
|
|
|
{
|
|
|
|
if (null === this.oSettings)
|
|
|
|
{
|
|
|
|
this.oSettings = Utils.isNormal(AppData) ? AppData : {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return Utils.isUnd(this.oSettings[sName]) ? null : this.oSettings[sName];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sName
|
|
|
|
* @param {?} mValue
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.settingsSet = function (sName, mValue)
|
|
|
|
{
|
|
|
|
if (null === this.oSettings)
|
|
|
|
{
|
|
|
|
this.oSettings = Utils.isNormal(AppData) ? AppData : {};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.oSettings[sName] = mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
AbstractApp.prototype.setTitle = function (sTitle)
|
|
|
|
{
|
2013-12-25 08:05:04 +08:00
|
|
|
sTitle = ((Utils.isNormal(sTitle) && 0 < sTitle.length) ? sTitle + ' - ' : '') +
|
2013-11-21 06:00:30 +08:00
|
|
|
RL.settingsGet('Title') || '';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2013-12-03 08:16:57 +08:00
|
|
|
window.document.title = '_';
|
2013-11-21 06:00:30 +08:00
|
|
|
window.document.title = sTitle;
|
2013-11-16 06:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean=} bLogout = false
|
|
|
|
* @param {boolean=} bClose = false
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.loginAndLogoutReload = function (bLogout, bClose)
|
|
|
|
{
|
|
|
|
var
|
2013-11-21 06:00:30 +08:00
|
|
|
sCustomLogoutLink = Utils.pString(RL.settingsGet('CustomLogoutLink')),
|
|
|
|
bInIframe = !!RL.settingsGet('InIframe')
|
2013-11-16 06:21:12 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
bLogout = Utils.isUnd(bLogout) ? false : !!bLogout;
|
|
|
|
bClose = Utils.isUnd(bClose) ? false : !!bClose;
|
|
|
|
|
|
|
|
if (bLogout && bClose && window.close)
|
|
|
|
{
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bLogout && '' !== sCustomLogoutLink && window.location.href !== sCustomLogoutLink)
|
|
|
|
{
|
|
|
|
_.delay(function () {
|
|
|
|
if (bInIframe && window.parent)
|
|
|
|
{
|
|
|
|
window.parent.location.href = sCustomLogoutLink;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.href = sCustomLogoutLink;
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kn.routeOff();
|
|
|
|
kn.setHash(RL.link().root(), true);
|
|
|
|
kn.routeOff();
|
|
|
|
|
|
|
|
_.delay(function () {
|
|
|
|
if (bInIframe && window.parent)
|
|
|
|
{
|
|
|
|
window.parent.location.reload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-03 23:54:05 +08:00
|
|
|
AbstractApp.prototype.historyBack = function ()
|
|
|
|
{
|
|
|
|
window.history.back();
|
|
|
|
};
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
/**
|
|
|
|
* @param {string} sQuery
|
|
|
|
* @param {Function} fCallback
|
|
|
|
*/
|
2013-11-27 06:34:05 +08:00
|
|
|
AbstractApp.prototype.getAutocomplete = function (sQuery, fCallback)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
|
|
|
fCallback([], sQuery);
|
|
|
|
};
|
|
|
|
|
2013-12-13 07:23:47 +08:00
|
|
|
/**
|
|
|
|
* @param {string} sName
|
|
|
|
* @param {Function} fFunc
|
|
|
|
* @param {Object=} oContext
|
|
|
|
* @return {AbstractApp}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.sub = function (sName, fFunc, oContext)
|
|
|
|
{
|
|
|
|
if (Utils.isUnd(this.oSubs[sName]))
|
|
|
|
{
|
|
|
|
this.oSubs[sName] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.oSubs[sName].push([fFunc, oContext]);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sName
|
|
|
|
* @param {Array=} aArgs
|
|
|
|
* @return {AbstractApp}
|
|
|
|
*/
|
|
|
|
AbstractApp.prototype.pub = function (sName, aArgs)
|
|
|
|
{
|
2014-01-29 00:09:41 +08:00
|
|
|
Plugins.runHook('rl-pub', [sName, aArgs]);
|
2013-12-13 07:23:47 +08:00
|
|
|
if (!Utils.isUnd(this.oSubs[sName]))
|
|
|
|
{
|
|
|
|
_.each(this.oSubs[sName], function (aItem) {
|
|
|
|
if (aItem[0])
|
|
|
|
{
|
|
|
|
aItem[0].apply(aItem[1] || null, aArgs || []);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
AbstractApp.prototype.bootstart = function ()
|
|
|
|
{
|
|
|
|
Utils.initOnStartOrLangChange(function () {
|
|
|
|
Utils.initNotificationLanguage();
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
_.delay(function () {
|
|
|
|
Utils.windowResize();
|
|
|
|
}, 1000);
|
2013-12-30 05:13:35 +08:00
|
|
|
|
|
|
|
ssm.addState({
|
2013-12-31 19:57:02 +08:00
|
|
|
'id': 'mobile',
|
|
|
|
'maxWidth': 767,
|
|
|
|
'onEnter': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.addClass('ssm-state-mobile');
|
|
|
|
},
|
2013-12-31 19:57:02 +08:00
|
|
|
'onLeave': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.removeClass('ssm-state-mobile');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ssm.addState({
|
2013-12-31 19:57:02 +08:00
|
|
|
'id': 'tablet',
|
|
|
|
'minWidth': 768,
|
|
|
|
'maxWidth': 999,
|
|
|
|
'onEnter': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.addClass('ssm-state-tablet');
|
|
|
|
},
|
2013-12-31 19:57:02 +08:00
|
|
|
'onLeave': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.removeClass('ssm-state-tablet');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ssm.addState({
|
2013-12-31 19:57:02 +08:00
|
|
|
'id': 'desktop',
|
|
|
|
'minWidth': 1000,
|
|
|
|
'maxWidth': 1400,
|
|
|
|
'onEnter': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.addClass('ssm-state-desktop');
|
|
|
|
},
|
2013-12-31 19:57:02 +08:00
|
|
|
'onLeave': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.removeClass('ssm-state-desktop');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ssm.addState({
|
2013-12-31 19:57:02 +08:00
|
|
|
'id': 'desktop-large',
|
|
|
|
'minWidth': 1400,
|
|
|
|
'onEnter': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.addClass('ssm-state-desktop-large');
|
|
|
|
},
|
2013-12-31 19:57:02 +08:00
|
|
|
'onLeave': function() {
|
2013-12-30 05:13:35 +08:00
|
|
|
$html.removeClass('ssm-state-desktop-large');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-12-31 19:57:02 +08:00
|
|
|
ssm.ready();
|
2013-11-16 06:21:12 +08:00
|
|
|
};
|