From 802cd3d12505ad4baab23f747f799fef6c09feaf Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 12 Sep 2023 22:51:06 +0200 Subject: [PATCH] Read popup HTML content based on popup name --- app/javascript/packs/application.js | 32 ++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index d02b6922d..0936e2964 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -54,20 +54,42 @@ document.addEventListener("turbolinks:load", function () { }); checkForNewsPopups(); -}) +}); + +const NEWS_POPUPS_BASE_PATH = '/news_popups/'; function checkForNewsPopups() { - $.ajax({ + $.get({ url: Routes.news_popups_path(), type: 'GET', dataType: 'json', - success: (data) => { - console.log(data); + success: (popupNames) => { + console.log(`Found unread news popups: ${popupNames}`); + openNewsPopups(popupNames); }, error: (xhr, status) => { console.log('ERROR fetching news popups'); console.log(xhr); console.log(status); } - }) + }); +} + +function openNewsPopups(popupNames) { + for (const popupName of popupNames) { + console.log(`Opening news popup: ${popupName}`) + $.ajax({ + url: NEWS_POPUPS_BASE_PATH + popupName + '.html', + type: 'GET', + dataType: 'html', + success: (html, textStatus, xhr) => { + console.log(`News popup (${popupName}): ${html}`); + }, + error: (xhr, status) => { + console.log(`ERROR getting HTML for news popup: ${popupName}`); + console.log(xhr); + console.log(status); + } + }) + } } \ No newline at end of file