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

52 lines
1.2 KiB
JavaScript

import RestModel from "discourse/models/rest";
import { ajax } from "discourse/lib/ajax";
export default class FormTemplate extends RestModel {
static createTemplate(data) {
return ajax("/admin/customize/form-templates.json", {
type: "POST",
data,
});
}
static updateTemplate(id, data) {
return ajax(`/admin/customize/form-templates/${id}.json`, {
type: "PUT",
data,
});
}
static createOrUpdateTemplate(data) {
if (data.id) {
return this.updateTemplate(data.id, data);
} else {
return this.createTemplate(data);
}
}
static deleteTemplate(id) {
return ajax(`/admin/customize/form-templates/${id}.json`, {
type: "DELETE",
});
}
static findAll() {
return ajax(`/admin/customize/form-templates.json`).then((model) => {
return model.form_templates.sort((a, b) => a.id - b.id);
});
}
static findById(id) {
return ajax(`/admin/customize/form-templates/${id}.json`).then((model) => {
return model.form_template;
});
}
static validateTemplate(data) {
return ajax(`/admin/customize/form-templates/preview.json`, {
type: "GET",
data,
});
}
}