2016-08-05 06:57:53 +00:00
|
|
|
|
(global => {
|
|
|
|
|
global.gl = global.gl || {};
|
2016-08-01 21:08:36 +00:00
|
|
|
|
|
2016-08-05 06:57:53 +00:00
|
|
|
|
gl.ProtectedBranchCreate = class {
|
|
|
|
|
constructor() {
|
|
|
|
|
this.$wrap = this.$form = $('#new_protected_branch');
|
|
|
|
|
this.buildDropdowns();
|
|
|
|
|
}
|
2016-08-01 21:08:36 +00:00
|
|
|
|
|
2016-08-05 06:57:53 +00:00
|
|
|
|
buildDropdowns() {
|
|
|
|
|
const $allowedToMergeDropdown = this.$wrap.find('.js-allowed-to-merge');
|
|
|
|
|
const $allowedToPushDropdown = this.$wrap.find('.js-allowed-to-push');
|
|
|
|
|
|
2016-08-05 07:18:20 +00:00
|
|
|
|
// Cache callback
|
|
|
|
|
this.onSelectCallback = this.onSelect.bind(this);
|
|
|
|
|
|
|
|
|
|
// Allowed to Merge dropdown
|
2016-08-05 06:57:53 +00:00
|
|
|
|
new gl.ProtectedBranchAccessDropdown({
|
|
|
|
|
$dropdown: $allowedToMergeDropdown,
|
|
|
|
|
data: gon.merge_access_levels,
|
2016-08-05 07:18:20 +00:00
|
|
|
|
onSelect: this.onSelectCallback
|
2016-08-05 06:57:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Allowed to Push dropdown
|
|
|
|
|
new gl.ProtectedBranchAccessDropdown({
|
|
|
|
|
$dropdown: $allowedToPushDropdown,
|
|
|
|
|
data: gon.push_access_levels,
|
2016-08-05 07:18:20 +00:00
|
|
|
|
onSelect: this.onSelectCallback
|
2016-08-05 06:57:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Select default
|
|
|
|
|
$allowedToPushDropdown.data('glDropdown').selectRowAtIndex(0);
|
2016-08-05 07:18:20 +00:00
|
|
|
|
$allowedToMergeDropdown.data('glDropdown').selectRowAtIndex(0);
|
2016-08-05 06:57:53 +00:00
|
|
|
|
|
|
|
|
|
// Protected branch dropdown
|
|
|
|
|
new ProtectedBranchDropdown({
|
|
|
|
|
$dropdown: this.$wrap.find('.js-protected-branch-select'),
|
2016-08-05 07:18:20 +00:00
|
|
|
|
onSelect: this.onSelectCallback
|
2016-08-05 06:57:53 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This will run after clicked callback
|
|
|
|
|
onSelect() {
|
2016-08-05 07:18:20 +00:00
|
|
|
|
|
2016-08-05 06:57:53 +00:00
|
|
|
|
// Enable submit button
|
|
|
|
|
const $branchInput = this.$wrap.find('input[name="protected_branch[name]"]');
|
2016-08-16 05:09:13 +00: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 21:08:36 +00:00
|
|
|
|
|
2016-08-21 05:20:57 +00:00
|
|
|
|
this.$form.find('input[type="submit"]').attr('disabled', !($branchInput.val() && $allowedToMergeInput.length && $allowedToPushInput.length));
|
2016-08-01 21:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-05 06:57:53 +00:00
|
|
|
|
|
|
|
|
|
})(window);
|