BigW Consortium Gitlab

Commit f8513d76 by Phil Hughes

Refactored code to rely less on IDs that could change

parent 4da474ca
......@@ -4,6 +4,8 @@
this.ProjectNew = (function() {
function ProjectNew() {
this.toggleSettings = bind(this.toggleSettings, this);
this.$selects = $('.features select');
$('.project-edit-container').on('ajax:before', (function(_this) {
return function() {
$('.project-edit-container').hide();
......@@ -15,17 +17,23 @@
}
ProjectNew.prototype.toggleSettings = function() {
this._showOrHide('#project_project_feature_attributes_builds_access_level', '.builds-feature');
this._showOrHide('#project_project_feature_attributes_merge_requests_access_level', '.merge-requests-feature');
var self = this;
this.$selects.each(function () {
var $select = $(this),
className = $select.data('field').replace(/_/g, '-')
.replace('access-level', 'feature');
self._showOrHide($select, '.' + className);
});
};
ProjectNew.prototype.toggleSettingsOnclick = function() {
$('#project_project_feature_attributes_builds_access_level, #project_project_feature_attributes_merge_requests_access_level').on('change', this.toggleSettings);
this.$selects.on('change', this.toggleSettings);
};
ProjectNew.prototype._showOrHide = function(checkElement, container) {
var $container;
$container = $(container);
var $container = $(container);
if ($(checkElement).val() !== '0') {
return $container.show();
} else {
......
......@@ -431,6 +431,6 @@ module ProjectsHelper
options.delete('Everyone with access') if @project.private? && level != ProjectFeature::ENABLED
options = options_for_select(options, selected: @project.project_feature.public_send(field) || ProjectFeature::ENABLED)
content_tag(:select, options, name: "project[project_feature_attributes][#{field.to_s}]", id: "project_project_feature_attributes_#{field.to_s}", class: "pull-right form-control").html_safe
content_tag(:select, options, name: "project[project_feature_attributes][#{field.to_s}]", id: "project_project_feature_attributes_#{field.to_s}", class: "pull-right form-control", data: { field: field }).html_safe
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment