2014-08-21 23:08:34 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
|
|
|
|
|
|
|
'use strict';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Utils = require('Utils'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-26 23:24:47 +08:00
|
|
|
AppSettings = require('../../Storages/AppSettings.js'),
|
|
|
|
Data = require('../../Storages/AdminDataStorage.js'),
|
|
|
|
Remote = require('../../Storages/AdminAjaxRemoteStorage.js'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-26 23:24:47 +08:00
|
|
|
PopupsPluginViewModel = require('../../ViewModels/Popups/PopupsPluginViewModel.js')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function AdminSettingsPlugins()
|
|
|
|
{
|
2014-08-22 23:08:56 +08:00
|
|
|
this.enabledPlugins = ko.observable(!!AppSettings.settingsGet('EnabledPlugins'));
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.pluginsError = ko.observable('');
|
|
|
|
|
|
|
|
this.plugins = Data.plugins;
|
|
|
|
this.pluginsLoading = Data.pluginsLoading;
|
|
|
|
|
|
|
|
this.visibility = ko.computed(function () {
|
|
|
|
return Data.pluginsLoading() ? 'visible' : 'hidden';
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.onPluginLoadRequest = _.bind(this.onPluginLoadRequest, this);
|
|
|
|
this.onPluginDisableRequest = _.bind(this.onPluginDisableRequest, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
AdminSettingsPlugins.prototype.disablePlugin = function (oPlugin)
|
|
|
|
{
|
|
|
|
oPlugin.disabled(!oPlugin.disabled());
|
|
|
|
Remote.pluginDisable(this.onPluginDisableRequest, oPlugin.name, oPlugin.disabled());
|
|
|
|
};
|
|
|
|
|
|
|
|
AdminSettingsPlugins.prototype.configurePlugin = function (oPlugin)
|
|
|
|
{
|
|
|
|
Remote.plugin(this.onPluginLoadRequest, oPlugin.name);
|
|
|
|
};
|
|
|
|
|
|
|
|
AdminSettingsPlugins.prototype.onBuild = function (oDom)
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
oDom
|
|
|
|
.on('click', '.e-item .configure-plugin-action', function () {
|
|
|
|
var oPlugin = ko.dataFor(this);
|
|
|
|
if (oPlugin)
|
|
|
|
{
|
|
|
|
self.configurePlugin(oPlugin);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('click', '.e-item .disabled-plugin', function () {
|
|
|
|
var oPlugin = ko.dataFor(this);
|
|
|
|
if (oPlugin)
|
|
|
|
{
|
|
|
|
self.disablePlugin(oPlugin);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
;
|
|
|
|
|
|
|
|
this.enabledPlugins.subscribe(function (bValue) {
|
|
|
|
Remote.saveAdminConfig(Utils.emptyFunction, {
|
|
|
|
'EnabledPlugins': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
AdminSettingsPlugins.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.pluginsError('');
|
2014-08-26 23:24:47 +08:00
|
|
|
require('../../Apps/AdminApp.js').reloadPluginList();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
AdminSettingsPlugins.prototype.onPluginLoadRequest = function (sResult, oData)
|
|
|
|
{
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
|
|
|
{
|
2014-08-25 23:49:01 +08:00
|
|
|
require('kn').showScreenPopup(PopupsPluginViewModel, [oData.Result]);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
AdminSettingsPlugins.prototype.onPluginDisableRequest = function (sResult, oData)
|
|
|
|
{
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData)
|
|
|
|
{
|
|
|
|
if (!oData.Result && oData.ErrorCode)
|
|
|
|
{
|
|
|
|
if (Enums.Notification.UnsupportedPluginPackage === oData.ErrorCode && oData.ErrorMessage && '' !== oData.ErrorMessage)
|
|
|
|
{
|
|
|
|
this.pluginsError(oData.ErrorMessage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.pluginsError(Utils.getNotification(oData.ErrorCode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 23:24:47 +08:00
|
|
|
require('../../Apps/AdminApp.js').reloadPluginList();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = AdminSettingsPlugins;
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|