Refactor vote type descriptions to use data attributes
This makes it easier to extend support for new types (e.g., 'open') without adding more conditional logic to the JavaScript.
This commit is contained in:
@@ -2,16 +2,18 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
App.AdminVotationTypesFields = {
|
App.AdminVotationTypesFields = {
|
||||||
adjustForm: function() {
|
adjustForm: function() {
|
||||||
if ($(this).val() === "unique") {
|
var select_field = $(this);
|
||||||
$(".max-votes").hide();
|
|
||||||
$(".description-unique").show();
|
$("[data-vote-type]").hide(0, function() {
|
||||||
$(".description-multiple").hide();
|
$("[data-vote-type=" + select_field.val() + "]").show();
|
||||||
$(".votation-type-max-votes").prop("disabled", true);
|
});
|
||||||
} else {
|
|
||||||
|
if (select_field.val() === "multiple") {
|
||||||
$(".max-votes").show();
|
$(".max-votes").show();
|
||||||
$(".description-unique").hide();
|
|
||||||
$(".description-multiple").show();
|
|
||||||
$(".votation-type-max-votes").prop("disabled", false);
|
$(".votation-type-max-votes").prop("disabled", false);
|
||||||
|
} else {
|
||||||
|
$(".max-votes").hide();
|
||||||
|
$(".votation-type-max-votes").prop("disabled", true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
|||||||
@@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<div class="callout primary">
|
<div class="callout primary">
|
||||||
<span class="description-unique">
|
<% descriptions.each do |vote_type, text| %>
|
||||||
<%= t("admin.polls.votation_type.unique_description") %>
|
<%= description_tag(vote_type, text) %>
|
||||||
</span>
|
<% end %>
|
||||||
<span class="description-multiple hidden">
|
|
||||||
<%= t("admin.polls.votation_type.multiple_description") %>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,17 @@ class Admin::VotationTypes::FieldsComponent < ApplicationComponent
|
|||||||
def initialize(form:)
|
def initialize(form:)
|
||||||
@form = form
|
@form = form
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def descriptions
|
||||||
|
{
|
||||||
|
unique: t("admin.polls.votation_type.unique_description"),
|
||||||
|
multiple: t("admin.polls.votation_type.multiple_description")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def description_tag(vote_type, text)
|
||||||
|
tag.span(text, data: { vote_type: vote_type })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user