2016-08-05 02:57:53 -04:00
|
|
|
|
(global => {
|
|
|
|
|
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() {
|
2016-08-05 03:18:20 -04:00
|
|
|
|
|
2016-08-05 02:57:53 -04:00
|
|
|
|
// Enable submit button
|
|
|
|
|
const $branchInput = this.$wrap.find('input[name="protected_branch[name]"]');
|
|
|
|
|
const $allowedToMergeInput = this.$wrap.find('input[name="protected_branch[merge_access_level_attributes][access_level]"]');
|
|
|
|
|
const $allowedToPushInput = this.$wrap.find('input[name="protected_branch[push_access_level_attributes][access_level]"]');
|
2016-08-01 17:08:36 -04:00
|
|
|
|
|
2016-08-05 02:57:53 -04:00
|
|
|
|
if ($branchInput.val() && $allowedToMergeInput.val() && $allowedToPushInput.val()){
|
2016-08-05 16:26:53 -04:00
|
|
|
|
this.$form.find('input[type="submit"]').removeAttr('disabled');
|
2016-08-05 02:57:53 -04:00
|
|
|
|
}
|
2016-08-01 17:08:36 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-05 02:57:53 -04:00
|
|
|
|
|
|
|
|
|
})(window);
|