Refactored code to rely less on IDs that could change

This commit is contained in:
Phil Hughes 2016-09-02 14:51:36 +01:00
parent 4da474ca92
commit f8513d7682
2 changed files with 14 additions and 6 deletions

View file

@ -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 {

View file

@ -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