2017-08-17 22:00:37 +05:30
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-unused-vars, one-var, no-underscore-dangle, prefer-template, no-else-return, prefer-arrow-callback, max-len */
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
import VisibilitySelect from './visibility_select';
|
|
|
|
|
|
|
|
function highlightChanges($elm) {
|
|
|
|
$elm.addClass('highlight-changes');
|
|
|
|
setTimeout(() => $elm.removeClass('highlight-changes'), 10);
|
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
(function() {
|
2016-09-13 17:45:13 +05:30
|
|
|
this.ProjectNew = (function() {
|
|
|
|
function ProjectNew() {
|
2017-09-10 17:25:29 +05:30
|
|
|
this.toggleSettings = this.toggleSettings.bind(this);
|
2016-09-29 09:46:39 +05:30
|
|
|
this.$selects = $('.features select');
|
2016-11-03 12:29:30 +05:30
|
|
|
this.$repoSelects = this.$selects.filter('.js-repo-select');
|
2017-09-10 17:25:29 +05:30
|
|
|
this.$projectSelects = this.$selects.not('.js-repo-select');
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
$('.project-edit-container').on('ajax:before', (function(_this) {
|
|
|
|
return function() {
|
|
|
|
$('.project-edit-container').hide();
|
|
|
|
return $('.save-project-loader').show();
|
|
|
|
};
|
|
|
|
})(this));
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
this.initVisibilitySelect();
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
this.toggleSettings();
|
|
|
|
this.toggleSettingsOnclick();
|
2016-11-03 12:29:30 +05:30
|
|
|
this.toggleRepoVisibility();
|
2016-09-13 17:45:13 +05:30
|
|
|
}
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
ProjectNew.prototype.initVisibilitySelect = function() {
|
|
|
|
const visibilityContainer = document.querySelector('.js-visibility-select');
|
|
|
|
if (!visibilityContainer) return;
|
2017-09-10 17:25:29 +05:30
|
|
|
const visibilitySelect = new VisibilitySelect(visibilityContainer);
|
2017-08-17 22:00:37 +05:30
|
|
|
visibilitySelect.init();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
const $visibilitySelect = $(visibilityContainer).find('select');
|
|
|
|
let projectVisibility = $visibilitySelect.val();
|
|
|
|
const PROJECT_VISIBILITY_PRIVATE = '0';
|
|
|
|
|
|
|
|
$visibilitySelect.on('change', () => {
|
|
|
|
const newProjectVisibility = $visibilitySelect.val();
|
|
|
|
|
|
|
|
if (projectVisibility !== newProjectVisibility) {
|
|
|
|
this.$projectSelects.each((idx, select) => {
|
|
|
|
const $select = $(select);
|
|
|
|
const $options = $select.find('option');
|
|
|
|
const values = $.map($options, e => e.value);
|
|
|
|
|
|
|
|
// if switched to "private", limit visibility options
|
|
|
|
if (newProjectVisibility === PROJECT_VISIBILITY_PRIVATE) {
|
|
|
|
if ($select.val() !== values[0] && $select.val() !== values[1]) {
|
|
|
|
$select.val(values[1]).trigger('change');
|
|
|
|
highlightChanges($select);
|
|
|
|
}
|
|
|
|
$options.slice(2).disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if switched from "private", increase visibility for non-disabled options
|
|
|
|
if (projectVisibility === PROJECT_VISIBILITY_PRIVATE) {
|
|
|
|
$options.enable();
|
|
|
|
if ($select.val() !== values[0] && $select.val() !== values[values.length - 1]) {
|
|
|
|
$select.val(values[values.length - 1]).trigger('change');
|
|
|
|
highlightChanges($select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
projectVisibility = newProjectVisibility;
|
|
|
|
}
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
};
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
ProjectNew.prototype.toggleSettings = function() {
|
2016-09-29 09:46:39 +05:30
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$selects.each(function () {
|
2017-08-17 22:00:37 +05:30
|
|
|
var $select = $(this);
|
|
|
|
var className = $select.data('field')
|
|
|
|
.replace(/_/g, '-')
|
|
|
|
.replace('access-level', 'feature');
|
2016-09-29 09:46:39 +05:30
|
|
|
self._showOrHide($select, '.' + className);
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
ProjectNew.prototype.toggleSettingsOnclick = function() {
|
2016-09-29 09:46:39 +05:30
|
|
|
this.$selects.on('change', this.toggleSettings);
|
2016-09-13 17:45:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
ProjectNew.prototype._showOrHide = function(checkElement, container) {
|
2016-09-29 09:46:39 +05:30
|
|
|
var $container = $(container);
|
|
|
|
|
|
|
|
if ($(checkElement).val() !== '0') {
|
2016-09-13 17:45:13 +05:30
|
|
|
return $container.show();
|
|
|
|
} else {
|
|
|
|
return $container.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
ProjectNew.prototype.toggleRepoVisibility = function () {
|
|
|
|
var $repoAccessLevel = $('.js-repo-access-level select');
|
2017-09-10 17:25:29 +05:30
|
|
|
var $lfsEnabledOption = $('.js-lfs-enabled select');
|
2017-08-17 22:00:37 +05:30
|
|
|
var containerRegistry = document.querySelectorAll('.js-container-registry')[0];
|
|
|
|
var containerRegistryCheckbox = document.getElementById('project_container_registry_enabled');
|
2017-09-10 17:25:29 +05:30
|
|
|
var prevSelectedVal = parseInt($repoAccessLevel.val(), 10);
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
this.$repoSelects.find("option[value='" + $repoAccessLevel.val() + "']")
|
|
|
|
.nextAll()
|
|
|
|
.hide();
|
|
|
|
|
|
|
|
$repoAccessLevel.off('change')
|
|
|
|
.on('change', function () {
|
2017-08-17 22:00:37 +05:30
|
|
|
var selectedVal = parseInt($repoAccessLevel.val(), 10);
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
this.$repoSelects.each(function () {
|
2017-08-17 22:00:37 +05:30
|
|
|
var $this = $(this);
|
|
|
|
var repoSelectVal = parseInt($this.val(), 10);
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
$this.find('option').enable();
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
if (selectedVal < repoSelectVal || repoSelectVal === prevSelectedVal) {
|
|
|
|
$this.val(selectedVal).trigger('change');
|
|
|
|
highlightChanges($this);
|
2016-11-03 12:29:30 +05:30
|
|
|
}
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
$this.find("option[value='" + selectedVal + "']").nextAll().disable();
|
2016-11-03 12:29:30 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
if (selectedVal) {
|
|
|
|
this.$repoSelects.removeClass('disabled');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
if ($lfsEnabledOption.length) {
|
|
|
|
$lfsEnabledOption.removeClass('disabled');
|
|
|
|
highlightChanges($lfsEnabledOption);
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
if (containerRegistry) {
|
|
|
|
containerRegistry.style.display = '';
|
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
} else {
|
|
|
|
this.$repoSelects.addClass('disabled');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
if ($lfsEnabledOption.length) {
|
|
|
|
$lfsEnabledOption.val('false').addClass('disabled');
|
|
|
|
highlightChanges($lfsEnabledOption);
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
if (containerRegistry) {
|
|
|
|
containerRegistry.style.display = 'none';
|
|
|
|
containerRegistryCheckbox.checked = false;
|
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
}
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
prevSelectedVal = selectedVal;
|
2016-11-03 12:29:30 +05:30
|
|
|
}.bind(this));
|
|
|
|
};
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
return ProjectNew;
|
|
|
|
})();
|
2017-08-17 22:00:37 +05:30
|
|
|
}).call(window);
|