snappymail/dev/Settings/Admin/Plugins.js

112 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
2016-06-07 05:57:52 +08:00
/* global RL_COMMUNITY */
2016-06-30 08:02:45 +08:00
var
_ = require('_'),
ko = require('ko'),
2016-06-30 08:02:45 +08:00
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
Translator = require('Common/Translator'),
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
Settings = require('Storage/Settings'),
2014-08-25 15:10:51 +08:00
2016-06-30 08:02:45 +08:00
AppStore = require('Stores/Admin/App'),
PluginStore = require('Stores/Admin/Plugin'),
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
Remote = require('Remote/Admin/Ajax');
2015-05-03 04:22:32 +08:00
2016-06-30 08:02:45 +08:00
/**
* @constructor
*/
function PluginsAdminSettings()
{
this.enabledPlugins = ko.observable(!!Settings.settingsGet('EnabledPlugins'));
2015-11-19 01:32:29 +08:00
2016-06-30 08:02:45 +08:00
this.plugins = PluginStore.plugins;
this.pluginsError = PluginStore.plugins.error;
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.community = RL_COMMUNITY || AppStore.community();
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.visibility = ko.computed(function() {
return PluginStore.plugins.loading() ? 'visible' : 'hidden';
}, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.onPluginLoadRequest = _.bind(this.onPluginLoadRequest, this);
this.onPluginDisableRequest = _.bind(this.onPluginDisableRequest, this);
}
2015-05-03 04:22:32 +08:00
2016-06-30 08:02:45 +08:00
PluginsAdminSettings.prototype.disablePlugin = function(oPlugin)
{
oPlugin.disabled(!oPlugin.disabled());
Remote.pluginDisable(this.onPluginDisableRequest, oPlugin.name, oPlugin.disabled());
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
PluginsAdminSettings.prototype.configurePlugin = function(oPlugin)
{
Remote.plugin(this.onPluginLoadRequest, oPlugin.name);
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
PluginsAdminSettings.prototype.onBuild = function(oDom)
{
var self = this;
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
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);
}
2014-08-21 23:08:34 +08:00
});
2016-06-30 08:02:45 +08:00
this.enabledPlugins.subscribe(function(bValue) {
Remote.saveAdminConfig(Utils.noop, {
'EnabledPlugins': bValue ? '1' : '0'
});
});
};
PluginsAdminSettings.prototype.onShow = function()
{
PluginStore.plugins.error('');
require('App/Admin').default.reloadPluginList();
};
PluginsAdminSettings.prototype.onPluginLoadRequest = function(sResult, oData)
{
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Plugin'), [oData.Result]);
}
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
PluginsAdminSettings.prototype.onPluginDisableRequest = function(sResult, oData)
{
if (Enums.StorageResultType.Success === sResult && oData)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
if (!oData.Result && oData.ErrorCode)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
if (Enums.Notification.UnsupportedPluginPackage === oData.ErrorCode && oData.ErrorMessage && '' !== oData.ErrorMessage)
{
PluginStore.plugins.error(oData.ErrorMessage);
}
else
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
PluginStore.plugins.error(Translator.getNotification(oData.ErrorCode));
2014-08-21 23:08:34 +08:00
}
}
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
require('App/Admin').default.reloadPluginList();
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
module.exports = PluginsAdminSettings;