gitlab-org--gitlab-foss/app/assets/javascripts/protected_tags/protected_tag_create.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.6 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
import { __ } from '~/locale';
import CreateItemDropdown from '../create_item_dropdown';
import ProtectedTagAccessDropdown from './protected_tag_access_dropdown';
2017-04-06 08:47:19 +00:00
export default class ProtectedTagCreate {
constructor() {
2017-04-06 13:39:48 +00:00
this.$form = $('.js-new-protected-tag');
2017-04-06 08:47:19 +00:00
this.buildDropdowns();
}
buildDropdowns() {
const $allowedToCreateDropdown = this.$form.find('.js-allowed-to-create');
// Cache callback
this.onSelectCallback = this.onSelect.bind(this);
// Allowed to Create dropdown
this.protectedTagAccessDropdown = new ProtectedTagAccessDropdown({
$dropdown: $allowedToCreateDropdown,
data: gon.create_access_levels,
onSelect: this.onSelectCallback,
});
// Select default
$allowedToCreateDropdown.data('deprecatedJQueryDropdown').selectRowAtIndex(0);
2017-04-06 08:47:19 +00:00
// Protected tag dropdown
this.createItemDropdown = new CreateItemDropdown({
2017-04-06 08:47:19 +00:00
$dropdown: this.$form.find('.js-protected-tag-select'),
defaultToggleLabel: __('Protected Tag'),
fieldName: 'protected_tag[name]',
2017-04-06 08:47:19 +00:00
onSelect: this.onSelectCallback,
getData: ProtectedTagCreate.getProtectedTags,
2017-04-06 08:47:19 +00:00
});
}
// This will run after clicked callback
onSelect() {
// Enable submit button
const $tagInput = this.$form.find('input[name="protected_tag[name]"]');
2017-04-06 13:39:48 +00:00
const $allowedToCreateInput = this.$form.find('#create_access_levels_attributes');
2017-04-06 08:47:19 +00:00
this.$form
.find('input[type="submit"]')
.prop('disabled', !($tagInput.val() && $allowedToCreateInput.length));
2017-04-06 08:47:19 +00:00
}
static getProtectedTags(term, callback) {
callback(gon.open_tags);
}
2017-04-06 08:47:19 +00:00
}