2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2021-03-16 16:46:23 +08:00
|
|
|
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
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
import { PluginAdminStore } from 'Stores/Admin/Plugin';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2015-05-03 04:22:32 +08:00
|
|
|
|
2021-01-26 05:00:13 +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
|
|
|
|
2021-02-17 21:40:21 +08:00
|
|
|
this.plugins = PluginAdminStore;
|
|
|
|
this.pluginsError = PluginAdminStore.error;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-07-20 21:47:33 +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, {
|
2021-03-25 04:26:40 +08:00
|
|
|
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) {
|
2020-08-30 16:30:50 +08:00
|
|
|
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() {
|
2021-02-17 21:40:21 +08:00
|
|
|
PluginAdminStore.error('');
|
2021-03-15 05:36:23 +08:00
|
|
|
PluginAdminStore.fetch();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-16 16:46:23 +08:00
|
|
|
onPluginLoadRequest(iError, data) {
|
2021-03-18 21:48:21 +08:00
|
|
|
if (!iError) {
|
2021-01-26 05:00:13 +08:00
|
|
|
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
|
|
|
|
2021-03-16 16:46:23 +08:00
|
|
|
onPluginDisableRequest(iError, data) {
|
2021-03-18 19:33:13 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 05:36:23 +08:00
|
|
|
PluginAdminStore.fetch();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
}
|