Files
grecia/app/assets/javascripts/forms.js
Javi Martín 5211f47842 Add and apply ESLint spacing rules
For now we're only adding rules related to spacing and double quotes,
following the same rules we use in Ruby, which are the same rules
CoffeeScript followed when compiling these files.

We're also using the recommended ESLint rules, which will warn us about
many JavaScript common pitfalls, the `strict` rule which enforces using
strict mode, and the `no-console` rule, which will prevent us from
shipping code meant for debugging.

Although it's arguably more common to use the JSON format to define
these rules, I've chosen YAML because it's the format we use in all our
linters.
2019-09-11 14:03:24 +02:00

68 lines
2.2 KiB
JavaScript

(function() {
"use strict";
App.Forms = {
disableEnter: function() {
$("form.js-enter-disabled").on("keyup keypress", function(event) {
if (event.which === 13) {
event.preventDefault();
}
});
},
submitOnChange: function() {
$(".js-submit-on-change").unbind("change").on("change", function() {
$(this).closest("form").submit();
return false;
});
},
toggleLink: function() {
$(".js-toggle-link").unbind("click").on("click", function() {
var toggle_txt;
$($(this).data("toggle-selector")).toggle("down");
if ($(this).data("toggle-text") !== void 0) {
toggle_txt = $(this).text();
$(this).text($(this).data("toggle-text"));
$(this).data("toggle-text", toggle_txt);
}
return false;
});
},
synchronizeInputs: function() {
var banners, inputs, processes, progress_bar;
progress_bar = "[name='progress_bar[percentage]']";
processes = "[name='legislation_process[background_color]'], [name='legislation_process[font_color]']";
banners = "[name='banner[background_color]'], [name='banner[font_color]']";
inputs = $(progress_bar + ", " + processes + ", " + banners);
inputs.on({
input: function() {
$("[name='" + this.name + "']").val($(this).val());
}
});
inputs.trigger("input");
},
hideOrShowFieldsAfterSelection: function() {
$("[name='progress_bar[kind]']").on({
change: function() {
var locale, title_field;
locale = App.Globalize.selected_language();
title_field = $(".translatable-fields[data-locale=" + locale + "]");
if (this.value === "primary") {
title_field.hide();
$(".globalize-languages").hide();
} else {
title_field.show();
$(".globalize-languages").show();
}
}
});
$("[name='progress_bar[kind]']").change();
},
initialize: function() {
App.Forms.disableEnter();
App.Forms.submitOnChange();
App.Forms.toggleLink();
App.Forms.synchronizeInputs();
App.Forms.hideOrShowFieldsAfterSelection();
}
};
}).call(this);