2017-01-11 19:48:34 -05:00
|
|
|
/* eslint-disable no-new, arrow-parens, no-param-reassign, comma-dangle, max-len */
|
2016-12-13 22:01:05 -05:00
|
|
|
/* global ProtectedBranchDropdown */
|
|
|
|
|
2016-08-05 02:57:53 -04:00
|
|
|
(global => {
|
2017-01-11 19:48:34 -05:00
|
|
|
global.gl = global.gl || {};
|
2016-08-01 17:08:36 -04:00
|
|
|
|
2016-08-05 02:57:53 -04:00
|
|
|
gl.ProtectedBranchCreate = class {
|
|
|
|
constructor() {
|
|
|
|
this.$wrap = this.$form = $('#new_protected_branch');
|
|
|
|
this.buildDropdowns();
|
|
|
|
}
|
2016-08-01 17:08:36 -04:00
|
|
|
|
2016-08-05 02:57:53 -04:00
|
|
|
buildDropdowns() {
|
|
|
|
const $allowedToMergeDropdown = this.$wrap.find('.js-allowed-to-merge');
|
|
|
|
const $allowedToPushDropdown = this.$wrap.find('.js-allowed-to-push');
|
|
|
|
|
2016-08-05 03:18:20 -04:00
|
|
|
// Cache callback
|
|
|
|
this.onSelectCallback = this.onSelect.bind(this);
|
|
|
|
|
|
|
|
// Allowed to Merge dropdown
|
2016-08-05 02:57:53 -04:00
|
|
|
new gl.ProtectedBranchAccessDropdown({
|
|
|
|
$dropdown: $allowedToMergeDropdown,
|
|
|
|
data: gon.merge_access_levels,
|
2016-08-05 03:18:20 -04:00
|
|
|
onSelect: this.onSelectCallback
|
2016-08-05 02:57:53 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Allowed to Push dropdown
|
|
|
|
new gl.ProtectedBranchAccessDropdown({
|
|
|
|
$dropdown: $allowedToPushDropdown,
|
|
|
|
data: gon.push_access_levels,
|
2016-08-05 03:18:20 -04:00
|
|
|
onSelect: this.onSelectCallback
|
2016-08-05 02:57:53 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Select default
|
|
|
|
$allowedToPushDropdown.data('glDropdown').selectRowAtIndex(0);
|
2016-08-05 03:18:20 -04:00
|
|
|
$allowedToMergeDropdown.data('glDropdown').selectRowAtIndex(0);
|
2016-08-05 02:57:53 -04:00
|
|
|
|
|
|
|
// Protected branch dropdown
|
|
|
|
new ProtectedBranchDropdown({
|
|
|
|
$dropdown: this.$wrap.find('.js-protected-branch-select'),
|
2016-08-05 03:18:20 -04:00
|
|
|
onSelect: this.onSelectCallback
|
2016-08-05 02:57:53 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will run after clicked callback
|
|
|
|
onSelect() {
|
|
|
|
// Enable submit button
|
|
|
|
const $branchInput = this.$wrap.find('input[name="protected_branch[name]"]');
|
2016-08-16 01:09:13 -04:00
|
|
|
const $allowedToMergeInput = this.$wrap.find('input[name="protected_branch[merge_access_levels_attributes][0][access_level]"]');
|
|
|
|
const $allowedToPushInput = this.$wrap.find('input[name="protected_branch[push_access_levels_attributes][0][access_level]"]');
|
2016-08-01 17:08:36 -04:00
|
|
|
|
2016-08-21 01:20:57 -04:00
|
|
|
this.$form.find('input[type="submit"]').attr('disabled', !($branchInput.val() && $allowedToMergeInput.length && $allowedToPushInput.length));
|
2016-08-01 17:08:36 -04:00
|
|
|
}
|
2017-01-10 17:54:56 -05:00
|
|
|
};
|
2016-08-05 02:57:53 -04:00
|
|
|
})(window);
|