2018-03-17 18:26:18 +05:30
|
|
|
import flash from '../flash';
|
|
|
|
import axios from '../lib/utils/axios_utils';
|
2017-08-17 22:00:37 +05:30
|
|
|
import ProtectedTagAccessDropdown from './protected_tag_access_dropdown';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { __ } from '~/locale';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
export default class ProtectedTagEdit {
|
|
|
|
constructor(options) {
|
|
|
|
this.$wrap = options.$wrap;
|
|
|
|
this.$allowedToCreateDropdownButton = this.$wrap.find('.js-allowed-to-create');
|
|
|
|
this.onSelectCallback = this.onSelect.bind(this);
|
|
|
|
|
|
|
|
this.buildDropdowns();
|
|
|
|
}
|
|
|
|
|
|
|
|
buildDropdowns() {
|
|
|
|
// Allowed to create dropdown
|
|
|
|
this.protectedTagAccessDropdown = new ProtectedTagAccessDropdown({
|
|
|
|
$dropdown: this.$allowedToCreateDropdownButton,
|
|
|
|
data: gon.create_access_levels,
|
|
|
|
onSelect: this.onSelectCallback,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelect() {
|
2018-12-13 13:39:08 +05:30
|
|
|
const $allowedToCreateInput = this.$wrap.find(
|
|
|
|
`input[name="${this.$allowedToCreateDropdownButton.data('fieldName')}"]`,
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
// Do not update if one dropdown has not selected any option
|
|
|
|
if (!$allowedToCreateInput.length) return;
|
|
|
|
|
|
|
|
this.$allowedToCreateDropdownButton.disable();
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
axios
|
|
|
|
.patch(this.$wrap.data('url'), {
|
|
|
|
protected_tag: {
|
|
|
|
create_access_levels_attributes: [
|
|
|
|
{
|
|
|
|
id: this.$allowedToCreateDropdownButton.data('accessLevelId'),
|
|
|
|
access_level: $allowedToCreateInput.val(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.$allowedToCreateDropdownButton.enable();
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$allowedToCreateDropdownButton.enable();
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
flash(
|
|
|
|
__('Failed to update tag!'),
|
|
|
|
'alert',
|
|
|
|
document.querySelector('.js-protected-tags-list'),
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|