cancel and skip buttons #26
This commit is contained in:
parent
038d473a4f
commit
aa7659ee1f
9 changed files with 144 additions and 51 deletions
|
|
@ -2,27 +2,33 @@ import {App, Modal, Setting} from 'obsidian';
|
|||
import {SelectModalElement} from './SelectModalElement';
|
||||
|
||||
export abstract class SelectModal<T> extends Modal {
|
||||
multiSelect: boolean;
|
||||
allowMultiSelect: boolean;
|
||||
|
||||
title: string;
|
||||
description: string;
|
||||
skipButton: boolean;
|
||||
|
||||
elements: T[];
|
||||
selectModalElements: SelectModalElement<T>[];
|
||||
|
||||
|
||||
constructor(app: App, elements: T[]) {
|
||||
protected constructor(app: App, elements: T[]) {
|
||||
super(app);
|
||||
this.elements = elements;
|
||||
this.allowMultiSelect = true;
|
||||
|
||||
this.title = '';
|
||||
this.description = '';
|
||||
this.skipButton = false;
|
||||
|
||||
this.elements = elements;
|
||||
this.selectModalElements = [];
|
||||
}
|
||||
|
||||
abstract renderElement(value: T, el: HTMLElement): any;
|
||||
|
||||
abstract onSubmit(): void;
|
||||
abstract submit(): void;
|
||||
|
||||
abstract skip(): void;
|
||||
|
||||
disableAllOtherElements(elementId: number) {
|
||||
for (const selectModalElement of this.selectModalElements) {
|
||||
|
|
@ -35,23 +41,17 @@ export abstract class SelectModal<T> extends Modal {
|
|||
async onOpen() {
|
||||
const {contentEl} = this;
|
||||
|
||||
/*
|
||||
contentEl.id = 'media-db-plugin-modal'
|
||||
|
||||
contentEl.on('keydown', '#' + contentEl.id, (ev, delegateTarget) => {
|
||||
console.log(ev.key);
|
||||
});
|
||||
*/
|
||||
|
||||
contentEl.createEl('h2', {text: this.title});
|
||||
contentEl.createEl('p', {text: this.description});
|
||||
|
||||
if (this.allowMultiSelect) {
|
||||
new Setting(contentEl)
|
||||
.setName('Select Multiple')
|
||||
.addToggle(cb => {
|
||||
cb.setValue(this.multiSelect);
|
||||
cb.onChange(value => {
|
||||
this.multiSelect = value;
|
||||
for (const selectModalElement of this.selectModalElements) {
|
||||
selectModalElement.setActive(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const elementWrapper = contentEl.createDiv({cls: 'media-db-plugin-select-wrapper'});
|
||||
|
||||
let i = 0;
|
||||
|
|
@ -65,8 +65,11 @@ export abstract class SelectModal<T> extends Modal {
|
|||
i += 1;
|
||||
}
|
||||
|
||||
new Setting(contentEl)
|
||||
.addButton(btn => btn.setButtonText('Cancel').onClick(() => this.close()))
|
||||
.addButton(btn => btn.setButtonText('Ok').setCta().onClick(() => this.onSubmit()));
|
||||
const bottomSetting = new Setting(contentEl);
|
||||
bottomSetting.addButton(btn => btn.setButtonText('Cancel').onClick(() => this.close()));
|
||||
if (this.skipButton) {
|
||||
bottomSetting.addButton(btn => btn.setButtonText('Skip').onClick(() => this.skip()));
|
||||
}
|
||||
bottomSetting.addButton(btn => btn.setButtonText('Ok').setCta().onClick(() => this.submit()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue