Commit c0d26698 authored by Mike Greiling's avatar Mike Greiling

Prettify protected_branches and protected_tags modules

parent b49c400a
...@@ -46,8 +46,12 @@ export default class ProtectedBranchCreate { ...@@ -46,8 +46,12 @@ export default class ProtectedBranchCreate {
onSelect() { onSelect() {
// Enable submit button // Enable submit button
const $branchInput = this.$form.find('input[name="protected_branch[name]"]'); const $branchInput = this.$form.find('input[name="protected_branch[name]"]');
const $allowedToMergeInput = this.$form.find('input[name="protected_branch[merge_access_levels_attributes][0][access_level]"]'); const $allowedToMergeInput = this.$form.find(
const $allowedToPushInput = this.$form.find('input[name="protected_branch[push_access_levels_attributes][0][access_level]"]'); 'input[name="protected_branch[merge_access_levels_attributes][0][access_level]"]',
);
const $allowedToPushInput = this.$form.find(
'input[name="protected_branch[push_access_levels_attributes][0][access_level]"]',
);
const completedForm = !( const completedForm = !(
$branchInput.val() && $branchInput.val() &&
$allowedToMergeInput.length && $allowedToMergeInput.length &&
......
...@@ -29,8 +29,12 @@ export default class ProtectedBranchEdit { ...@@ -29,8 +29,12 @@ export default class ProtectedBranchEdit {
} }
onSelect() { onSelect() {
const $allowedToMergeInput = this.$wrap.find(`input[name="${this.$allowedToMergeDropdown.data('fieldName')}"]`); const $allowedToMergeInput = this.$wrap.find(
const $allowedToPushInput = this.$wrap.find(`input[name="${this.$allowedToPushDropdown.data('fieldName')}"]`); `input[name="${this.$allowedToMergeDropdown.data('fieldName')}"]`,
);
const $allowedToPushInput = this.$wrap.find(
`input[name="${this.$allowedToPushDropdown.data('fieldName')}"]`,
);
// Do not update if one dropdown has not selected any option // Do not update if one dropdown has not selected any option
if (!($allowedToMergeInput.length && $allowedToPushInput.length)) return; if (!($allowedToMergeInput.length && $allowedToPushInput.length)) return;
...@@ -38,25 +42,36 @@ export default class ProtectedBranchEdit { ...@@ -38,25 +42,36 @@ export default class ProtectedBranchEdit {
this.$allowedToMergeDropdown.disable(); this.$allowedToMergeDropdown.disable();
this.$allowedToPushDropdown.disable(); this.$allowedToPushDropdown.disable();
axios.patch(this.$wrap.data('url'), { axios
protected_branch: { .patch(this.$wrap.data('url'), {
merge_access_levels_attributes: [{ protected_branch: {
id: this.$allowedToMergeDropdown.data('accessLevelId'), merge_access_levels_attributes: [
access_level: $allowedToMergeInput.val(), {
}], id: this.$allowedToMergeDropdown.data('accessLevelId'),
push_access_levels_attributes: [{ access_level: $allowedToMergeInput.val(),
id: this.$allowedToPushDropdown.data('accessLevelId'), },
access_level: $allowedToPushInput.val(), ],
}], push_access_levels_attributes: [
}, {
}).then(() => { id: this.$allowedToPushDropdown.data('accessLevelId'),
this.$allowedToMergeDropdown.enable(); access_level: $allowedToPushInput.val(),
this.$allowedToPushDropdown.enable(); },
}).catch(() => { ],
this.$allowedToMergeDropdown.enable(); },
this.$allowedToPushDropdown.enable(); })
.then(() => {
flash('Failed to update branch!', 'alert', document.querySelector('.js-protected-branches-list')); this.$allowedToMergeDropdown.enable();
}); this.$allowedToPushDropdown.enable();
})
.catch(() => {
this.$allowedToMergeDropdown.enable();
this.$allowedToPushDropdown.enable();
flash(
'Failed to update branch!',
'alert',
document.querySelector('.js-protected-branches-list'),
);
});
} }
} }
...@@ -40,7 +40,9 @@ export default class ProtectedTagCreate { ...@@ -40,7 +40,9 @@ export default class ProtectedTagCreate {
const $tagInput = this.$form.find('input[name="protected_tag[name]"]'); const $tagInput = this.$form.find('input[name="protected_tag[name]"]');
const $allowedToCreateInput = this.$form.find('#create_access_levels_attributes'); const $allowedToCreateInput = this.$form.find('#create_access_levels_attributes');
this.$form.find('input[type="submit"]').prop('disabled', !($tagInput.val() && $allowedToCreateInput.length)); this.$form
.find('input[type="submit"]')
.prop('disabled', !($tagInput.val() && $allowedToCreateInput.length));
} }
static getProtectedTags(term, callback) { static getProtectedTags(term, callback) {
......
...@@ -21,26 +21,33 @@ export default class ProtectedTagEdit { ...@@ -21,26 +21,33 @@ export default class ProtectedTagEdit {
} }
onSelect() { onSelect() {
const $allowedToCreateInput = this.$wrap.find(`input[name="${this.$allowedToCreateDropdownButton.data('fieldName')}"]`); const $allowedToCreateInput = this.$wrap.find(
`input[name="${this.$allowedToCreateDropdownButton.data('fieldName')}"]`,
);
// Do not update if one dropdown has not selected any option // Do not update if one dropdown has not selected any option
if (!$allowedToCreateInput.length) return; if (!$allowedToCreateInput.length) return;
this.$allowedToCreateDropdownButton.disable(); this.$allowedToCreateDropdownButton.disable();
axios.patch(this.$wrap.data('url'), { axios
protected_tag: { .patch(this.$wrap.data('url'), {
create_access_levels_attributes: [{ protected_tag: {
id: this.$allowedToCreateDropdownButton.data('accessLevelId'), create_access_levels_attributes: [
access_level: $allowedToCreateInput.val(), {
}], id: this.$allowedToCreateDropdownButton.data('accessLevelId'),
}, access_level: $allowedToCreateInput.val(),
}).then(() => { },
this.$allowedToCreateDropdownButton.enable(); ],
}).catch(() => { },
this.$allowedToCreateDropdownButton.enable(); })
.then(() => {
flash('Failed to update tag!', 'alert', document.querySelector('.js-protected-tags-list')); this.$allowedToCreateDropdownButton.enable();
}); })
.catch(() => {
this.$allowedToCreateDropdownButton.enable();
flash('Failed to update tag!', 'alert', document.querySelector('.js-protected-tags-list'));
});
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment