summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/visual_review_toolbar/components/note.js
blob: 9cddcb710f256bd6d4045c3e9819ed16321c032b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { NOTE, NOTE_CONTAINER, RED } from '../shared';
import { selectById, selectNote, selectNoteContainer } from './utils';

const note = `
  <div id="${NOTE_CONTAINER}" style="visibility: hidden;">
    <p id="${NOTE}" class="gitlab-message"></p>
  </div>
`;

const clearNote = inputId => {
  const currentNote = selectNote();
  const noteContainer = selectNoteContainer();

  currentNote.innerText = '';
  currentNote.style.color = '';
  noteContainer.style.visibility = 'hidden';

  if (inputId) {
    const field = document.getElementById(inputId);
    field.style.borderColor = '';
  }
};

const postError = (message, inputId) => {
  const currentNote = selectNote();
  const noteContainer = selectNoteContainer();
  const field = selectById(inputId);
  field.style.borderColor = RED;
  currentNote.style.color = RED;
  currentNote.innerText = message;
  noteContainer.style.visibility = 'visible';
  setTimeout(clearNote.bind(null, inputId), 5000);
};

export { clearNote, note, postError };