Skip to content

Commit

Permalink
Improve users autoblocks config form
Browse files Browse the repository at this point in the history
  • Loading branch information
entantoencuanto committed Dec 2, 2024
1 parent ca40ee6 commit 3a3c01b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def detect_and_run
end

def calculate_scores
@config_form = form(UsersAutoblocksConfigForm).from_model(current_config)
@config_form = form(UsersAutoblocksConfigForm).from_params(params)

AutoblockUsers.call(@config_form, perform_block: false) do
on(:ok) do |count|
Expand Down
20 changes: 20 additions & 0 deletions app/packs/src/decidim/decidim_awesome/admin/users_autoblocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
document.addEventListener("DOMContentLoaded", () => {
const configCheckBox = document.getElementById("users_autoblocks_config_perform_block");

configCheckBox.addEventListener("change", (event) => {
const form = event.currentTarget.form;
const submitButton = form.querySelector("[data-perform-block-message]");
const messages = JSON.parse(submitButton.dataset.performBlockMessage);
const justificationMessage = form.querySelector("[data-justification-message]");

if (event.target.checked) {
submitButton.setAttribute("data-confirm", submitButton.dataset.confirmMessage);
justificationMessage.classList.remove("hidden");
justificationMessage.querySelector("input").required = true;
} else {
submitButton.removeAttribute("data-confirm");
justificationMessage.classList.add("hidden");
justificationMessage.querySelector("input").required = false;
}
});
});
1 change: 1 addition & 0 deletions app/packs/src/decidim/decidim_awesome/awesome_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "src/decidim/decidim_awesome/admin/proposal_sortings"
import "src/decidim/decidim_awesome/admin/codemirror"
import "src/decidim/decidim_awesome/admin/check_redirections"
import "src/decidim/decidim_awesome/admin/form_exit_warn"
import "src/decidim/decidim_awesome/admin/users_autoblocks"

import "src/decidim/decidim_awesome/proposals/custom_fields"
import "src/decidim/decidim_awesome/admin/custom_fields_builder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<span class="help-text"><%= t(".threshold_config_detected_cases", count: @threshold_detected_cases) %></span>
<% end %>
</div>
<div class="form__wrapper gap-0 hidden" data-justification-message>
<%= form.text_field :block_justification_message, class: "mb-6", required: true, help_text: t(".block_justification_message_help") %>
</div>

<div class="form__wrapper gap-0">
<%= form.check_box :perform_block, class: "mb-6", help_text: t(".perform_block_message_help") %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
</table>
</div>

<%= decidim_form_for(@config_form, method: :post, url: decidim_admin_decidim_awesome.detect_and_run_users_autoblocks_path, html: { class: "form-defaults awesome-edit-config" }) do |f| %>
<%= decidim_form_for(
@config_form,
method: :post,
url: decidim_admin_decidim_awesome.detect_and_run_users_autoblocks_path,
html: { class: "form-defaults", id: "users_autoblocks_config"}
) do |f| %>
<div class="card pt-4">
<div class="card-section">
<%= render partial: "config_form", locals: { form: f } %>
Expand All @@ -49,8 +54,7 @@

<div class="item__edit-sticky">
<div class="item__edit-sticky-container">
<%= link_to t(".calculate_scores"), decidim_admin_decidim_awesome.calculate_scores_users_autoblocks_path, method: :post, class: "button button__sm button__secondary" %>
<%= f.submit t(".detect_and_run"), class: "button button__sm button__secondary", data: { confirm: t(".confirm_block") } %>
<%= f.submit t(".calculate_scores"), class: "button button__sm button__secondary", data: { confirm_message: t(".confirm_block"), perform_block_message: { "true": t(".detect_and_run"), "false": t(".calculate_scores") } } %>
</div>
</div>
<% end %>
Expand Down

0 comments on commit 3a3c01b

Please sign in to comment.