2016-11-15 09:08:06 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, space-before-blocks, prefer-rest-params, wrap-iife, no-unused-vars, one-var, indent, no-underscore-dangle, prefer-template, no-else-return, prefer-arrow-callback, radix, padded-blocks, max-len */
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
|
|
|
|
|
|
|
this.ProjectNew = (function() {
|
|
|
|
function ProjectNew() {
|
|
|
|
this.toggleSettings = bind(this.toggleSettings, this);
|
2016-09-16 15:15:39 -04:00
|
|
|
this.$selects = $('.features select');
|
|
|
|
this.$repoSelects = this.$selects.filter('.js-repo-select');
|
2016-09-02 09:51:36 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
$('.project-edit-container').on('ajax:before', (function(_this) {
|
|
|
|
return function() {
|
|
|
|
$('.project-edit-container').hide();
|
|
|
|
return $('.save-project-loader').show();
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
this.toggleSettings();
|
|
|
|
this.toggleSettingsOnclick();
|
2016-09-16 15:15:39 -04:00
|
|
|
this.toggleRepoVisibility();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectNew.prototype.toggleSettings = function() {
|
2016-09-02 09:51:36 -04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$selects.each(function () {
|
|
|
|
var $select = $(this),
|
|
|
|
className = $select.data('field').replace(/_/g, '-')
|
|
|
|
.replace('access-level', 'feature');
|
|
|
|
self._showOrHide($select, '.' + className);
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
ProjectNew.prototype.toggleSettingsOnclick = function() {
|
2016-09-02 09:51:36 -04:00
|
|
|
this.$selects.on('change', this.toggleSettings);
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
ProjectNew.prototype._showOrHide = function(checkElement, container) {
|
2016-09-02 09:51:36 -04:00
|
|
|
var $container = $(container);
|
|
|
|
|
2016-09-02 07:03:49 -04:00
|
|
|
if ($(checkElement).val() !== '0') {
|
2016-07-24 16:45:11 -04:00
|
|
|
return $container.show();
|
|
|
|
} else {
|
|
|
|
return $container.hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-16 15:15:39 -04:00
|
|
|
ProjectNew.prototype.toggleRepoVisibility = function () {
|
2016-10-21 06:21:14 -04:00
|
|
|
var $repoAccessLevel = $('.js-repo-access-level select'),
|
|
|
|
containerRegistry = document.querySelectorAll('.js-container-registry')[0],
|
|
|
|
containerRegistryCheckbox = document.getElementById('project_container_registry_enabled');
|
2016-09-16 15:15:39 -04:00
|
|
|
|
|
|
|
this.$repoSelects.find("option[value='" + $repoAccessLevel.val() + "']")
|
|
|
|
.nextAll()
|
|
|
|
.hide();
|
|
|
|
|
|
|
|
$repoAccessLevel.off('change')
|
|
|
|
.on('change', function () {
|
|
|
|
var selectedVal = parseInt($repoAccessLevel.val());
|
|
|
|
|
|
|
|
this.$repoSelects.each(function () {
|
|
|
|
var $this = $(this),
|
|
|
|
repoSelectVal = parseInt($this.val());
|
|
|
|
|
|
|
|
$this.find('option').show();
|
|
|
|
|
|
|
|
if (selectedVal < repoSelectVal) {
|
|
|
|
$this.val(selectedVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this.find("option[value='" + selectedVal + "']").nextAll().hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (selectedVal) {
|
|
|
|
this.$repoSelects.removeClass('disabled');
|
2016-10-21 06:21:14 -04:00
|
|
|
|
|
|
|
if (containerRegistry) {
|
|
|
|
containerRegistry.style.display = '';
|
|
|
|
}
|
2016-09-16 15:15:39 -04:00
|
|
|
} else {
|
|
|
|
this.$repoSelects.addClass('disabled');
|
2016-10-21 06:21:14 -04:00
|
|
|
|
|
|
|
if (containerRegistry) {
|
|
|
|
containerRegistry.style.display = 'none';
|
|
|
|
containerRegistryCheckbox.checked = false;
|
|
|
|
}
|
2016-09-16 15:15:39 -04:00
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return ProjectNew;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
}).call(this);
|