| 1 |
/** |
| 2 |
* Entries Page Script. |
| 3 |
* |
| 4 |
* Handles UI interactions on the Entries admin page. |
| 5 |
*/ |
| 6 |
|
| 7 |
wp.domReady( () => { |
| 8 |
|
| 9 |
/** |
| 10 |
* Internal dependencies |
| 11 |
*/ |
| 12 |
const { applyZebraStriping } = window.frmAdminBuild; |
| 13 |
const { onClickPreventDefault } = frmDom.util; |
| 14 |
|
| 15 |
/** |
| 16 |
* Applies zebra striping to the entry view page table. |
| 17 |
*/ |
| 18 |
applyZebraStriping( '.frm-alt-table', 'frm-empty-row' ); |
| 19 |
|
| 20 |
/** |
| 21 |
* Manages the behavior of the 'Show Empty Fields' button. |
| 22 |
* |
| 23 |
* Handles the initialization and event binding for the button. It toggles |
| 24 |
* the button's state between showing and hiding empty fields in the table and adjusts |
| 25 |
* the zebra striping accordingly. |
| 26 |
*/ |
| 27 |
manageShowEmptyFieldsButton(); |
| 28 |
|
| 29 |
function manageShowEmptyFieldsButton() { |
| 30 |
const showEmptyFieldsButton = document.getElementById( 'frm-entry-show-empty-fields' ); |
| 31 |
|
| 32 |
// Early return if the button is not found in the DOM. |
| 33 |
if ( ! showEmptyFieldsButton ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
if ( ! showEmptyFieldsButton.dataset.show ) { |
| 38 |
showEmptyFieldsButton.dataset.show = 'false'; |
| 39 |
} |
| 40 |
|
| 41 |
onClickPreventDefault( showEmptyFieldsButton, () => { |
| 42 |
// Toggle button state and update table striping |
| 43 |
const newShowState = showEmptyFieldsButton.dataset.show === 'true' ? 'false' : 'true'; |
| 44 |
showEmptyFieldsButton.dataset.show = newShowState; |
| 45 |
|
| 46 |
setTimeout( () => { |
| 47 |
applyZebraStriping( '.frm-alt-table', newShowState === 'true' ? '' : 'frm-empty-row' ); |
| 48 |
}, newShowState === 'true' ? 0 : 200 ); |
| 49 |
}); |
| 50 |
} |
| 51 |
}); |
| 52 |
|