debian-mirror-gitlab/app/assets/javascripts/project_new.js

83 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-09-13 17:45:13 +05:30
(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-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');
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));
this.toggleSettings();
this.toggleSettingsOnclick();
2016-11-03 12:29:30 +05:30
this.toggleRepoVisibility();
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 () {
var $select = $(this),
className = $select.data('field').replace(/_/g, '-')
.replace('access-level', 'feature');
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');
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');
} else {
this.$repoSelects.addClass('disabled');
}
}.bind(this));
};
2016-09-13 17:45:13 +05:30
return ProjectNew;
})();
}).call(this);