mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
editor form
This commit is contained in:
@ -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
|
||||
Reference in New Issue
Block a user