discourse/app/assets/javascripts/admin/addon/models/form-template.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-02-09 03:21:39 +08:00
import RestModel from "discourse/models/rest";
import { ajax } from "discourse/lib/ajax";
export default class FormTemplate extends RestModel {
static createTemplate(data) {
2023-02-09 03:21:39 +08:00
return ajax("/admin/customize/form-templates.json", {
type: "POST",
data,
});
}
2023-02-09 03:21:39 +08:00
static updateTemplate(id, data) {
2023-02-09 03:21:39 +08:00
return ajax(`/admin/customize/form-templates/${id}.json`, {
type: "PUT",
data,
});
}
2023-02-09 03:21:39 +08:00
static createOrUpdateTemplate(data) {
if (data.id) {
return this.updateTemplate(data.id, data);
} else {
return this.createTemplate(data);
}
}
static deleteTemplate(id) {
2023-02-09 03:21:39 +08:00
return ajax(`/admin/customize/form-templates/${id}.json`, {
type: "DELETE",
});
}
2023-02-09 03:21:39 +08:00
static async findAll() {
const result = await ajax("/admin/customize/form-templates.json");
return result.form_templates;
}
2023-02-09 03:21:39 +08:00
static async findById(id) {
const result = await ajax(`/admin/customize/form-templates/${id}.json`);
return result.form_template;
}
static validateTemplate(data) {
return ajax(`/admin/customize/form-templates/preview.json`, {
type: "GET",
data,
});
}
}