diff options
author | Phil Hughes <me@iamphill.com> | 2018-01-09 15:10:53 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-01-11 11:55:17 +0300 |
commit | a607f343c5c28511e92e058a9556b89f897ae8c2 (patch) | |
tree | fee96d57f1369fbe63888d5845b21cfb5afdb539 /app/assets/javascripts/pages/admin/abuse_reports/abuse_reports.js | |
parent | 21bb393378c864d1715c252e7523e7ca3f70472b (diff) |
Admin dispatcher JS imports
Diffstat (limited to 'app/assets/javascripts/pages/admin/abuse_reports/abuse_reports.js')
-rw-r--r-- | app/assets/javascripts/pages/admin/abuse_reports/abuse_reports.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/assets/javascripts/pages/admin/abuse_reports/abuse_reports.js b/app/assets/javascripts/pages/admin/abuse_reports/abuse_reports.js new file mode 100644 index 00000000000..d87e6304a24 --- /dev/null +++ b/app/assets/javascripts/pages/admin/abuse_reports/abuse_reports.js @@ -0,0 +1,36 @@ +import { truncate } from '../../../lib/utils/text_utility'; + +const MAX_MESSAGE_LENGTH = 500; +const MESSAGE_CELL_SELECTOR = '.abuse-reports .message'; + +export default class AbuseReports { + constructor() { + $(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage); + $(document) + .off('click', MESSAGE_CELL_SELECTOR) + .on('click', MESSAGE_CELL_SELECTOR, this.toggleMessageTruncation); + } + + truncateLongMessage() { + const $messageCellElement = $(this); + const reportMessage = $messageCellElement.text(); + if (reportMessage.length > MAX_MESSAGE_LENGTH) { + $messageCellElement.data('original-message', reportMessage); + $messageCellElement.data('message-truncated', 'true'); + $messageCellElement.text(truncate(reportMessage, MAX_MESSAGE_LENGTH)); + } + } + + 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))}...`); + } + } +} |