snappymail/dev/Apps/AdminApp.js

273 lines
5.7 KiB
JavaScript
Raw Normal View History

2014-09-05 06:49:03 +08:00
(function () {
2014-08-26 14:31:20 +08:00
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
var
2014-08-25 23:49:01 +08:00
window = require('window'),
_ = require('_'),
ko = require('ko'),
2014-08-25 15:10:51 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
LinkBuilder = require('Common/LinkBuilder'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
Settings = require('Storage:Settings'),
Data = require('Storage:Admin:Data'),
Remote = require('Storage:Admin:Remote'),
2014-08-25 15:10:51 +08:00
2014-08-27 23:59:44 +08:00
AdminSettingsScreen = require('Screen:Admin:Settings'),
AdminLoginScreen = require('Screen:Admin:Login'),
2014-08-21 23:08:34 +08:00
kn = require('App:Knoin'),
2014-08-27 23:59:44 +08:00
AbstractApp = require('App:Abstract')
2014-08-20 23:03:12 +08:00
;
/**
* @constructor
* @extends AbstractApp
*/
function AdminApp()
{
2014-08-22 23:08:56 +08:00
AbstractApp.call(this, Remote);
}
2014-08-20 23:03:12 +08:00
_.extend(AdminApp.prototype, AbstractApp.prototype);
2014-08-22 23:08:56 +08:00
AdminApp.prototype.remote = function ()
{
return Remote;
};
2014-08-20 23:03:12 +08:00
AdminApp.prototype.data = function ()
{
2014-08-22 23:08:56 +08:00
return Data;
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
AdminApp.prototype.reloadDomainList = function ()
{
2014-08-21 23:08:34 +08:00
Data.domainsLoading(true);
2014-08-25 15:10:51 +08:00
2014-08-21 23:08:34 +08:00
Remote.domainList(function (sResult, oData) {
Data.domainsLoading(false);
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
var aList = _.map(oData.Result, function (bEnabled, sName) {
return {
'name': sName,
'disabled': ko.observable(!bEnabled),
'deleteAccess': ko.observable(false)
};
}, this);
2014-08-21 23:08:34 +08:00
Data.domains(aList);
2014-08-20 23:03:12 +08:00
}
});
};
2014-08-20 23:03:12 +08:00
AdminApp.prototype.reloadPluginList = function ()
{
2014-08-21 23:08:34 +08:00
Data.pluginsLoading(true);
Remote.pluginList(function (sResult, oData) {
2014-08-22 23:08:56 +08:00
2014-08-21 23:08:34 +08:00
Data.pluginsLoading(false);
2014-08-25 15:10:51 +08:00
2014-08-20 23:03:12 +08:00
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);
2014-08-21 23:08:34 +08:00
Data.plugins(aList);
2014-08-20 23:03:12 +08:00
}
});
};
2014-08-20 23:03:12 +08:00
AdminApp.prototype.reloadPackagesList = function ()
{
2014-08-21 23:08:34 +08:00
Data.packagesLoading(true);
Data.packagesReal(true);
2014-08-21 23:08:34 +08:00
Remote.packagesList(function (sResult, oData) {
2014-08-21 23:08:34 +08:00
Data.packagesLoading(false);
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
2014-08-21 23:08:34 +08:00
Data.packagesReal(!!oData.Result.Real);
Data.packagesMainUpdatable(!!oData.Result.MainUpdatable);
2014-08-20 23:03:12 +08:00
var
aList = [],
aLoading = {}
;
2014-08-21 23:08:34 +08:00
_.each(Data.packages(), function (oItem) {
2014-08-20 23:03:12 +08:00
if (oItem && oItem['loading']())
{
2014-08-20 23:03:12 +08:00
aLoading[oItem['file']] = oItem;
}
2014-08-20 23:03:12 +08:00
});
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;
}));
}
2014-08-21 23:08:34 +08:00
Data.packages(aList);
}
2014-08-20 23:03:12 +08:00
else
{
2014-08-21 23:08:34 +08:00
Data.packagesReal(false);
2014-08-20 23:03:12 +08:00
}
});
};
2014-08-20 23:03:12 +08:00
AdminApp.prototype.updateCoreData = function ()
{
2014-08-21 23:08:34 +08:00
Data.coreUpdating(true);
Remote.updateCoreData(function (sResult, oData) {
2014-08-21 23:08:34 +08:00
Data.coreUpdating(false);
Data.coreRemoteVersion('');
Data.coreRemoteRelease('');
Data.coreVersionCompare(-2);
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
2014-08-21 23:08:34 +08:00
Data.coreReal(true);
2014-08-20 23:03:12 +08:00
window.location.reload();
}
else
{
2014-08-21 23:08:34 +08:00
Data.coreReal(false);
2014-08-20 23:03:12 +08:00
}
});
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
AdminApp.prototype.reloadCoreData = function ()
{
2014-08-21 23:08:34 +08:00
Data.coreChecking(true);
Data.coreReal(true);
2014-08-21 23:08:34 +08:00
Remote.coreData(function (sResult, oData) {
2014-08-21 23:08:34 +08:00
Data.coreChecking(false);
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
2014-08-21 23:08:34 +08:00
Data.coreReal(!!oData.Result.Real);
Data.coreUpdatable(!!oData.Result.Updatable);
Data.coreAccess(!!oData.Result.Access);
Data.coreRemoteVersion(oData.Result.RemoteVersion || '');
Data.coreRemoteRelease(oData.Result.RemoteRelease || '');
Data.coreVersionCompare(Utils.pInt(oData.Result.VersionCompare));
2014-08-20 23:03:12 +08:00
}
else
{
2014-08-21 23:08:34 +08:00
Data.coreReal(false);
Data.coreRemoteVersion('');
Data.coreRemoteRelease('');
Data.coreVersionCompare(-2);
2014-08-20 23:03:12 +08:00
}
});
};
2014-08-20 23:03:12 +08:00
/**
*
* @param {boolean=} bForce = false
*/
AdminApp.prototype.reloadLicensing = function (bForce)
{
bForce = Utils.isUnd(bForce) ? false : !!bForce;
2014-08-21 23:08:34 +08:00
Data.licensingProcess(true);
Data.licenseError('');
2014-08-20 23:03:12 +08:00
2014-08-21 23:08:34 +08:00
Remote.licensing(function (sResult, oData) {
Data.licensingProcess(false);
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && Utils.isNormal(oData.Result['Expired']))
{
2014-08-21 23:08:34 +08:00
Data.licenseValid(true);
Data.licenseExpired(Utils.pInt(oData.Result['Expired']));
Data.licenseError('');
2014-08-20 23:03:12 +08:00
2014-08-21 23:08:34 +08:00
Data.licensing(true);
}
else
{
2014-08-20 23:03:12 +08:00
if (oData && oData.ErrorCode && -1 < Utils.inArray(Utils.pInt(oData.ErrorCode), [
Enums.Notification.LicensingServerIsUnavailable,
Enums.Notification.LicensingExpired
]))
{
2014-08-21 23:08:34 +08:00
Data.licenseError(Utils.getNotification(Utils.pInt(oData.ErrorCode)));
Data.licensing(true);
}
else
{
2014-08-20 23:03:12 +08:00
if (Enums.StorageResultType.Abort === sResult)
{
2014-08-21 23:08:34 +08:00
Data.licenseError(Utils.getNotification(Enums.Notification.LicensingServerIsUnavailable));
Data.licensing(true);
2014-08-20 23:03:12 +08:00
}
else
{
2014-08-21 23:08:34 +08:00
Data.licensing(false);
2014-08-20 23:03:12 +08:00
}
}
}
2014-08-20 23:03:12 +08:00
}, bForce);
};
2014-08-20 23:03:12 +08:00
AdminApp.prototype.bootstart = function ()
{
2014-08-20 23:03:12 +08:00
AbstractApp.prototype.bootstart.call(this);
2014-08-21 23:08:34 +08:00
Data.populateDataOnStart();
2014-08-20 23:03:12 +08:00
kn.hideLoading();
2014-05-16 00:06:44 +08:00
2014-08-27 23:59:44 +08:00
if (!Settings.settingsGet('AllowAdminPanel'))
{
2014-08-20 23:03:12 +08:00
kn.routeOff();
2014-08-21 23:08:34 +08:00
kn.setHash(LinkBuilder.root(), true);
2014-08-20 23:03:12 +08:00
kn.routeOff();
2014-08-20 23:03:12 +08:00
_.defer(function () {
window.location.href = '/';
});
}
else
{
2014-08-27 23:59:44 +08:00
if (!!Settings.settingsGet('Auth'))
2014-08-20 23:03:12 +08:00
{
kn.startScreens([AdminSettingsScreen]);
}
else
{
kn.startScreens([AdminLoginScreen]);
}
}
if (window.SimplePace)
{
window.SimplePace.set(100);
}
2014-08-20 23:03:12 +08:00
};
2014-08-20 23:03:12 +08:00
module.exports = new AdminApp();
2014-09-05 06:49:03 +08:00
}());