2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
2014-08-25 23:49:01 +08:00
|
|
|
|
2021-03-18 19:33:13 +08:00
|
|
|
import { Scope } from 'Common/Enums';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { getNotification, i18n } from 'Common/Translator';
|
2021-07-22 03:34:17 +08:00
|
|
|
import { arrayLength } from 'Common/Utils';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-02-04 16:49:55 +08:00
|
|
|
import { decorateKoCommands, showScreenPopup } from 'Knoin/Knoin';
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
2021-01-26 05:00:13 +08:00
|
|
|
import { AskPopupView } from 'View/Popup/Ask';
|
2021-01-24 17:25:23 +08:00
|
|
|
|
|
|
|
class PluginPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('Plugin');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
saveError: '',
|
2021-08-09 17:13:10 +08:00
|
|
|
id: '',
|
2020-10-26 19:54:03 +08:00
|
|
|
name: '',
|
|
|
|
readme: ''
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-02-10 00:48:05 +08:00
|
|
|
this.config = ko.observableArray();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-09-03 22:37:20 +08:00
|
|
|
this.addComputables({
|
|
|
|
hasReadme: () => !!this.readme(),
|
2022-02-10 00:48:05 +08:00
|
|
|
hasConfiguration: () => 0 < this.config().length
|
2021-09-03 22:37:20 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
this.bDisabeCloseOnEsc = true;
|
2021-09-23 02:17:44 +08:00
|
|
|
this.keyScope.scope = Scope.All;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-08-19 02:24:17 +08:00
|
|
|
this.tryToClosePopup = this.tryToClosePopup.debounce(200);
|
2021-02-19 19:09:20 +08:00
|
|
|
|
|
|
|
decorateKoCommands(this, {
|
|
|
|
saveCommand: self => self.hasConfiguration()
|
|
|
|
});
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
saveCommand() {
|
2021-12-03 07:11:19 +08:00
|
|
|
const oConfig = {
|
2021-08-09 17:13:10 +08:00
|
|
|
Id: this.id(),
|
|
|
|
Settings: {}
|
|
|
|
};
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-02-10 00:48:05 +08:00
|
|
|
this.config.forEach(oItem => {
|
2016-09-10 06:38:16 +08:00
|
|
|
let value = oItem.value();
|
2019-07-05 03:19:24 +08:00
|
|
|
if (false === value || true === value) {
|
2021-08-09 17:13:10 +08:00
|
|
|
value = value ? 1 : 0;
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2021-12-03 07:11:19 +08:00
|
|
|
oConfig.Settings[oItem.Name] = value;
|
2016-09-10 06:38:16 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
this.saveError('');
|
2021-12-03 07:11:19 +08:00
|
|
|
Remote.request('AdminPluginSettingsUpdate',
|
|
|
|
iError => iError
|
2021-04-23 16:47:24 +08:00
|
|
|
? this.saveError(getNotification(iError))
|
2021-12-03 07:11:19 +08:00
|
|
|
: this.cancelCommand(),
|
|
|
|
oConfig);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2013-12-14 07:27:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow(oPlugin) {
|
2021-08-09 17:13:10 +08:00
|
|
|
this.id('');
|
2020-09-28 16:29:58 +08:00
|
|
|
this.name('');
|
|
|
|
this.readme('');
|
2022-02-10 00:48:05 +08:00
|
|
|
this.config([]);
|
2014-08-27 23:59:44 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (oPlugin) {
|
2021-08-09 17:13:10 +08:00
|
|
|
this.id(oPlugin.Id);
|
2016-08-17 06:01:20 +08:00
|
|
|
this.name(oPlugin.Name);
|
|
|
|
this.readme(oPlugin.Readme);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const config = oPlugin.Config;
|
2021-07-22 03:34:17 +08:00
|
|
|
if (arrayLength(config)) {
|
2022-02-10 00:48:05 +08:00
|
|
|
this.config(
|
|
|
|
config.map(item => {
|
|
|
|
item.value = ko.observable(item.value);
|
|
|
|
return item;
|
|
|
|
})
|
2019-07-05 03:19:24 +08:00
|
|
|
);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
tryToClosePopup() {
|
2022-02-04 16:49:55 +08:00
|
|
|
if (AskPopupView.hidden()) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(AskPopupView, [
|
2019-07-05 03:19:24 +08:00
|
|
|
i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'),
|
2021-07-16 15:11:10 +08:00
|
|
|
() => this.modalVisibility() && this.cancelCommand()
|
2019-07-05 03:19:24 +08:00
|
|
|
]);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onBuild() {
|
2021-03-16 23:06:16 +08:00
|
|
|
shortcuts.add('escape', '', Scope.All, () => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.modalVisibility()) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.tryToClosePopup();
|
2021-08-13 16:03:13 +08:00
|
|
|
return false;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { PluginPopupView, PluginPopupView as default };
|