From 49f5e48ffa14a97b51fafe2579ef70c5fc5917f4 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Wed, 5 Nov 2025 13:27:21 -0800 Subject: [PATCH] ove organization dashboard JS to separate file --- app/assets/javascripts/index.js | 1 + .../javascripts/organizationDashboard.js | 68 +++++++++++++++++++ .../organizations/organization/index.html | 66 ++---------------- 3 files changed, 75 insertions(+), 60 deletions(-) create mode 100644 app/assets/javascripts/organizationDashboard.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index a7cd56fbb..7c1348397 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -60,6 +60,7 @@ import { initCurrentYear } from './date.js'; import './sidenav.js'; import './validation.js'; import './scrollPosition.js'; +import './organizationDashboard.js'; initCurrentYear(); diff --git a/app/assets/javascripts/organizationDashboard.js b/app/assets/javascripts/organizationDashboard.js new file mode 100644 index 000000000..cb85cef3c --- /dev/null +++ b/app/assets/javascripts/organizationDashboard.js @@ -0,0 +1,68 @@ +(function() { + 'use strict'; + + function scrollToElement(element, delay) { + setTimeout(function() { + element.scrollIntoView({ + behavior: 'smooth', + block: 'center', + inline: 'nearest' + }); + }, delay || 0); + } + + function focusFirstInput(container, delay) { + setTimeout(function() { + var input = container.querySelector('input[type="text"], input[type="email"]'); + if (input) input.focus(); + }, delay || 0); + } + + function highlightAndScrollToService(serviceId) { + var serviceRow = document.getElementById('service-' + serviceId); + if (serviceRow) { + scrollToElement(serviceRow, 300); + + setTimeout(function() { + serviceRow.classList.remove('is-highlighted'); + if (serviceRow.className === '') { + serviceRow.removeAttribute('class'); + } + }, 3300); + } + } + + function initForms() { + requestAnimationFrame(function() { + var form = document.getElementById('create-service-form') || + document.getElementById('invite-user-form') || + document.getElementById('edit-service-form'); + + if (form) { + scrollToElement(form, 50); + focusFirstInput(form, 150); + } + }); + } + + function initEditServiceConfirmation() { + var confirmEditButton = document.getElementById('edit-service-confirm-btn'); + if (confirmEditButton) { + confirmEditButton.addEventListener('click', function() { + var editForm = document.getElementById('edit-service-form'); + if (editForm) { + editForm.submit(); + } + }); + } + } + + document.addEventListener('DOMContentLoaded', function() { + initForms(); + initEditServiceConfirmation(); + }); + + window.OrganizationDashboard = { + highlightAndScrollToService: highlightAndScrollToService + }; +})(); diff --git a/app/templates/views/organizations/organization/index.html b/app/templates/views/organizations/organization/index.html index 553068ff6..d6bb9281e 100644 --- a/app/templates/views/organizations/organization/index.html +++ b/app/templates/views/organizations/organization/index.html @@ -265,73 +265,19 @@ {% block extra_javascripts %} {{ super() }} {% endblock %}