debian-mirror-gitlab/app/assets/javascripts/visual_review_toolbar/components/note.js

36 lines
1,001 B
JavaScript
Raw Normal View History

2019-09-30 21:07:59 +05:30
import { NOTE, NOTE_CONTAINER, RED } from './constants';
import { selectById, selectNote, selectNoteContainer } from './utils';
2019-09-04 21:01:54 +05:30
const note = `
2019-09-30 21:07:59 +05:30
<div id="${NOTE_CONTAINER}" style="visibility: hidden;">
<p id="${NOTE}" class="gitlab-message"></p>
</div>
2019-09-04 21:01:54 +05:30
`;
const clearNote = inputId => {
const currentNote = selectNote();
2019-09-30 21:07:59 +05:30
const noteContainer = selectNoteContainer();
2019-09-04 21:01:54 +05:30
currentNote.innerText = '';
currentNote.style.color = '';
2019-09-30 21:07:59 +05:30
noteContainer.style.visibility = 'hidden';
2019-09-04 21:01:54 +05:30
if (inputId) {
const field = document.getElementById(inputId);
field.style.borderColor = '';
}
};
const postError = (message, inputId) => {
const currentNote = selectNote();
2019-09-30 21:07:59 +05:30
const noteContainer = selectNoteContainer();
2019-09-04 21:01:54 +05:30
const field = selectById(inputId);
field.style.borderColor = RED;
currentNote.style.color = RED;
currentNote.innerText = message;
2019-09-30 21:07:59 +05:30
noteContainer.style.visibility = 'visible';
setTimeout(clearNote.bind(null, inputId), 5000);
2019-09-04 21:01:54 +05:30
};
export { clearNote, note, postError };