BigW Consortium Gitlab

abuse_reports.js 1.31 KB
Newer Older
1 2
const MAX_MESSAGE_LENGTH = 500;
const MESSAGE_CELL_SELECTOR = '.abuse-reports .message';
3

4 5 6 7 8 9 10
class AbuseReports {
  constructor() {
    $(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage);
    $(document)
      .off('click', MESSAGE_CELL_SELECTOR)
      .on('click', MESSAGE_CELL_SELECTOR, this.toggleMessageTruncation);
  }
11

12 13 14 15 16 17
  truncateLongMessage() {
    const $messageCellElement = $(this);
    const reportMessage = $messageCellElement.text();
    if (reportMessage.length > MAX_MESSAGE_LENGTH) {
      $messageCellElement.data('original-message', reportMessage);
      $messageCellElement.data('message-truncated', 'true');
18
      $messageCellElement.text(window.gl.text.truncate(reportMessage, MAX_MESSAGE_LENGTH));
19
    }
20
  }
21

22 23 24 25 26 27 28 29 30 31
  toggleMessageTruncation() {
    const $messageCellElement = $(this);
    const originalMessage = $messageCellElement.data('original-message');
    if (!originalMessage) return;
    if ($messageCellElement.data('message-truncated') === 'true') {
      $messageCellElement.data('message-truncated', 'false');
      $messageCellElement.text(originalMessage);
    } else {
      $messageCellElement.data('message-truncated', 'true');
      $messageCellElement.text(`${originalMessage.substr(0, (MAX_MESSAGE_LENGTH - 3))}...`);
32 33
    }
  }
34
}
35

36 37
window.gl = window.gl || {};
window.gl.AbuseReports = AbuseReports;