2016-08-05 06:57:53 +00:00
|
|
|
|
(global => {
|
|
|
|
|
global.gl = global.gl || {};
|
2016-08-03 18:02:42 +00:00
|
|
|
|
|
2016-08-05 06:57:53 +00:00
|
|
|
|
gl.ProtectedBranchEdit = class {
|
|
|
|
|
constructor(options) {
|
|
|
|
|
this.$wrap = options.$wrap;
|
|
|
|
|
this.$allowedToMergeDropdown = this.$wrap.find('.js-allowed-to-merge');
|
|
|
|
|
this.$allowedToPushDropdown = this.$wrap.find('.js-allowed-to-push');
|
2016-08-03 18:02:42 +00:00
|
|
|
|
|
2016-08-05 06:57:53 +00:00
|
|
|
|
this.buildDropdowns();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildDropdowns() {
|
|
|
|
|
|
|
|
|
|
// Allowed to merge dropdown
|
|
|
|
|
new gl.ProtectedBranchAccessDropdown({
|
|
|
|
|
$dropdown: this.$allowedToMergeDropdown,
|
|
|
|
|
data: gon.merge_access_levels,
|
|
|
|
|
onSelect: this.onSelect.bind(this)
|
|
|
|
|
});
|
2016-08-03 18:02:42 +00:00
|
|
|
|
|
2016-08-05 06:57:53 +00:00
|
|
|
|
// Allowed to push dropdown
|
|
|
|
|
new gl.ProtectedBranchAccessDropdown({
|
|
|
|
|
$dropdown: this.$allowedToPushDropdown,
|
|
|
|
|
data: gon.push_access_levels,
|
|
|
|
|
onSelect: this.onSelect.bind(this)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSelect() {
|
2016-08-05 22:09:21 +00:00
|
|
|
|
const $allowedToMergeInput = this.$wrap.find(`input[name="${this.$allowedToMergeDropdown.data('fieldName')}"]`);
|
|
|
|
|
const $allowedToPushInput = this.$wrap.find(`input[name="${this.$allowedToPushDropdown.data('fieldName')}"]`);
|
2016-08-05 06:57:53 +00:00
|
|
|
|
|
2016-08-21 05:19:22 +00:00
|
|
|
|
// Do not update if one dropdown has not selected any option
|
|
|
|
|
if (!($allowedToMergeInput.length && $allowedToPushInput.length)) return;
|
|
|
|
|
|
2016-08-05 06:57:53 +00:00
|
|
|
|
$.ajax({
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: this.$wrap.data('url'),
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
data: {
|
|
|
|
|
_method: 'PATCH',
|
|
|
|
|
id: this.$wrap.data('banchId'),
|
|
|
|
|
protected_branch: {
|
2016-08-16 05:09:13 +00:00
|
|
|
|
merge_access_levels_attributes: [{
|
|
|
|
|
id: this.$allowedToMergeDropdown.data('access-level-id'),
|
2016-08-05 06:57:53 +00:00
|
|
|
|
access_level: $allowedToMergeInput.val()
|
2016-08-16 05:09:13 +00:00
|
|
|
|
}],
|
|
|
|
|
push_access_levels_attributes: [{
|
|
|
|
|
id: this.$allowedToPushDropdown.data('access-level-id'),
|
2016-08-05 06:57:53 +00:00
|
|
|
|
access_level: $allowedToPushInput.val()
|
2016-08-16 05:09:13 +00:00
|
|
|
|
}]
|
2016-08-03 18:02:42 +00:00
|
|
|
|
}
|
2016-08-05 06:57:53 +00:00
|
|
|
|
},
|
|
|
|
|
success: () => {
|
|
|
|
|
this.$wrap.effect('highlight');
|
|
|
|
|
},
|
|
|
|
|
error() {
|
|
|
|
|
$.scrollTo(0);
|
|
|
|
|
new Flash('Failed to update branch!');
|
2016-08-03 18:02:42 +00:00
|
|
|
|
}
|
2016-08-05 06:57:53 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2016-08-03 18:02:42 +00:00
|
|
|
|
}
|
2016-08-05 06:57:53 +00:00
|
|
|
|
|
|
|
|
|
})(window);
|