From b03e84daf46f4906a22ae01ca0917cc44d12f19b Mon Sep 17 00:00:00 2001 From: tooyosi Date: Mon, 7 Oct 2024 08:05:05 +0100 Subject: [PATCH] hound cleanups --- app/assets/javascripts/views/forms/form.js | 37 ++++++++++++++-------- app/controllers/reducers_controller.rb | 1 - config/initializers/assets.rb | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/views/forms/form.js b/app/assets/javascripts/views/forms/form.js index 5e9c4d25..2f6c366d 100644 --- a/app/assets/javascripts/views/forms/form.js +++ b/app/assets/javascripts/views/forms/form.js @@ -1,20 +1,31 @@ document.addEventListener("DOMContentLoaded", function () { - const form = document.querySelector("form"); - const prefix = 'reducer'; - const is_reducer_form = form?.id.includes(prefix); - - const toggle_input = function(value){ - const is_subject = value.includes('subject'); - let hidden_input_id = is_subject ? 'user_reducer_keys' : 'subject_reducer_keys'; - let visible_input_id = hidden_input_id.includes('user_reducer_keys') ? 'subject_reducer_keys' : 'user_reducer_keys'; - - document.getElementById(hidden_input_id)?.classList.remove('hidden'); - - document.getElementById(visible_input_id)?.classList.add('hidden'); + var form = document.querySelector("form"); + var prefix = 'reducer'; + var is_reducer_form = false + if(form){ + is_reducer_form = form.id.includes(prefix); } + + var toggle_input = function(value){ + var is_subject = value.includes('subject'); + var hidden_input_id = is_subject ? 'user_reducer_keys' : 'subject_reducer_keys'; + var visible_input_id = hidden_input_id.includes('user_reducer_keys') ? 'subject_reducer_keys' : 'user_reducer_keys'; + + var hidden_input = document.getElementById(hidden_input_id); + + if(hidden_input){ + hidden_input.classList.remove('hidden'); + }; + + var visible_input = document.getElementById(visible_input_id); + if(visible_input){ + visible_input.classList.add('hidden'); + }; + }; + if (is_reducer_form) { - const reducer_topic = document.getElementById("reducer_topic"); + var reducer_topic = document.getElementById("reducer_topic"); toggle_input(reducer_topic.value); diff --git a/app/controllers/reducers_controller.rb b/app/controllers/reducers_controller.rb index 77112c9c..968a9358 100644 --- a/app/controllers/reducers_controller.rb +++ b/app/controllers/reducers_controller.rb @@ -144,6 +144,5 @@ def remove_unwanted_config_key(param_object) elsif param_object[:user_reducer_keys] = nil end - @reducer.save if @reducer end end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 90bd7a78..c88beb5a 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -12,4 +12,4 @@ # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) -Rails.application.config.assets.precompile += %w( views/forms/form.js ) \ No newline at end of file +Rails.application.config.assets.precompile += %w[views/forms/form.js]