mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 14:37:02 +03:00
CommonJS (research)
This commit is contained in:
parent
2fa2cd191e
commit
56607de87c
91 changed files with 20220 additions and 12933 deletions
|
|
@ -1,359 +1,385 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractBoot
|
||||
*/
|
||||
function AbstractApp()
|
||||
{
|
||||
KnoinAbstractBoot.call(this);
|
||||
(function (module) {
|
||||
|
||||
this.oSettings = null;
|
||||
this.oPlugins = null;
|
||||
this.oLocal = null;
|
||||
this.oLink = null;
|
||||
this.oSubs = {};
|
||||
'use strict';
|
||||
|
||||
this.isLocalAutocomplete = true;
|
||||
|
||||
this.popupVisibilityNames = ko.observableArray([]);
|
||||
|
||||
this.popupVisibility = ko.computed(function () {
|
||||
return 0 < this.popupVisibilityNames().length;
|
||||
}, this);
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$document.on('keydown', function (oEvent) {
|
||||
if (oEvent && oEvent.ctrlKey)
|
||||
{
|
||||
$html.addClass('rl-ctrl-key-pressed');
|
||||
}
|
||||
}).on('keyup', function (oEvent) {
|
||||
if (oEvent && !oEvent.ctrlKey)
|
||||
{
|
||||
$html.removeClass('rl-ctrl-key-pressed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_.extend(AbstractApp.prototype, KnoinAbstractBoot.prototype);
|
||||
|
||||
AbstractApp.prototype.oSettings = null;
|
||||
AbstractApp.prototype.oPlugins = null;
|
||||
AbstractApp.prototype.oLocal = null;
|
||||
AbstractApp.prototype.oLink = null;
|
||||
AbstractApp.prototype.oSubs = {};
|
||||
|
||||
/**
|
||||
* @param {string} sLink
|
||||
* @return {boolean}
|
||||
*/
|
||||
AbstractApp.prototype.download = function (sLink)
|
||||
{
|
||||
var
|
||||
oLink = null,
|
||||
oE = null,
|
||||
sUserAgent = navigator.userAgent.toLowerCase()
|
||||
$ = require('../External/jquery.js'),
|
||||
_ = require('../External/underscore.js'),
|
||||
ko = require('../External/ko.js'),
|
||||
window = require('../External/window.js'),
|
||||
$html = require('../External/$html.js'),
|
||||
$window = require('../External/$window.js'),
|
||||
$doc = require('../External/$doc.js'),
|
||||
AppData = require('../External/AppData.js'),
|
||||
Globals = require('../Common/Globals.js'),
|
||||
Utils = require('../Common/Utils.js'),
|
||||
KnoinAbstractBoot = require('../Knoin/KnoinAbstractBoot.js'),
|
||||
RL = require('./RL.js')
|
||||
;
|
||||
|
||||
if (sUserAgent && (sUserAgent.indexOf('chrome') > -1 || sUserAgent.indexOf('chrome') > -1))
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractBoot
|
||||
*/
|
||||
function AbstractApp()
|
||||
{
|
||||
oLink = document.createElement('a');
|
||||
oLink['href'] = sLink;
|
||||
KnoinAbstractBoot.call(this);
|
||||
|
||||
if (document['createEvent'])
|
||||
{
|
||||
oE = document['createEvent']('MouseEvents');
|
||||
if (oE && oE['initEvent'] && oLink['dispatchEvent'])
|
||||
this.oSettings = null;
|
||||
this.oPlugins = null;
|
||||
this.oLocal = null;
|
||||
this.oLink = null;
|
||||
this.oSubs = {};
|
||||
|
||||
this.isLocalAutocomplete = true;
|
||||
|
||||
this.popupVisibilityNames = ko.observableArray([]);
|
||||
|
||||
this.popupVisibility = ko.computed(function () {
|
||||
return 0 < this.popupVisibilityNames().length;
|
||||
}, this);
|
||||
|
||||
this.iframe = $('<iframe style="display:none" src="javascript:;" />').appendTo('body');
|
||||
|
||||
$window.on('error', function (oEvent) {
|
||||
if (oEvent && oEvent.originalEvent && oEvent.originalEvent.message &&
|
||||
-1 === Utils.inArray(oEvent.originalEvent.message, [
|
||||
'Script error.', 'Uncaught Error: Error calling method on NPObject.'
|
||||
]))
|
||||
{
|
||||
oE['initEvent']('click', true, true);
|
||||
oLink['dispatchEvent'](oE);
|
||||
return true;
|
||||
// TODO cjs
|
||||
RL.remote().jsError(
|
||||
Utils.emptyFunction,
|
||||
oEvent.originalEvent.message,
|
||||
oEvent.originalEvent.filename,
|
||||
oEvent.originalEvent.lineno,
|
||||
window.location && window.location.toString ? window.location.toString() : '',
|
||||
$html.attr('class'),
|
||||
Utils.microtime() - Globals.now
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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)
|
||||
{
|
||||
sTitle = ((Utils.isNormal(sTitle) && 0 < sTitle.length) ? sTitle + ' - ' : '') +
|
||||
RL.settingsGet('Title') || '';
|
||||
|
||||
window.document.title = '_';
|
||||
window.document.title = sTitle;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean=} bLogout = false
|
||||
* @param {boolean=} bClose = false
|
||||
*/
|
||||
AbstractApp.prototype.loginAndLogoutReload = function (bLogout, bClose)
|
||||
{
|
||||
var
|
||||
sCustomLogoutLink = Utils.pString(RL.settingsGet('CustomLogoutLink')),
|
||||
bInIframe = !!RL.settingsGet('InIframe')
|
||||
;
|
||||
|
||||
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)
|
||||
$doc.on('keydown', function (oEvent) {
|
||||
if (oEvent && oEvent.ctrlKey)
|
||||
{
|
||||
window.parent.location.href = sCustomLogoutLink;
|
||||
$html.addClass('rl-ctrl-key-pressed');
|
||||
}
|
||||
else
|
||||
}).on('keyup', function (oEvent) {
|
||||
if (oEvent && !oEvent.ctrlKey)
|
||||
{
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
AbstractApp.prototype.historyBack = function ()
|
||||
{
|
||||
window.history.back();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sQuery
|
||||
* @param {Function} fCallback
|
||||
*/
|
||||
AbstractApp.prototype.getAutocomplete = function (sQuery, fCallback)
|
||||
{
|
||||
fCallback([], sQuery);
|
||||
};
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
Plugins.runHook('rl-pub', [sName, aArgs]);
|
||||
if (!Utils.isUnd(this.oSubs[sName]))
|
||||
{
|
||||
_.each(this.oSubs[sName], function (aItem) {
|
||||
if (aItem[0])
|
||||
{
|
||||
aItem[0].apply(aItem[1] || null, aArgs || []);
|
||||
$html.removeClass('rl-ctrl-key-pressed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
_.extend(AbstractApp.prototype, KnoinAbstractBoot.prototype);
|
||||
|
||||
/**
|
||||
* @param {string} sName
|
||||
* @return {boolean}
|
||||
*/
|
||||
AbstractApp.prototype.capa = function (sName)
|
||||
{
|
||||
var mCapa = this.settingsGet('Capa');
|
||||
return Utils.isArray(mCapa) && Utils.isNormal(sName) && -1 < Utils.inArray(sName, mCapa);
|
||||
};
|
||||
AbstractApp.prototype.oSettings = null;
|
||||
AbstractApp.prototype.oPlugins = null;
|
||||
AbstractApp.prototype.oLocal = null;
|
||||
AbstractApp.prototype.oLink = null;
|
||||
AbstractApp.prototype.oSubs = {};
|
||||
|
||||
AbstractApp.prototype.bootstart = function ()
|
||||
{
|
||||
var self = this;
|
||||
/**
|
||||
* @param {string} sLink
|
||||
* @return {boolean}
|
||||
*/
|
||||
AbstractApp.prototype.download = function (sLink)
|
||||
{
|
||||
var
|
||||
oE = null,
|
||||
oLink = null,
|
||||
sUserAgent = window.navigator.userAgent.toLowerCase()
|
||||
;
|
||||
|
||||
Utils.initOnStartOrLangChange(function () {
|
||||
Utils.initNotificationLanguage();
|
||||
}, null);
|
||||
if (sUserAgent && (sUserAgent.indexOf('chrome') > -1 || sUserAgent.indexOf('chrome') > -1))
|
||||
{
|
||||
oLink = window.document.createElement('a');
|
||||
oLink['href'] = sLink;
|
||||
|
||||
_.delay(function () {
|
||||
Utils.windowResize();
|
||||
}, 1000);
|
||||
|
||||
ssm.addState({
|
||||
'id': 'mobile',
|
||||
'maxWidth': 767,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-mobile');
|
||||
self.pub('ssm.mobile-enter');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-mobile');
|
||||
self.pub('ssm.mobile-leave');
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ssm.addState({
|
||||
'id': 'tablet',
|
||||
'minWidth': 768,
|
||||
'maxWidth': 999,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-tablet');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-tablet');
|
||||
if (Globals.bMobileDevice)
|
||||
{
|
||||
window.open(sLink, '_self');
|
||||
window.focus();
|
||||
}
|
||||
});
|
||||
|
||||
ssm.addState({
|
||||
'id': 'desktop',
|
||||
'minWidth': 1000,
|
||||
'maxWidth': 1400,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-desktop');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-desktop');
|
||||
else
|
||||
{
|
||||
this.iframe.attr('src', sLink);
|
||||
// window.document.location.href = sLink;
|
||||
}
|
||||
});
|
||||
|
||||
ssm.addState({
|
||||
'id': 'desktop-large',
|
||||
'minWidth': 1400,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-desktop-large');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-desktop-large');
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {LinkBuilder}
|
||||
*/
|
||||
AbstractApp.prototype.link = function ()
|
||||
{
|
||||
if (null === this.oLink)
|
||||
{
|
||||
this.oLink = new LinkBuilder(); // TODO cjs
|
||||
}
|
||||
});
|
||||
|
||||
RL.sub('ssm.mobile-enter', function () {
|
||||
RL.data().leftPanelDisabled(true);
|
||||
});
|
||||
return this.oLink;
|
||||
};
|
||||
|
||||
RL.sub('ssm.mobile-leave', function () {
|
||||
RL.data().leftPanelDisabled(false);
|
||||
});
|
||||
/**
|
||||
* @return {LocalStorage}
|
||||
*/
|
||||
AbstractApp.prototype.local = function ()
|
||||
{
|
||||
if (null === this.oLocal)
|
||||
{
|
||||
this.oLocal = new LocalStorage(); // TODO cjs
|
||||
}
|
||||
|
||||
RL.data().leftPanelDisabled.subscribe(function (bValue) {
|
||||
$html.toggleClass('rl-left-panel-disabled', bValue);
|
||||
});
|
||||
return this.oLocal;
|
||||
};
|
||||
|
||||
ssm.ready();
|
||||
};
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
sTitle = ((Utils.isNormal(sTitle) && 0 < sTitle.length) ? sTitle + ' - ' : '') +
|
||||
RL.settingsGet('Title') || ''; // TODO cjs
|
||||
|
||||
window.document.title = '_';
|
||||
window.document.title = sTitle;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean=} bLogout = false
|
||||
* @param {boolean=} bClose = false
|
||||
*/
|
||||
AbstractApp.prototype.loginAndLogoutReload = function (bLogout, bClose)
|
||||
{
|
||||
var
|
||||
sCustomLogoutLink = Utils.pString(RL.settingsGet('CustomLogoutLink')),
|
||||
bInIframe = !!RL.settingsGet('InIframe')
|
||||
;
|
||||
|
||||
// TODO cjs
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
AbstractApp.prototype.historyBack = function ()
|
||||
{
|
||||
window.history.back();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sQuery
|
||||
* @param {Function} fCallback
|
||||
*/
|
||||
AbstractApp.prototype.getAutocomplete = function (sQuery, fCallback)
|
||||
{
|
||||
fCallback([], sQuery);
|
||||
};
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
Plugins.runHook('rl-pub', [sName, aArgs]);
|
||||
if (!Utils.isUnd(this.oSubs[sName]))
|
||||
{
|
||||
_.each(this.oSubs[sName], function (aItem) {
|
||||
if (aItem[0])
|
||||
{
|
||||
aItem[0].apply(aItem[1] || null, aArgs || []);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sName
|
||||
* @return {boolean}
|
||||
*/
|
||||
AbstractApp.prototype.capa = function (sName)
|
||||
{
|
||||
var mCapa = this.settingsGet('Capa');
|
||||
return Utils.isArray(mCapa) && Utils.isNormal(sName) && -1 < Utils.inArray(sName, mCapa);
|
||||
};
|
||||
|
||||
AbstractApp.prototype.bootstart = function ()
|
||||
{
|
||||
var ssm = require('../External/ssm.js');
|
||||
|
||||
Utils.initOnStartOrLangChange(function () {
|
||||
Utils.initNotificationLanguage();
|
||||
}, null);
|
||||
|
||||
_.delay(function () {
|
||||
Utils.windowResize();
|
||||
}, 1000);
|
||||
|
||||
ssm.addState({
|
||||
'id': 'mobile',
|
||||
'maxWidth': 767,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-mobile');
|
||||
RL.pub('ssm.mobile-enter');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-mobile');
|
||||
RL.pub('ssm.mobile-leave');
|
||||
}
|
||||
});
|
||||
|
||||
ssm.addState({
|
||||
'id': 'tablet',
|
||||
'minWidth': 768,
|
||||
'maxWidth': 999,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-tablet');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-tablet');
|
||||
}
|
||||
});
|
||||
|
||||
ssm.addState({
|
||||
'id': 'desktop',
|
||||
'minWidth': 1000,
|
||||
'maxWidth': 1400,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-desktop');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-desktop');
|
||||
}
|
||||
});
|
||||
|
||||
ssm.addState({
|
||||
'id': 'desktop-large',
|
||||
'minWidth': 1400,
|
||||
'onEnter': function() {
|
||||
$html.addClass('ssm-state-desktop-large');
|
||||
},
|
||||
'onLeave': function() {
|
||||
$html.removeClass('ssm-state-desktop-large');
|
||||
}
|
||||
});
|
||||
|
||||
RL.sub('ssm.mobile-enter', function () { // TODO cjs
|
||||
RL.data().leftPanelDisabled(true);
|
||||
});
|
||||
|
||||
RL.sub('ssm.mobile-leave', function () { // TODO cjs
|
||||
RL.data().leftPanelDisabled(false);
|
||||
});
|
||||
|
||||
RL.data().leftPanelDisabled.subscribe(function (bValue) { // TODO cjs
|
||||
$html.toggleClass('rl-left-panel-disabled', bValue);
|
||||
});
|
||||
|
||||
ssm.ready();
|
||||
};
|
||||
|
||||
module.exports = AbstractApp;
|
||||
|
||||
}(module));
|
||||
|
|
@ -1,302 +1,320 @@
|
|||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractApp
|
||||
*/
|
||||
function AdminApp()
|
||||
{
|
||||
AbstractApp.call(this);
|
||||
(function (module) {
|
||||
|
||||
this.oData = null;
|
||||
this.oRemote = null;
|
||||
this.oCache = null;
|
||||
}
|
||||
'use strict';
|
||||
|
||||
_.extend(AdminApp.prototype, AbstractApp.prototype);
|
||||
var
|
||||
ko = require('../External/ko.js'),
|
||||
_ = require('../External/underscore.js'),
|
||||
window = require('../External/window.js'),
|
||||
Enums = require('../Common/Enums.js'),
|
||||
Utils = require('../Common/Utils.js'),
|
||||
kn = require('../Knoin/Knoin.js'),
|
||||
AbstractApp = require('./AbstractApp.js')
|
||||
;
|
||||
|
||||
AdminApp.prototype.oData = null;
|
||||
AdminApp.prototype.oRemote = null;
|
||||
AdminApp.prototype.oCache = null;
|
||||
|
||||
/**
|
||||
* @return {AdminDataStorage}
|
||||
*/
|
||||
AdminApp.prototype.data = function ()
|
||||
{
|
||||
if (null === this.oData)
|
||||
/**
|
||||
* @constructor
|
||||
* @extends AbstractApp
|
||||
*/
|
||||
function AdminApp()
|
||||
{
|
||||
this.oData = new AdminDataStorage();
|
||||
AbstractApp.call(this);
|
||||
|
||||
this.oData = null;
|
||||
this.oRemote = null;
|
||||
this.oCache = null;
|
||||
}
|
||||
|
||||
return this.oData;
|
||||
};
|
||||
_.extend(AdminApp.prototype, AbstractApp.prototype);
|
||||
|
||||
/**
|
||||
* @return {AdminAjaxRemoteStorage}
|
||||
*/
|
||||
AdminApp.prototype.remote = function ()
|
||||
{
|
||||
if (null === this.oRemote)
|
||||
AdminApp.prototype.oData = null;
|
||||
AdminApp.prototype.oRemote = null;
|
||||
AdminApp.prototype.oCache = null;
|
||||
|
||||
/**
|
||||
* @return {AdminDataStorage}
|
||||
*/
|
||||
AdminApp.prototype.data = function ()
|
||||
{
|
||||
this.oRemote = new AdminAjaxRemoteStorage();
|
||||
}
|
||||
|
||||
return this.oRemote;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {AdminCacheStorage}
|
||||
*/
|
||||
AdminApp.prototype.cache = function ()
|
||||
{
|
||||
if (null === this.oCache)
|
||||
{
|
||||
this.oCache = new AdminCacheStorage();
|
||||
}
|
||||
|
||||
return this.oCache;
|
||||
};
|
||||
|
||||
AdminApp.prototype.reloadDomainList = function ()
|
||||
{
|
||||
RL.data().domainsLoading(true);
|
||||
RL.remote().domainList(function (sResult, oData) {
|
||||
RL.data().domainsLoading(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
if (null === this.oData)
|
||||
{
|
||||
var aList = _.map(oData.Result, function (bEnabled, sName) {
|
||||
return {
|
||||
'name': sName,
|
||||
'disabled': ko.observable(!bEnabled),
|
||||
'deleteAccess': ko.observable(false)
|
||||
};
|
||||
}, this);
|
||||
|
||||
RL.data().domains(aList);
|
||||
this.oData = new AdminDataStorage(); // TODO cjs
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AdminApp.prototype.reloadPluginList = function ()
|
||||
{
|
||||
RL.data().pluginsLoading(true);
|
||||
RL.remote().pluginList(function (sResult, oData) {
|
||||
RL.data().pluginsLoading(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
return this.oData;
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {AdminAjaxRemoteStorage}
|
||||
*/
|
||||
AdminApp.prototype.remote = function ()
|
||||
{
|
||||
if (null === this.oRemote)
|
||||
{
|
||||
var aList = _.map(oData.Result, function (oItem) {
|
||||
return {
|
||||
'name': oItem['Name'],
|
||||
'disabled': ko.observable(!oItem['Enabled']),
|
||||
'configured': ko.observable(!!oItem['Configured'])
|
||||
};
|
||||
}, this);
|
||||
|
||||
RL.data().plugins(aList);
|
||||
this.oRemote = new AdminAjaxRemoteStorage(); // TODO cjs
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AdminApp.prototype.reloadPackagesList = function ()
|
||||
{
|
||||
RL.data().packagesLoading(true);
|
||||
RL.data().packagesReal(true);
|
||||
return this.oRemote;
|
||||
};
|
||||
|
||||
RL.remote().packagesList(function (sResult, oData) {
|
||||
|
||||
RL.data().packagesLoading(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
/**
|
||||
* @return {AdminCacheStorage}
|
||||
*/
|
||||
AdminApp.prototype.cache = function ()
|
||||
{
|
||||
if (null === this.oCache)
|
||||
{
|
||||
RL.data().packagesReal(!!oData.Result.Real);
|
||||
RL.data().packagesMainUpdatable(!!oData.Result.MainUpdatable);
|
||||
this.oCache = new AdminCacheStorage(); // TODO cjs
|
||||
}
|
||||
|
||||
var
|
||||
aList = [],
|
||||
aLoading = {}
|
||||
;
|
||||
return this.oCache;
|
||||
};
|
||||
|
||||
_.each(RL.data().packages(), function (oItem) {
|
||||
if (oItem && oItem['loading']())
|
||||
{
|
||||
aLoading[oItem['file']] = oItem;
|
||||
}
|
||||
});
|
||||
|
||||
if (Utils.isArray(oData.Result.List))
|
||||
AdminApp.prototype.reloadDomainList = function ()
|
||||
{
|
||||
// TODO cjs
|
||||
RL.data().domainsLoading(true);
|
||||
RL.remote().domainList(function (sResult, oData) {
|
||||
RL.data().domainsLoading(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
aList = _.compact(_.map(oData.Result.List, function (oItem) {
|
||||
if (oItem)
|
||||
{
|
||||
oItem['loading'] = ko.observable(!Utils.isUnd(aLoading[oItem['file']]));
|
||||
return 'core' === oItem['type'] && !oItem['canBeInstalled'] ? null : oItem;
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
var aList = _.map(oData.Result, function (bEnabled, sName) {
|
||||
return {
|
||||
'name': sName,
|
||||
'disabled': ko.observable(!bEnabled),
|
||||
'deleteAccess': ko.observable(false)
|
||||
};
|
||||
}, this);
|
||||
|
||||
RL.data().domains(aList);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RL.data().packages(aList);
|
||||
}
|
||||
else
|
||||
{
|
||||
RL.data().packagesReal(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
AdminApp.prototype.reloadPluginList = function ()
|
||||
{
|
||||
// TODO cjs
|
||||
RL.data().pluginsLoading(true);
|
||||
RL.remote().pluginList(function (sResult, oData) {
|
||||
RL.data().pluginsLoading(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
var aList = _.map(oData.Result, function (oItem) {
|
||||
return {
|
||||
'name': oItem['Name'],
|
||||
'disabled': ko.observable(!oItem['Enabled']),
|
||||
'configured': ko.observable(!!oItem['Configured'])
|
||||
};
|
||||
}, this);
|
||||
|
||||
AdminApp.prototype.updateCoreData = function ()
|
||||
{
|
||||
var oRainData = RL.data();
|
||||
RL.data().plugins(aList);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
oRainData.coreUpdating(true);
|
||||
RL.remote().updateCoreData(function (sResult, oData) {
|
||||
AdminApp.prototype.reloadPackagesList = function ()
|
||||
{
|
||||
// TODO cjs
|
||||
RL.data().packagesLoading(true);
|
||||
RL.data().packagesReal(true);
|
||||
|
||||
oRainData.coreUpdating(false);
|
||||
oRainData.coreRemoteVersion('');
|
||||
oRainData.coreRemoteRelease('');
|
||||
oRainData.coreVersionCompare(-2);
|
||||
RL.remote().packagesList(function (sResult, oData) {
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
oRainData.coreReal(true);
|
||||
window.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
oRainData.coreReal(false);
|
||||
}
|
||||
});
|
||||
RL.data().packagesLoading(false);
|
||||
|
||||
};
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
RL.data().packagesReal(!!oData.Result.Real);
|
||||
RL.data().packagesMainUpdatable(!!oData.Result.MainUpdatable);
|
||||
|
||||
AdminApp.prototype.reloadCoreData = function ()
|
||||
{
|
||||
var oRainData = RL.data();
|
||||
var
|
||||
aList = [],
|
||||
aLoading = {}
|
||||
;
|
||||
|
||||
oRainData.coreChecking(true);
|
||||
oRainData.coreReal(true);
|
||||
_.each(RL.data().packages(), function (oItem) {
|
||||
if (oItem && oItem['loading']())
|
||||
{
|
||||
aLoading[oItem['file']] = oItem;
|
||||
}
|
||||
});
|
||||
|
||||
RL.remote().coreData(function (sResult, oData) {
|
||||
if (Utils.isArray(oData.Result.List))
|
||||
{
|
||||
aList = _.compact(_.map(oData.Result.List, function (oItem) {
|
||||
if (oItem)
|
||||
{
|
||||
oItem['loading'] = ko.observable(!Utils.isUnd(aLoading[oItem['file']]));
|
||||
return 'core' === oItem['type'] && !oItem['canBeInstalled'] ? null : oItem;
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
|
||||
oRainData.coreChecking(false);
|
||||
RL.data().packages(aList);
|
||||
}
|
||||
else
|
||||
{
|
||||
RL.data().packagesReal(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
oRainData.coreReal(!!oData.Result.Real);
|
||||
oRainData.coreUpdatable(!!oData.Result.Updatable);
|
||||
oRainData.coreAccess(!!oData.Result.Access);
|
||||
oRainData.coreRemoteVersion(oData.Result.RemoteVersion || '');
|
||||
oRainData.coreRemoteRelease(oData.Result.RemoteRelease || '');
|
||||
oRainData.coreVersionCompare(Utils.pInt(oData.Result.VersionCompare));
|
||||
}
|
||||
else
|
||||
{
|
||||
oRainData.coreReal(false);
|
||||
AdminApp.prototype.updateCoreData = function ()
|
||||
{
|
||||
// TODO cjs
|
||||
var oRainData = RL.data();
|
||||
|
||||
oRainData.coreUpdating(true);
|
||||
RL.remote().updateCoreData(function (sResult, oData) {
|
||||
|
||||
oRainData.coreUpdating(false);
|
||||
oRainData.coreRemoteVersion('');
|
||||
oRainData.coreRemoteRelease('');
|
||||
oRainData.coreVersionCompare(-2);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {boolean=} bForce = false
|
||||
*/
|
||||
AdminApp.prototype.reloadLicensing = function (bForce)
|
||||
{
|
||||
bForce = Utils.isUnd(bForce) ? false : !!bForce;
|
||||
|
||||
RL.data().licensingProcess(true);
|
||||
RL.data().licenseError('');
|
||||
|
||||
RL.remote().licensing(function (sResult, oData) {
|
||||
RL.data().licensingProcess(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && Utils.isNormal(oData.Result['Expired']))
|
||||
{
|
||||
RL.data().licenseValid(true);
|
||||
RL.data().licenseExpired(Utils.pInt(oData.Result['Expired']));
|
||||
RL.data().licenseError('');
|
||||
|
||||
RL.data().licensing(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oData && oData.ErrorCode && -1 < Utils.inArray(Utils.pInt(oData.ErrorCode), [
|
||||
Enums.Notification.LicensingServerIsUnavailable,
|
||||
Enums.Notification.LicensingExpired
|
||||
]))
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
RL.data().licenseError(Utils.getNotification(Utils.pInt(oData.ErrorCode)));
|
||||
oRainData.coreReal(true);
|
||||
window.location.reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
oRainData.coreReal(false);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
AdminApp.prototype.reloadCoreData = function ()
|
||||
{
|
||||
var oRainData = RL.data();
|
||||
|
||||
oRainData.coreChecking(true);
|
||||
oRainData.coreReal(true);
|
||||
|
||||
RL.remote().coreData(function (sResult, oData) {
|
||||
|
||||
oRainData.coreChecking(false);
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
oRainData.coreReal(!!oData.Result.Real);
|
||||
oRainData.coreUpdatable(!!oData.Result.Updatable);
|
||||
oRainData.coreAccess(!!oData.Result.Access);
|
||||
oRainData.coreRemoteVersion(oData.Result.RemoteVersion || '');
|
||||
oRainData.coreRemoteRelease(oData.Result.RemoteRelease || '');
|
||||
oRainData.coreVersionCompare(Utils.pInt(oData.Result.VersionCompare));
|
||||
}
|
||||
else
|
||||
{
|
||||
oRainData.coreReal(false);
|
||||
oRainData.coreRemoteVersion('');
|
||||
oRainData.coreRemoteRelease('');
|
||||
oRainData.coreVersionCompare(-2);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {boolean=} bForce = false
|
||||
*/
|
||||
AdminApp.prototype.reloadLicensing = function (bForce)
|
||||
{
|
||||
bForce = Utils.isUnd(bForce) ? false : !!bForce;
|
||||
|
||||
// TODO cjs
|
||||
RL.data().licensingProcess(true);
|
||||
RL.data().licenseError('');
|
||||
|
||||
RL.remote().licensing(function (sResult, oData) {
|
||||
RL.data().licensingProcess(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && Utils.isNormal(oData.Result['Expired']))
|
||||
{
|
||||
RL.data().licenseValid(true);
|
||||
RL.data().licenseExpired(Utils.pInt(oData.Result['Expired']));
|
||||
RL.data().licenseError('');
|
||||
|
||||
RL.data().licensing(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Enums.StorageResultType.Abort === sResult)
|
||||
if (oData && oData.ErrorCode && -1 < Utils.inArray(Utils.pInt(oData.ErrorCode), [
|
||||
Enums.Notification.LicensingServerIsUnavailable,
|
||||
Enums.Notification.LicensingExpired
|
||||
]))
|
||||
{
|
||||
RL.data().licenseError(Utils.getNotification(Enums.Notification.LicensingServerIsUnavailable));
|
||||
RL.data().licenseError(Utils.getNotification(Utils.pInt(oData.ErrorCode)));
|
||||
RL.data().licensing(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
RL.data().licensing(false);
|
||||
if (Enums.StorageResultType.Abort === sResult)
|
||||
{
|
||||
RL.data().licenseError(Utils.getNotification(Enums.Notification.LicensingServerIsUnavailable));
|
||||
RL.data().licensing(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
RL.data().licensing(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, bForce);
|
||||
};
|
||||
}, bForce);
|
||||
};
|
||||
|
||||
AdminApp.prototype.bootstart = function ()
|
||||
{
|
||||
AbstractApp.prototype.bootstart.call(this);
|
||||
|
||||
RL.data().populateDataOnStart();
|
||||
|
||||
kn.hideLoading();
|
||||
|
||||
if (!RL.settingsGet('AllowAdminPanel'))
|
||||
AdminApp.prototype.bootstart = function ()
|
||||
{
|
||||
kn.routeOff();
|
||||
kn.setHash(RL.link().root(), true);
|
||||
kn.routeOff();
|
||||
AbstractApp.prototype.bootstart.call(this);
|
||||
|
||||
_.defer(function () {
|
||||
window.location.href = '/';
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Utils.removeSettingsViewModel(AdminAbout);
|
||||
RL.data().populateDataOnStart();
|
||||
|
||||
if (!RL.capa(Enums.Capa.Prem))
|
||||
kn.hideLoading();
|
||||
|
||||
if (!RL.settingsGet('AllowAdminPanel'))
|
||||
{
|
||||
Utils.removeSettingsViewModel(AdminBranding);
|
||||
}
|
||||
kn.routeOff();
|
||||
kn.setHash(RL.link().root(), true);
|
||||
kn.routeOff();
|
||||
|
||||
if (!!RL.settingsGet('Auth'))
|
||||
{
|
||||
// TODO
|
||||
// if (!RL.settingsGet('AllowPackages') && AdminPackages)
|
||||
// {
|
||||
// Utils.disableSettingsViewModel(AdminPackages);
|
||||
// }
|
||||
|
||||
kn.startScreens([AdminSettingsScreen]);
|
||||
_.defer(function () {
|
||||
window.location.href = '/';
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
kn.startScreens([AdminLoginScreen]);
|
||||
// Utils.removeSettingsViewModel(AdminAbout);
|
||||
|
||||
if (!RL.capa(Enums.Capa.Prem))
|
||||
{
|
||||
Utils.removeSettingsViewModel(AdminBranding);
|
||||
}
|
||||
|
||||
if (!!RL.settingsGet('Auth'))
|
||||
{
|
||||
// TODO
|
||||
// if (!RL.settingsGet('AllowPackages') && AdminPackages)
|
||||
// {
|
||||
// Utils.disableSettingsViewModel(AdminPackages);
|
||||
// }
|
||||
|
||||
kn.startScreens([AdminSettingsScreen]);
|
||||
}
|
||||
else
|
||||
{
|
||||
kn.startScreens([AdminLoginScreen]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (window.SimplePace)
|
||||
{
|
||||
window.SimplePace.set(100);
|
||||
}
|
||||
};
|
||||
if (window.SimplePace)
|
||||
{
|
||||
window.SimplePace.set(100);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {AdminApp}
|
||||
*/
|
||||
RL = new AdminApp();
|
||||
module.exports = new AdminApp();
|
||||
|
||||
}(module));
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue