Corrige salvamento de projetos de quadrinhos com feedback visual e fallbacks inteligentes de titulo e tema
This commit is contained in:
+34
-5
@@ -4749,15 +4749,32 @@ Se algum dado não for mencionado, deixe a string vazia ou false para boolean.`
|
||||
|
||||
const saveComicsProjectFlow = async (forceNew = false) => {
|
||||
let titulo = comicsProjectTitleInput ? comicsProjectTitleInput.value.trim() : '';
|
||||
let tema = comicsTemaInput ? comicsTemaInput.value.trim() : '';
|
||||
|
||||
if (!titulo) {
|
||||
titulo = comicsResultTitle ? comicsResultTitle.textContent.trim() : 'Minha História em Quadrinhos';
|
||||
if (comicsResultTitle && comicsResultTitle.textContent.trim() && comicsResultTitle.textContent.trim() !== 'Resultado da História em Quadrinhos') {
|
||||
titulo = comicsResultTitle.textContent.trim();
|
||||
} else if (tema) {
|
||||
titulo = tema;
|
||||
} else {
|
||||
titulo = 'Minha História em Quadrinhos';
|
||||
}
|
||||
if (comicsProjectTitleInput) comicsProjectTitleInput.value = titulo;
|
||||
}
|
||||
|
||||
if (!tema) {
|
||||
tema = titulo;
|
||||
}
|
||||
|
||||
const characters = [];
|
||||
document.querySelectorAll('.comic-char-row').forEach(row => {
|
||||
const type = row.querySelector('.char-type-input').value.trim();
|
||||
const name = row.querySelector('.char-name-input').value.trim();
|
||||
const isAnimal = row.querySelector('.comic-char-animal-toggle').classList.contains('active');
|
||||
const typeInput = row.querySelector('.char-type-input');
|
||||
const nameInput = row.querySelector('.char-name-input');
|
||||
const animalToggle = row.querySelector('.comic-char-animal-toggle');
|
||||
|
||||
const type = typeInput ? typeInput.value.trim() : '';
|
||||
const name = nameInput ? nameInput.value.trim() : '';
|
||||
const isAnimal = animalToggle ? animalToggle.classList.contains('active') : false;
|
||||
if (type && name) {
|
||||
characters.push({ type, name, isAnimal });
|
||||
}
|
||||
@@ -4769,11 +4786,18 @@ Se algum dado não for mencionado, deixe a string vazia ou false para boolean.`
|
||||
}
|
||||
|
||||
const targetId = forceNew ? null : currentComicsProjectId;
|
||||
const activeBtn = forceNew ? btnSaveNewComicsProject : btnSaveComicsProject;
|
||||
const originalText = activeBtn ? activeBtn.textContent : '';
|
||||
|
||||
if (activeBtn) {
|
||||
activeBtn.disabled = true;
|
||||
activeBtn.textContent = '⏳ Salvando...';
|
||||
}
|
||||
|
||||
const body = {
|
||||
id: targetId,
|
||||
titulo,
|
||||
tema: comicsTemaInput.value.trim(),
|
||||
tema,
|
||||
cenario,
|
||||
proporcao: selectedComicsRatio,
|
||||
character_description_global: JSON.stringify(characters),
|
||||
@@ -4808,6 +4832,11 @@ Se algum dado não for mencionado, deixe a string vazia ou false para boolean.`
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await showCustomAlert('Erro', 'Erro ao salvar projeto: ' + err.message);
|
||||
} finally {
|
||||
if (activeBtn) {
|
||||
activeBtn.disabled = false;
|
||||
activeBtn.textContent = originalText;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user