2023-02-09 03:21:39 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2023-10-11 02:38:59 +08:00
|
|
|
import RestModel from "discourse/models/rest";
|
2023-02-09 03:21:39 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
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-03-17 18:18:42 +08:00
|
|
|
}
|
2023-02-09 03:21:39 +08:00
|
|
|
|
2023-03-17 18:18:42 +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-03-17 18:18:42 +08:00
|
|
|
}
|
2023-02-09 03:21:39 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static createOrUpdateTemplate(data) {
|
2023-03-02 03:07:13 +08:00
|
|
|
if (data.id) {
|
|
|
|
return this.updateTemplate(data.id, data);
|
|
|
|
} else {
|
|
|
|
return this.createTemplate(data);
|
|
|
|
}
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2023-03-02 03:07:13 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static deleteTemplate(id) {
|
2023-02-09 03:21:39 +08:00
|
|
|
return ajax(`/admin/customize/form-templates/${id}.json`, {
|
|
|
|
type: "DELETE",
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2023-02-09 03:21:39 +08:00
|
|
|
|
2023-05-30 05:47:18 +08:00
|
|
|
static async findAll() {
|
|
|
|
const result = await ajax("/admin/customize/form-templates.json");
|
|
|
|
return result.form_templates;
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2023-02-09 03:21:39 +08:00
|
|
|
|
2023-05-30 05:47:18 +08:00
|
|
|
static async findById(id) {
|
|
|
|
const result = await ajax(`/admin/customize/form-templates/${id}.json`);
|
|
|
|
return result.form_template;
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2023-03-02 03:07:13 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static validateTemplate(data) {
|
2023-03-02 03:07:13 +08:00
|
|
|
return ajax(`/admin/customize/form-templates/preview.json`, {
|
|
|
|
type: "GET",
|
|
|
|
data,
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
|
|
|
}
|