Add a base class for chooser factories

pull/8934/head
Matt Westcott 2022-07-06 14:57:03 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic ac4220d88e
commit d4c146ad01
4 zmienionych plików z 31 dodań i 45 usunięć

Wyświetl plik

@ -138,3 +138,22 @@ export class Chooser {
});
}
}
export class ChooserFactory {
widgetClass = Chooser;
constructor(html, idPattern) {
this.html = html;
this.idPattern = idPattern;
}
render(placeholder, name, id, initialState) {
const html = this.html.replace(/__NAME__/g, name).replace(/__ID__/g, id);
// eslint-disable-next-line no-param-reassign
placeholder.outerHTML = html;
// eslint-disable-next-line new-cap
const chooser = new this.widgetClass(id);
chooser.setState(initialState);
return chooser;
}
}

Wyświetl plik

@ -1,19 +1,8 @@
class DocumentChooserFactory {
constructor(html, idPattern) {
this.html = html;
this.idPattern = idPattern;
}
import { ChooserFactory } from '../../components/ChooserWidget';
render(placeholder, name, id, initialState) {
const html = this.html.replace(/__NAME__/g, name).replace(/__ID__/g, id);
// eslint-disable-next-line no-param-reassign
placeholder.outerHTML = html;
/* the DocumentChooser object also serves as the JS widget representation */
// eslint-disable-next-line no-undef
const chooser = new DocumentChooser(id);
chooser.setState(initialState);
return chooser;
}
class DocumentChooserFactory extends ChooserFactory {
// eslint-disable-next-line no-undef
widgetClass = DocumentChooser;
}
window.telepath.register(
'wagtail.documents.widgets.DocumentChooser',

Wyświetl plik

@ -1,19 +1,8 @@
class ImageChooserFactory {
constructor(html, idPattern) {
this.html = html;
this.idPattern = idPattern;
}
import { ChooserFactory } from '../../components/ChooserWidget';
render(placeholder, name, id, initialState) {
const html = this.html.replace(/__NAME__/g, name).replace(/__ID__/g, id);
// eslint-disable-next-line no-param-reassign
placeholder.outerHTML = html;
/* the ImageChooser object also serves as the JS widget representation */
// eslint-disable-next-line no-undef
const chooser = new ImageChooser(id);
chooser.setState(initialState);
return chooser;
}
class ImageChooserFactory extends ChooserFactory {
// eslint-disable-next-line no-undef
widgetClass = ImageChooser;
}
window.telepath.register(
'wagtail.images.widgets.ImageChooser',

Wyświetl plik

@ -1,19 +1,8 @@
class SnippetChooserFactory {
constructor(html, idPattern) {
this.html = html;
this.idPattern = idPattern;
}
import { ChooserFactory } from '../../components/ChooserWidget';
render(placeholder, name, id, initialState) {
const html = this.html.replace(/__NAME__/g, name).replace(/__ID__/g, id);
// eslint-disable-next-line no-param-reassign
placeholder.outerHTML = html;
/* the SnippetChooser object also serves as the JS widget representation */
// eslint-disable-next-line no-undef
const chooser = new SnippetChooser(id);
chooser.setState(initialState);
return chooser;
}
class SnippetChooserFactory extends ChooserFactory {
// eslint-disable-next-line no-undef
widgetClass = SnippetChooser;
}
window.telepath.register(
'wagtail.snippets.widgets.SnippetChooser',