2016-07-16 05:29:42 +08:00
|
|
|
import _ from '_';
|
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { StorageResultType, Notification } from 'Common/Enums';
|
|
|
|
import { getNotification } from 'Common/Translator';
|
|
|
|
import { boolToAjax } from 'Common/Utils';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { settingsGet } from 'Storage/Settings';
|
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import AppStore from 'Stores/Admin/App';
|
|
|
|
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';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class PluginsAdminSettings {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
|
|
|
this.enabledPlugins = ko.observable(!!settingsGet('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.community = RL_COMMUNITY || AppStore.community();
|
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
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.onPluginLoadRequest = _.bind(this.onPluginLoadRequest, this);
|
|
|
|
this.onPluginDisableRequest = _.bind(this.onPluginDisableRequest, this);
|
|
|
|
}
|
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) {
|
|
|
|
const self = this;
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
oDom
|
2019-07-05 03:19:24 +08:00
|
|
|
.on('click', '.e-item .configure-plugin-action', function() {
|
|
|
|
// eslint-disable-line prefer-arrow-callback
|
2016-08-17 06:01:20 +08:00
|
|
|
const plugin = ko.dataFor(this); // eslint-disable-line no-invalid-this
|
2019-07-05 03:19:24 +08:00
|
|
|
if (plugin) {
|
2016-07-16 05:29:42 +08:00
|
|
|
self.configurePlugin(plugin);
|
|
|
|
}
|
|
|
|
})
|
2019-07-05 03:19:24 +08:00
|
|
|
.on('click', '.e-item .disabled-plugin', function() {
|
|
|
|
// eslint-disable-line prefer-arrow-callback
|
2016-08-17 06:01:20 +08:00
|
|
|
const plugin = ko.dataFor(this); // eslint-disable-line no-invalid-this
|
2019-07-05 03:19:24 +08:00
|
|
|
if (plugin) {
|
2016-07-16 05:29:42 +08:00
|
|
|
self.disablePlugin(plugin);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.enabledPlugins.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'EnabledPlugins': boolToAjax(value)
|
|
|
|
});
|
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('');
|
2016-08-17 06:01:20 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +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 };
|