|
|
|
|
| import { StateManager } from '../services/state-manager.js';
|
| import { ApiService } from '../services/api-service.js';
|
| import { TranslationService } from '../services/translation-service.js';
|
|
|
| export const CommentComponent = {
|
| elements: {
|
| leaveCommentText: null,
|
| commentOverlay: null,
|
| closeCommentBtn: null,
|
| cancelCommentBtn: null,
|
| sendCommentBtn: null,
|
| commentInput: null,
|
| statusComment: null
|
| },
|
|
|
| |
| |
|
|
| init() {
|
| this.elements.leaveCommentText = document.getElementById('leave-comment');
|
| this.elements.commentOverlay = document.getElementById('comment-overlay');
|
| this.elements.closeCommentBtn = document.getElementById('closeCommentBtn');
|
| this.elements.cancelCommentBtn = document.getElementById('cancelCommentBtn');
|
| this.elements.sendCommentBtn = document.getElementById('sendCommentBtn');
|
| this.elements.commentInput = document.getElementById('commentInput');
|
| this.elements.statusComment = document.getElementById('commentStatus');
|
|
|
| this.attachOutsideClickListener();
|
| this.attachEventListeners();
|
| this.initializeStatus();
|
| },
|
|
|
| attachOutsideClickListener() {
|
| this.elements.commentOverlay.addEventListener('click', (e) => {
|
|
|
| if (e.target === this.elements.commentOverlay) {
|
| this.closeOverlay();
|
| }
|
| });
|
| },
|
|
|
| |
| |
|
|
| attachEventListeners() {
|
| this.elements.leaveCommentText.addEventListener('click', (e) => this.openOverlay(e));
|
| this.elements.closeCommentBtn.addEventListener('click', () => this.closeOverlay());
|
| this.elements.cancelCommentBtn.addEventListener('click', () => this.closeOverlay());
|
| this.elements.sendCommentBtn.addEventListener('click', () => this.sendComment());
|
|
|
|
|
| this.elements.commentInput.addEventListener('keydown', (e) => {
|
| if (e.key === 'Enter' && !e.shiftKey) {
|
| e.preventDefault();
|
| this.sendComment();
|
| }
|
| });
|
| },
|
|
|
| |
| |
|
|
| initializeStatus() {
|
| this.elements.statusComment.dataset.i18n = "ready";
|
| this.elements.statusComment.className = 'status-ok';
|
| TranslationService.applyTranslation();
|
| },
|
|
|
| |
| |
|
|
| openOverlay(e) {
|
| e.preventDefault();
|
| this.elements.commentOverlay.style.display = '';
|
| },
|
|
|
| |
| |
|
|
| closeOverlay() {
|
| this.elements.commentOverlay.style.display = 'none';
|
| },
|
|
|
| |
| |
|
|
| async sendComment() {
|
| const comment = this.elements.commentInput.value;
|
| if (!comment) return;
|
|
|
| this.setStatus('sending', 'info');
|
|
|
| const result = await ApiService.sendComment(comment);
|
|
|
| if (!result.success) {
|
| if (result.status === 400) {
|
| this.setStatus('empty_message_error', 'error');
|
| } else {
|
| this.setStatus('server_error', 'error');
|
| }
|
| return;
|
| }
|
|
|
| this.elements.commentInput.value = '';
|
| this.setStatus('comment_sent', 'ok');
|
| },
|
|
|
| |
| |
| |
| |
|
|
| setStatus(messageKey, type) {
|
| this.elements.statusComment.dataset.i18n = messageKey;
|
| this.elements.statusComment.className = `status-${type}`;
|
| TranslationService.applyTranslation();
|
| }
|
| }; |