|
1 | 1 | 'use strict'; |
| 2 | + |
| 3 | + |
2 | 4 | define('forum/topic', [ |
3 | 5 | 'forum/infinitescroll', |
4 | 6 | 'forum/topic/threadTools', |
@@ -69,14 +71,28 @@ define('forum/topic', [ |
69 | 71 | handleThumbs(); |
70 | 72 |
|
71 | 73 | $(window).on('scroll', utils.debounce(updateTopicTitle, 250)); |
| 74 | + configurePostToggle(); |
72 | 75 |
|
73 | 76 | handleTopicSearch(); |
74 | 77 |
|
75 | 78 | hooks.fire('action:topic.loaded', ajaxify.data); |
76 | | - addResolved_Status(); |
77 | | - addEndorsed_Status(); |
78 | 79 | }; |
79 | 80 |
|
| 81 | + function configurePostToggle() { |
| 82 | + $('.topic').on('click', '.view-translated-btn', function () { |
| 83 | + // Toggle the visibility of the next .translated-content div |
| 84 | + $(this).closest('.sensitive-content-message').next('.translated-content').toggle(); |
| 85 | + // Optionally, change the button text based on visibility |
| 86 | + var isVisible = $(this).closest('.sensitive-content-message').next('.translated-content').is(':visible'); |
| 87 | + if (isVisible) { |
| 88 | + $(this).text('Hide the translated message.'); |
| 89 | + } else { |
| 90 | + $(this).text('Click here to view the translated message.'); |
| 91 | + } |
| 92 | + }); |
| 93 | + } |
| 94 | + |
| 95 | + |
80 | 96 | function handleTopicSearch() { |
81 | 97 | require(['mousetrap'], (mousetrap) => { |
82 | 98 | if (config.topicSearchEnabled) { |
@@ -481,143 +497,5 @@ define('forum/topic', [ |
481 | 497 | } |
482 | 498 |
|
483 | 499 |
|
484 | | - function addResolved_Status() { |
485 | | - const firstPost = $('[component="post"][data-index="0"]'); |
486 | | - if (!firstPost.length) return; |
487 | | - |
488 | | - const isAdmin = app.user && app.user.isAdmin; |
489 | | - const tid = ajaxify.data.tid; |
490 | | - |
491 | | - firstPost.prepend('<div class="resolved-loading">Loading...</div>'); |
492 | | - |
493 | | - fetch(`/api/topics/${tid}/resolved`).then(res => res.json()) |
494 | | - .then(data => { |
495 | | - const isResolved = data.resolved; |
496 | | - |
497 | | - const currStatus = $(` |
498 | | - <div class="post-toggle" style="cursor: ${isAdmin ? 'pointer' : 'default'}; padding: 5px; margin: 5px; display: flex; align-items: center; gap: 8px;"> |
499 | | - <div class="checkbox" style="width: 15px; height: 15px; border: 2px solid #999; display: inline-block; text-align: center; line-height: 12px; font-size: 12px;"> |
500 | | - ${isResolved ? '✓' : ''} |
501 | | - </div> |
502 | | - <span class="current_status" style="color: ${isResolved ? 'green' : 'red'}"> |
503 | | - ${isResolved ? 'resolved' : 'unresolved'} |
504 | | - </span> |
505 | | - ${!isAdmin ? '<span style="color: #999; font-size: 11px;">(admin only)</span>' : ''} |
506 | | - </div> |
507 | | - `); |
508 | | - |
509 | | - if (isAdmin) { |
510 | | - currStatus.on('click', function () { |
511 | | - const checkbox = $(this).find('.checkbox'); |
512 | | - const statusText = $(this).find('.current_status'); |
513 | | - const currentResolved = checkbox.text().trim() === '✓'; |
514 | | - const newStatus = !currentResolved; |
515 | | - |
516 | | - fetch(`${config.relative_path}/api/topics/${tid}/resolved`, { |
517 | | - method: 'PUT', |
518 | | - headers: { |
519 | | - 'Content-Type': 'application/json', |
520 | | - 'x-csrf-token': config.csrf_token, |
521 | | - }, |
522 | | - credentials: 'same-origin', |
523 | | - body: JSON.stringify({ resolved: newStatus }), |
524 | | - }) |
525 | | - .then(res => { |
526 | | - if (!res.ok) { |
527 | | - return res.json().then(err => { |
528 | | - console.log('Error response:', err); |
529 | | - throw new Error('Failed to update'); |
530 | | - }); |
531 | | - } |
532 | | - return res.json(); |
533 | | - }) |
534 | | - .then((data) => { |
535 | | - console.log('Success response:', data); |
536 | | - checkbox.text(newStatus ? '✓' : ''); |
537 | | - statusText.text(newStatus ? 'resolved' : 'unresolved'); |
538 | | - statusText.css('color', newStatus ? 'green' : 'red'); |
539 | | - alerts.success(newStatus ? 'Marked as resolved' : 'Marked as unresolved'); |
540 | | - }) |
541 | | - .catch((err) => { |
542 | | - console.log('Catch error:', err); |
543 | | - alerts.error('Failed to update'); |
544 | | - }); |
545 | | - }); |
546 | | - } |
547 | | - |
548 | | - firstPost.find('.resolved-loading').replaceWith(currStatus); |
549 | | - }); |
550 | | - } |
551 | | - |
552 | | - function addEndorsed_Status() { |
553 | | - const allPosts = $('[component="post"]'); |
554 | | - const isAdmin = app.user && app.user.isAdmin; |
555 | | - |
556 | | - allPosts.each(function () { |
557 | | - const postElem = $(this); |
558 | | - const pid = postElem.attr('data-pid'); |
559 | | - |
560 | | - if (!pid) return; |
561 | | - |
562 | | - postElem.prepend('<div class="endorsed-loading">Loading...</div>'); |
563 | | - |
564 | | - fetch(`/api/posts/${pid}/endorsed`, { |
565 | | - credentials: 'same-origin', |
566 | | - }).then(r => r.json()) |
567 | | - .then(data => { |
568 | | - const isEndorsed = data.endorsed; |
569 | | - |
570 | | - let endorsedStatus; |
571 | | - |
572 | | - if (isAdmin) { |
573 | | - // Admin sees a button with data attribute to track state |
574 | | - endorsedStatus = $(` |
575 | | - <button class="endorsed-button btn btn-sm" data-endorsed="${isEndorsed}" style="margin: 5px; ${isEndorsed ? 'background-color: #007bff; color: white; border: none;' : 'background-color: #f0f0f0; color: #666; border: 2px solid #007bff;'}"> |
576 | | - ${isEndorsed ? 'Endorsed ✓' : 'Endorse this post?'} |
577 | | - </button> |
578 | | - `); |
579 | | - |
580 | | - endorsedStatus.on('click', function () { |
581 | | - const button = $(this); |
582 | | - const currentState = button.attr('data-endorsed') === 'true'; // Read current state from button |
583 | | - const newStatus = !currentState; |
584 | | - |
585 | | - fetch(`/api/posts/${pid}/endorsed`, { |
586 | | - method: 'PUT', |
587 | | - headers: { |
588 | | - 'Content-Type': 'application/json', |
589 | | - 'x-csrf-token': config.csrf_token, |
590 | | - }, |
591 | | - credentials: 'same-origin', |
592 | | - body: JSON.stringify({ endorsed: newStatus }), |
593 | | - }).then(r => r.json()) |
594 | | - .then(() => { |
595 | | - button.attr('data-endorsed', newStatus); // Update state on button |
596 | | - if (newStatus) { |
597 | | - button.text('Endorsed ✓').css({'background-color': '#007bff', 'color': 'white', 'border': 'none'}); |
598 | | - } else { |
599 | | - button.text('Endorse this post?').css({'background-color': '#f0f0f0', 'color': '#666', 'border': '2px solid #007bff'}); |
600 | | - } |
601 | | - alerts.success(newStatus ? 'Post endorsed' : 'Post unendorsed'); |
602 | | - }) |
603 | | - .catch(() => alerts.error('Failed to update')); |
604 | | - }); |
605 | | - } else { |
606 | | - // Non-admin sees read-only status |
607 | | - endorsedStatus = $(` |
608 | | - <div style="padding: 5px; margin: 5px; color: ${isEndorsed ? 'blue' : '#999'}; font-size: 14px;"> |
609 | | - ${isEndorsed ? 'Endorsed by admin ✓' : ''} |
610 | | - </div> |
611 | | - `); |
612 | | - } |
613 | | - |
614 | | - postElem.find('.endorsed-loading').replaceWith(endorsedStatus); |
615 | | - }); |
616 | | - }); |
617 | | - } |
618 | | - |
619 | | - |
620 | 500 | return Topic; |
621 | 501 | }); |
622 | | - |
623 | | - |
0 commit comments