snappymail/dev/Settings/Admin/Plugins.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { StorageResultType, Notification } from 'Common/Enums';
import { getNotification } from 'Common/Translator';
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
2014-08-25 15:10:51 +08:00
2016-07-16 05:29:42 +08:00
import PluginStore from 'Stores/Admin/Plugin';
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
import Remote from 'Remote/Admin/Ajax';
2015-05-03 04:22:32 +08:00
2019-07-05 03:19:24 +08:00
import { getApp } from 'Helper/Apps/Admin';
2019-07-05 03:19:24 +08:00
class PluginsAdminSettings {
2016-07-16 05:29:42 +08:00
constructor() {
this.enabledPlugins = ko.observable(!!rl.settings.get('EnabledPlugins'));
2015-11-19 01:32:29 +08:00
2016-07-16 05:29:42 +08:00
this.plugins = PluginStore.plugins;
this.pluginsError = PluginStore.plugins.error;
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
this.visibility = ko.computed(() => (PluginStore.plugins.loading() ? 'visible' : 'hidden'));
2014-08-21 23:08:34 +08:00
this.onPluginLoadRequest = this.onPluginLoadRequest.bind(this);
this.onPluginDisableRequest = this.onPluginDisableRequest.bind(this);
2016-07-16 05:29:42 +08:00
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
disablePlugin(plugin) {
plugin.disabled(!plugin.disabled());
Remote.pluginDisable(this.onPluginDisableRequest, plugin.name, plugin.disabled());
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
configurePlugin(plugin) {
Remote.plugin(this.onPluginLoadRequest, plugin.name);
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
onBuild(oDom) {
oDom.addEventListener('click', event => {
let el = event.target.closestWithin('.e-item .configure-plugin-action', oDom);
el && ko.dataFor(el) && this.configurePlugin(ko.dataFor(el));
el = event.target.closestWithin('.e-item .disabled-plugin', oDom);
el && ko.dataFor(el) && this.disablePlugin(ko.dataFor(el));
});
2016-07-16 05:29:42 +08:00
this.enabledPlugins.subscribe((value) => {
Remote.saveAdminConfig(null, {
'EnabledPlugins': value ? '1' : '0'
2016-07-16 05:29:42 +08:00
});
2016-06-30 08:02:45 +08:00
});
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
onShow() {
PluginStore.plugins.error('');
getApp().reloadPluginList();
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
onPluginLoadRequest(result, data) {
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data && data.Result) {
2016-07-16 05:29:42 +08:00
showScreenPopup(require('View/Popup/Plugin'), [data.Result]);
}
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
onPluginDisableRequest(result, data) {
2019-07-05 03:19:24 +08:00
if (StorageResultType.Success === result && data) {
if (!data.Result && data.ErrorCode) {
if (Notification.UnsupportedPluginPackage === data.ErrorCode && data.ErrorMessage && data.ErrorMessage) {
2016-07-16 05:29:42 +08:00
PluginStore.plugins.error(data.ErrorMessage);
2019-07-05 03:19:24 +08:00
} else {
2016-07-16 05:29:42 +08:00
PluginStore.plugins.error(getNotification(data.ErrorCode));
}
2014-08-21 23:08:34 +08:00
}
}
getApp().reloadPluginList();
2016-07-16 05:29:42 +08:00
}
}
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
export { PluginsAdminSettings, PluginsAdminSettings as default };