Add modal manager to plugin API
This commit is contained in:
parent
e94a7c50a4
commit
fdc9330195
|
@ -138,6 +138,34 @@ export default class PluginApi {
|
|||
};
|
||||
}
|
||||
|
||||
get modalStack() {
|
||||
return this._modalStack || (this._modalStack = []);
|
||||
}
|
||||
addModal(modal, component) {
|
||||
const modal = Modals.add(modal);
|
||||
modal.close = force => this.closeModal(force);
|
||||
}
|
||||
async closeModal(modal, force) {
|
||||
await Modals.close(modal, force);
|
||||
this._modalStack = this.modalStack.filter(m => m !== modal);
|
||||
}
|
||||
closeAllModals() {
|
||||
for (let modal of this.modalStack)
|
||||
modal.close();
|
||||
}
|
||||
closeLastModal() {
|
||||
if (!this.modalStack.length) return;
|
||||
this.modalStack[this.modalStack.length - 1].close();
|
||||
}
|
||||
get Modals() {
|
||||
return {
|
||||
add: this.addModal.bind(this),
|
||||
close: this.closeModal.bind(this),
|
||||
closeAll: this.closeAllModals.bind(this),
|
||||
closeLastModal: this.closeLastModal.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
async getPlugin(plugin_id) {
|
||||
// This should require extra permissions
|
||||
return await PluginManager.waitForPlugin(plugin_id);
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
this.saving = true;
|
||||
try {
|
||||
if (this.modal.saveSettings) await this.modal.saveSettings(this.settings);
|
||||
else this.modal.settings.merge(this.settings);
|
||||
else await this.modal.settings.merge(this.settings);
|
||||
} catch (err) {
|
||||
// TODO Display error that settings failed to save
|
||||
Logger.err('SettingsModal', ['Failed to save settings:', err]);
|
||||
|
|
|
@ -122,13 +122,12 @@ export default class {
|
|||
}
|
||||
}
|
||||
|
||||
static settings(settings, headertext, saveSettings) {
|
||||
return this.add({
|
||||
headertext, settings, schemes: settings.schemes,
|
||||
saveSettings: saveSettings ? saveSettings : newSettings => {
|
||||
return settings.merge(newSettings);
|
||||
}
|
||||
}, SettingsModal);
|
||||
static settings(settingsset, headertext, options) {
|
||||
return this.add(Object.assign({
|
||||
headertext: headertext ? headertext : settingsset.headertext,
|
||||
settings: settingsset,
|
||||
schemes: settings.schemes
|
||||
}, options), SettingsModal);
|
||||
}
|
||||
|
||||
static internalSettings(set_id) {
|
||||
|
|
Loading…
Reference in New Issue