gitlab-org--gitlab-foss/app/assets/javascripts/visibility_select.js.es6
Luke "Jared" Bennett 2c9bb13505
Fixed tests
Grab permissions description from backend

Review changes

Added unit tests
2016-12-10 17:28:36 +00:00

27 lines
841 B
JavaScript

(() => {
const gl = window.gl || (window.gl = {});
class VisibilitySelect {
constructor(container) {
if (!container) throw new Error('VisibilitySelect requires a container element as argument 1');
this.container = container;
this.helpBlock = this.container.querySelector('.help-block');
this.select = this.container.querySelector('select');
}
init() {
if (this.select) {
this.updateHelpText();
this.select.addEventListener('change', this.updateHelpText.bind(this));
} else {
this.helpBlock.textContent = this.container.querySelector('.js-locked').dataset.helpBlock;
}
}
updateHelpText() {
this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description;
}
}
gl.VisibilitySelect = VisibilitySelect;
})();