Фикс для динмаического добавления и редактирования

This commit is contained in:
Никита Потапов 2023-11-12 17:37:54 +04:00
parent 0f688cd350
commit 53d6a412fd
2 changed files with 31 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -42,8 +42,9 @@ let currentEditPostId = null;
async function buttonPostPublicationClicked() {
let text = document.getElementById("post-editor").value.trim();
const img = document.getElementById("input-title-image").files[0];
var check = document.getElementById("check-title-image").checked;
if (text == "" && img == null) {
if (text == "" && check) {
return;
}
@ -59,7 +60,9 @@ let imgBase64 = null;
var post = createPostObject(1, new Date(), text, imgBase64);
await postApiEndpoint.createObject(post);
location.reload();
showImage(null);
document.getElementById("post-editor").value = "";
await loadPosts();
}
async function postObjectEdit(e) {
@ -67,7 +70,7 @@ async function postObjectEdit(e) {
const img = document.getElementById("input-title-image").files[0];
var check = document.getElementById("check-title-image").checked;
if (text == "" && img == null && check) {
if (text == "" && !check) {
return;
}
@ -88,7 +91,12 @@ async function postObjectEdit(e) {
}
await postApiEndpoint.updateObject(post);
location.reload();
document.getElementById("edit-block").style.display = "none";
document.getElementById("post-publication-button").style.display = "block";
currentEditPostId = null;
showImage(null);
document.getElementById("post-editor").value = "";
await loadPosts();
}
async function editPost(e) {
@ -110,7 +118,10 @@ async function loadPosts() {
document.getElementById("edit-block").style.display = "none";
document.getElementById("edit-post-button-cancel").addEventListener('click', () => {location.reload();});
document.getElementById("edit-post-button-accept").addEventListener('click', postObjectEdit);
const posts = await postApiEndpoint.getObjects();
var posts = await postApiEndpoint.getObjects();
posts.sort((a, b) => (a.createdDateTime < b.createdDateTime ? 1 : -1));
const center = document.getElementsByClassName("posts-wrapper")[0];
center.innerHTML = "";
for (let i = 0; i < posts.length; i++) {
@ -181,7 +192,7 @@ function showImage(img) {
var check = document.getElementById("check-title-image");
var preview = document.getElementById("title-image-preview");
// if (check != null) check.checked = true;
if (check != null) check.checked = false;
if (img != null) {
var src = img;
previewEmpty.style.display = "none";