From 6154510af69a800c437f5646fe1cb80d593bde7f Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Tue, 28 May 2019 00:12:17 -0600 Subject: [PATCH] Load and render public dictionary correctly --- src/js/view/displayToggles.js | 36 +++++++++++++++++++++++++++++++++++ src/js/view/index.js | 7 ++++--- src/js/view/setupListeners.js | 11 ++++------- src/php/api/router.php | 3 ++- 4 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 src/js/view/displayToggles.js diff --git a/src/js/view/displayToggles.js b/src/js/view/displayToggles.js new file mode 100644 index 0000000..bf1d893 --- /dev/null +++ b/src/js/view/displayToggles.js @@ -0,0 +1,36 @@ +import { renderDescription, renderDetails, renderStats } from './render'; + +export function showSection(sectionName) { + switch (sectionName) { + case 'description': showDescription(); break; + case 'details': showDetails(); break; + case 'stats': showStats(); break; + } +} + +export function hideDetailsPanel() { + document.getElementById('detailsPanel').style.display = 'none'; +} + +export function getIsDetailsPanelDisplayed() { + return document.getElementById('detailsPanel').style.display !== 'none'; +} + +function showDescription() { + const detailsPanel = document.getElementById('detailsPanel'); + detailsPanel.style.display = 'block'; + + renderDescription(); +} + +function showDetails() { + const detailsPanel = document.getElementById('detailsPanel'); + detailsPanel.style.display = 'block'; + renderDetails(); +} + +function showStats() { + const detailsPanel = document.getElementById('detailsPanel'); + detailsPanel.style.display = 'block'; + renderStats(); +} diff --git a/src/js/view/index.js b/src/js/view/index.js index ca3f0b9..591c84e 100644 --- a/src/js/view/index.js +++ b/src/js/view/index.js @@ -1,5 +1,6 @@ import '../../main.scss'; -import { getDictionary } from './dictionaryManagement'; +import { renderAll } from './render'; +import setupListeners from './setupListeners'; // import setupListeners, { setupSearchFilters } from './js/setupListeners'; // import { renderAll } from './js/render'; @@ -8,8 +9,8 @@ import { getDictionary } from './dictionaryManagement'; // import { loadSettings } from './js/settings'; function initialize() { - getDictionary(); - // setupSearchFilters(); + renderAll(); + setupListeners(); } window.onload = (function (oldLoad) { diff --git a/src/js/view/setupListeners.js b/src/js/view/setupListeners.js index 8b5bd59..82e8b47 100644 --- a/src/js/view/setupListeners.js +++ b/src/js/view/setupListeners.js @@ -1,4 +1,4 @@ -import {showSection, hideDetailsPanel} from '../displayToggles'; +import {showSection, hideDetailsPanel} from './displayToggles'; import { showSearchModal, clearSearchText, checkAllPartsOfSpeechFilters, uncheckAllPartsOfSpeechFilters } from '../search'; import { renderWords, renderInfoModal } from './render'; @@ -23,9 +23,6 @@ function setupDetailsTabs() { } }); }); - setupEditFormTabs(); - setupEditFormInteractions(); - setupEditFormButtons(); } function setupSearchBar() { @@ -82,17 +79,17 @@ export function setupSearchFilters() { export function setupInfoButtons() { document.getElementById('helpInfoButton').addEventListener('click', () => { - import('../markdown/help.md').then(html => { + import('../../markdown/help.md').then(html => { renderInfoModal(html); }); }); document.getElementById('termsInfoButton').addEventListener('click', () => { - import('../markdown/terms.md').then(html => { + import('../../markdown/terms.md').then(html => { renderInfoModal(html); }); }); document.getElementById('privacyInfoButton').addEventListener('click', () => { - import('../markdown/privacy.md').then(html => { + import('../../markdown/privacy.md').then(html => { renderInfoModal(html); }); }); diff --git a/src/php/api/router.php b/src/php/api/router.php index 4ae1e08..25f16ff 100644 --- a/src/php/api/router.php +++ b/src/php/api/router.php @@ -14,7 +14,8 @@ switch ($view) { $html = str_replace('{{dict}}', $dict, $html); $html = str_replace('{{dict_name}}', $dictionary_data['name'] . ' ' . $dictionary_data['specification'], $html); $html = str_replace('{{public_name}}', $dictionary_data['createdBy'], $html); - $html = str_replace('{{dict_json}}', json_encode($dictionary_data), $html); + $dictionary_json = json_encode($dictionary_data); + $html = str_replace('{{dict_json}}', addslashes($dictionary_json), $html); } echo $html; }