Note that in the budgets wizard test we now create district with no associated geozone, so the text "all city" will appear in the districts table too, meaning we can't use `within "section", text: "All city" do` anymore since it would result in an ambiguous match. Co-Authored-By: Julian Herrero <microweb10@gmail.com> Co-Authored-By: Javi Martín <javim@elretirao.net>
69 lines
2.3 KiB
JavaScript
69 lines
2.3 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(selector) {
|
|
$("body").on("change", selector, function() {
|
|
$(this).closest("form").submit();
|
|
return false;
|
|
});
|
|
},
|
|
toggleLink: function() {
|
|
$("body").on("click", ".js-toggle-link", function() {
|
|
var toggle_txt;
|
|
$($(this).data("toggle-selector")).toggle("down");
|
|
if ($(this).data("toggle-text") !== undefined) {
|
|
toggle_txt = $(this).text();
|
|
$(this).text($(this).data("toggle-text"));
|
|
$(this).data("toggle-text", toggle_txt);
|
|
}
|
|
return false;
|
|
});
|
|
},
|
|
synchronizeInputs: function() {
|
|
var banners, geozones, 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]']";
|
|
geozones = "[name='geozone[color]']";
|
|
inputs = $(progress_bar + ", " + processes + ", " + banners + ", " + geozones);
|
|
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]']").trigger("change");
|
|
},
|
|
initialize: function() {
|
|
App.Forms.disableEnter();
|
|
App.Forms.submitOnChange(".js-submit-on-change");
|
|
App.Forms.toggleLink();
|
|
App.Forms.synchronizeInputs();
|
|
App.Forms.hideOrShowFieldsAfterSelection();
|
|
}
|
|
};
|
|
}).call(this);
|