wiki features

This commit is contained in:
amazuecos
2025-02-23 00:14:07 +01:00
parent f270b6dee8
commit eea947e80b
13 changed files with 251 additions and 33 deletions

View File

@ -17,7 +17,23 @@ export const alertConfirmationDelete = (title, type = "primary") => {
buttonsStyling: false
})
}
export const alertConfirmAction = (title, type = "primary") => {
return Swal.fire({
title: '¿Está seguro?',
text: title,
icon: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Sí',
cancelButtonText: 'Cancelar',
customClass: {
confirmButton: 'btn btn-success me-1',
cancelButton: 'btn btn-label-secondary'
},
buttonsStyling: false
})
}
export const alertSuccessMessage = (title, type = "primary") => {
return Swal.fire({
showCancelButton: false,

View File

@ -11,7 +11,7 @@ import '../../../../../themes/vuexy/js/editorjs/tune.js';
import Ajax from '../ajax.js'
import { alertError, alertSuccess, alertWarning } from '../alerts/sweetAlert.js';
import { alertConfirmAction, alertError, alertSuccess, alertWarning } from '../alerts/sweetAlert.js';
class WikiEditor {
constructor() {
@ -48,7 +48,6 @@ class WikiEditor {
class: Alert,
inlineToolbar: true,
tunes : ['alignment'],
shortcut: 'CMD+SHIFT+W',
config: {
alertTypes: ['primary', 'secondary', 'info', 'success', 'warning', 'danger', 'light', 'dark'],
defaultType: 'primary',
@ -102,19 +101,41 @@ class WikiEditor {
new DragDrop(this.editor);
/** Do anything you need after editor initialization */
$('#save-editor').on('click', () => {
this.editor.save().then(outputData => {
this.editor.readOnly.toggle()
console.log("Data saved", outputData)
this.handleSaveContent(outputData)
alertConfirmAction('Guardar contenido').then(result => {
if(result.isConfirmed){
this.handleSaveContent(outputData)
}
});
})
})
$('#release-editor').on('click', () => {
this.editor.save().then(outputData => {
this.editor.readOnly.toggle()
console.log("Data published", outputData)
alertConfirmAction('Publicar contenido').then(result => {
if(result.isConfirmed){
this.handlePublishContent(outputData)
}
});
})
})
$('#preview-editor').on('click', () => {
this.editor.readOnly.toggle()
$('#edit-editor').removeClass('d-none')
$('#preview-editor').addClass('d-none')
$('#release-editor').attr('disabled',null)
$('#save-editor').attr('disabled',null)
})
$('#edit-editor').on('click', () => {
$('#edit-editor').addClass('d-none')
$('#preview-editor').removeClass('d-none')
$('#release-editor').attr('disabled','disabled')
$('#save-editor').attr('disabled','disabled')
this.editor.readOnly.toggle()
})
this.handleGetData();
@ -143,6 +164,26 @@ class WikiEditor {
handleGetDataError(error) {
console.log(error)
}
handleGetDataPublished() {
const ajax = new Ajax(`/wiki/section/${this.sectionId}`,
null,
null,
this.handleGetDataSuccess.bind(this),
this.handleGetDataError.bind(this))
ajax.get()
}
handleGetDataPublishedSuccess(response) {
if (response.data.contents) {
alertSuccess(response.message).fire()
this.renderContent(response.data.contents.editor_data)
} else {
alertWarning('No hay contenido').fire()
}
}
handleGetDataPublishedError(error) {
alertError(error.error).fire()
}
renderContent(content) {
try {
let parsedContent = JSON.parse(content)
@ -162,7 +203,18 @@ class WikiEditor {
}
handleSaveContentSuccess(response) {
this.handleGetData()
// alertSuccess(response.message).fire()
}
handleSaveContentError(response) { }
handlePublishContent(data) {
const ajax = new Ajax(`/wiki/publish/${this.sectionId}`,
data,
null,
this.handleSaveContentSuccess.bind(this),
this.handleSaveContentError.bind(this))
ajax.post()
}
handleSaveContentSuccess(response) {
this.handleGetData()
}
handleSaveContentError(response) { }