diff --git a/app/javascript/packs/application.ts b/app/javascript/packs/application.ts index bcfeddc4..91272b03 100644 --- a/app/javascript/packs/application.ts +++ b/app/javascript/packs/application.ts @@ -1,5 +1,7 @@ import start from '../retrospring/common'; import initAnswerbox from '../retrospring/features/answerbox/index'; +import initInbox from '../retrospring/features/inbox/index'; start(); document.addEventListener('turbolinks:load', initAnswerbox); +document.addEventListener('turbolinks:load', initInbox); \ No newline at end of file diff --git a/app/javascript/retrospring/features/inbox/index.ts b/app/javascript/retrospring/features/inbox/index.ts new file mode 100644 index 00000000..4c4af9b3 --- /dev/null +++ b/app/javascript/retrospring/features/inbox/index.ts @@ -0,0 +1,14 @@ +import registerEvents from "retrospring/utilities/registerEvents"; +import {reportEventHandler} from "./report"; + +export default (): void => { + const entries: NodeList = document.querySelectorAll('.inbox-entry:not(.js-initialized)'); + + entries.forEach((element: HTMLElement) => { + registerEvents([ + {type: 'click', target: element.querySelector('[name=ib-report]'), handler: reportEventHandler} + ]); + + element.classList.add('js-initialized'); + }); +} diff --git a/app/javascript/retrospring/features/inbox/report.ts b/app/javascript/retrospring/features/inbox/report.ts new file mode 100644 index 00000000..1c3f6b31 --- /dev/null +++ b/app/javascript/retrospring/features/inbox/report.ts @@ -0,0 +1,4 @@ +export function reportEventHandler(event: Event): void { + const element = event.target as HTMLElement; + window['reportDialog']('question', element.dataset.qId); +} \ No newline at end of file diff --git a/app/javascript/retrospring/utilities/registerEvents.ts b/app/javascript/retrospring/utilities/registerEvents.ts index a0991cce..4ff6edfa 100644 --- a/app/javascript/retrospring/utilities/registerEvents.ts +++ b/app/javascript/retrospring/utilities/registerEvents.ts @@ -1,4 +1,4 @@ -interface EventDef { +export interface EventDef { type: string; target: Node | NodeList; handler: EventListenerOrEventListenerObject; diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index 216c61ee..ae46e93a 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -12,6 +12,21 @@ %a{ href: show_user_question_path(i.question.user.screen_name, i.question.id) } = pluralize(i.question.answer_count, t('views.inbox.entry.response')) %p.answerbox__question-text= i.question.content + - if i.question.user_id != current_user.id || current_user.has_role?(:administrator) + .pull-right + .btn-group + %button.btn.btn-default.btn-sm.dropdown-toggle{ data: { toggle: :dropdown }, aria: { expanded: false } } + %span.caret + .dropdown-menu.dropdown-menu-right{ role: :menu } + - if i.question.user_id != current_user.id + %a.dropdown-item{ name: 'ib-report', data: { q_id: i.question.id } } + %i.fa.fa-warning + = t 'views.actions.report' + - if current_user.has_role? :administrator + %a.dropdown-item{ href: rails_admin_path_for_resource(i) } + %i.fa.fa-gears + View in Kontrollzentrum + .card-body %textarea.form-control{ name: 'ib-answer', placeholder: t('views.placeholder.inbox'), data: { id: i.id } } %br/