editor form

This commit is contained in:
amazuecos
2025-02-25 18:41:59 +01:00
parent eea947e80b
commit 3406fb3005
23 changed files with 503 additions and 145 deletions

View File

@ -0,0 +1,76 @@
import Ajax from "../ajax.js";
import { alertError, alertSuccess } from "../alerts/sweetAlert.js";
class WikiSectionForm
{
constructor() {
this.item = $("#formSection")
this.btnNew = $("#submit-new-section")
this.btnUpdate = $("#submit-update-section")
this.name = this.item.find('#section-name')
this.icon = this.item.find('#section-icon')
}
initPost()
{
this.showPost()
this.btnNew.on('click',this.post.bind(this))
this.btnUpdate.off('click')
}
initUpdate()
{
this.showUpdate()
this.btnUpdate.on('click',this.update.bind(this))
this.btnNew.off('click')
}
getFormData()
{
return {
name : this.name.val(),
icon : this.icon.val()
}
}
post(){
const ajax = new Ajax('/wiki/section',
this.getFormData(),
null,
this.success.bind(this),
this.error.bind(this)
)
ajax.post()
}
update(){
const ajax = new Ajax('/wiki/update/section',
this.getFormData(),
null,
this.success.bind(this),
this.error.bind(this)
)
ajax.post()
}
success(response)
{
alertSuccess(response.message).fire()
}
error(error)
{
alertError(error?.message).fire()
}
showPost(){
this.btnNew.removeClass('d-none')
this.btnUpdate.addClass('d-none')
}
showUpdate(){
this.btnUpdate.removeClass('d-none')
this.btnNew.addClass('d-none')
}
}
export default WikiSectionForm