- closeUpdateForm() {
- if (!this.editingComment) return;
- this.editingComment.querySelector('[comment-content]').style.display = 'block';
- this.editingComment.querySelector('[comment-edit-container]').style.display = 'none';
- }
-
- editComment(commentElem) {
- this.hideForm();
- if (this.editingComment) this.closeUpdateForm();
- commentElem.querySelector('[comment-content]').style.display = 'none';
- commentElem.querySelector('[comment-edit-container]').style.display = 'block';
- const textArea = commentElem.querySelector('[comment-edit-container] textarea');
- const lineCount = textArea.value.split('\n').length;
- textArea.style.height = `${(lineCount * 20) + 40}px`;
- this.editingComment = commentElem;
- }
-
- updateComment(event) {
- const form = event.target;
- event.preventDefault();
- const text = form.querySelector('textarea').value;
- const reqData = {
- text,
- parent_id: this.parentId || null,
- };
- this.showLoading(form);
- const commentId = this.editingComment.getAttribute('comment');
- window.$http.put(`/comment/${commentId}`, reqData).then(resp => {
- const newComment = document.createElement('div');
- newComment.innerHTML = resp.data;
- this.editingComment.innerHTML = newComment.children[0].innerHTML;
- window.$events.success(this.updatedText);
- window.$components.init(this.editingComment);
- this.closeUpdateForm();
- this.editingComment = null;
- }).catch(window.$events.showValidationErrors).then(() => {
- this.hideLoading(form);
- });
- }
-
- deleteComment(commentElem) {
- const id = commentElem.getAttribute('comment');
- this.showLoading(commentElem.querySelector('[comment-content]'));
- window.$http.delete(`/comment/${id}`).then(() => {
- commentElem.parentNode.removeChild(commentElem);
- window.$events.success(this.deletedText);