snappymail/dev/Settings/Admin/Plugins.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
import { Notification } from 'Common/Enums';
2021-03-10 18:44:48 +08:00
import { SettingsGet } from 'Common/Globals';
2019-07-05 03:19:24 +08:00
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
import { PluginAdminStore } from 'Stores/Admin/Plugin';
2014-08-21 23:08:34 +08:00
import Remote from 'Remote/Admin/Fetch';
2015-05-03 04:22:32 +08:00
import { PluginPopupView } from 'View/Popup/Plugin';
2021-01-22 23:32:08 +08:00
export class PluginsAdminSettings {
2016-07-16 05:29:42 +08:00
constructor() {
2021-03-10 18:44:48 +08:00
this.enabledPlugins = ko.observable(!!SettingsGet('EnabledPlugins'));
2015-11-19 01:32:29 +08:00
this.plugins = PluginAdminStore;
this.pluginsError = PluginAdminStore.error;
2014-08-21 23:08:34 +08:00
this.onPluginLoadRequest = this.onPluginLoadRequest.bind(this);
this.onPluginDisableRequest = this.onPluginDisableRequest.bind(this);
2021-03-16 18:38:40 +08:00
this.enabledPlugins.subscribe(value =>
Remote.saveAdminConfig(null, {
EnabledPlugins: value ? 1 : 0
2021-03-16 18:38:40 +08:00
})
);
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
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
onShow() {
PluginAdminStore.error('');
PluginAdminStore.fetch();
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
onPluginLoadRequest(iError, data) {
2021-03-18 21:48:21 +08:00
if (!iError) {
showScreenPopup(PluginPopupView, [data.Result]);
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
onPluginDisableRequest(iError, data) {
if (iError) {
if (Notification.UnsupportedPluginPackage === iError && data && data.ErrorMessage) {
PluginAdminStore.error(data.ErrorMessage);
} else {
PluginAdminStore.error(getNotification(iError));
2014-08-21 23:08:34 +08:00
}
}
PluginAdminStore.fetch();
2016-07-16 05:29:42 +08:00
}
}