Skip to content

Commit 116b19d

Browse files
committed
Ensure that 'Allow Dismissal' checkbox is respected in Dashboard Panel.
See cuny-academic-commons/commons-in-a-box#538.
1 parent 56a97ab commit 116b19d

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

assets/js/dashboard-panel.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global ajaxurl, CBOXOLDashboardPanel */
22

33
// Create 'Screen options' checkbox for OpenLab News panel.
4-
const { backgroundColor, panelIsVisible, textColor } = CBOXOLDashboardPanel;
4+
const { allowDismissal, backgroundColor, panelIsVisible, textColor } = CBOXOLDashboardPanel;
55
const checkboxEl = document.createElement( 'input' );
66
checkboxEl.setAttribute( 'type', 'checkbox' );
77
checkboxEl.setAttribute( 'id', 'openlab_news_panel-hide' );
@@ -33,15 +33,17 @@ const dashboardWidgetsWrap = document.querySelector( '#dashboard-widgets-wrap' )
3333
dashboardWidgetsWrap.before( openlabNewsPanel );
3434

3535
// Add a Dismiss link to the panel.
36-
const openlabNewsPanelDismiss = document.createElement( 'a' );
37-
openlabNewsPanelDismiss.setAttribute( 'href', '#' );
38-
openlabNewsPanelDismiss.setAttribute( 'class', 'panel-dismiss' );
39-
openlabNewsPanelDismiss.textContent = 'Dismiss'; // @todo i18n
40-
openlabNewsPanel.prepend( openlabNewsPanelDismiss );
41-
openlabNewsPanelDismiss.addEventListener( 'click', ( e ) => {
42-
e.preventDefault();
43-
openlabNewsPanelDismissHandler( false );
44-
} );
36+
if ( allowDismissal ) {
37+
const openlabNewsPanelDismiss = document.createElement( 'a' );
38+
openlabNewsPanelDismiss.setAttribute( 'href', '#' );
39+
openlabNewsPanelDismiss.setAttribute( 'class', 'panel-dismiss' );
40+
openlabNewsPanelDismiss.textContent = 'Dismiss'; // @todo i18n
41+
openlabNewsPanel.prepend( openlabNewsPanelDismiss );
42+
openlabNewsPanelDismiss.addEventListener( 'click', ( e ) => {
43+
e.preventDefault();
44+
openlabNewsPanelDismissHandler( false );
45+
} );
46+
}
4547

4648
// Hide OpenLab News panel if checkbox is checked.
4749
const openlabNewsPanelShow = document.querySelector( '#openlab_news_panel-hide' );

includes/dashboard-panel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function display() {
105105
'cboxol-dashboard-panel',
106106
'const CBOXOLDashboardPanel = ' . wp_json_encode(
107107
[
108+
'allowDismissal' => (bool) $settings['allow_dismissal'],
108109
'backgroundColor' => $background_color,
109110
'panelIsVisible' => (bool) $panel_is_visible,
110111
'textColor' => $text_color,

0 commit comments

Comments
 (0)