Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@
"js/formidable_styles.js",
"js/formidable-color-picker.js",
"js/formidable_admin.js",
"js/formidable_builder.js",
"js/formidable-form-settings.js",
"js/formidable-global-settings.js",
"js/formidable-import-export.js",
"js/bootstrap-multiselect.js",
"js/formidable-settings-components.js",
"js/formidable-web-components.js",
Expand Down
58 changes: 55 additions & 3 deletions classes/controllers/FrmAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,9 @@ public static function admin_js() {
self::enqueue_floating_links( $plugin_url, $version );
}

wp_register_script( 'formidable_admin', $plugin_url . '/js/formidable_admin.js', self::get_admin_js_dependencies(), $version, true );
$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
$admin_dependencies = self::get_admin_js_dependencies( $page, $plugin_url, $version );
wp_register_script( 'formidable_admin', $plugin_url . '/js/formidable_admin.js', $admin_dependencies, $version, true );

wp_register_script(
'formidable_forms_list',
Expand All @@ -761,7 +763,6 @@ public static function admin_js() {
FrmTransLiteAppController::hide_gateway_fields_in_builder();
}

$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
$post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );

global $pagenow;
Expand Down Expand Up @@ -795,6 +796,7 @@ public static function admin_js() {
// Registers and enqueues the entries page scripts.
wp_register_script( 'formidable_entries', $plugin_url . '/js/admin/entries.js', array( 'formidable_admin', 'wp-dom-ready' ), $version, true );
wp_enqueue_script( 'formidable_entries' );
wp_set_script_translations( 'formidable_entries', 'formidable' );
}

do_action( 'frm_enqueue_builder_scripts' );
Expand Down Expand Up @@ -857,9 +859,13 @@ private static function register_color_picker_script( $plugin_url, $version ) {
/**
* @since 6.27
*
* @param string $page The admin page slug.
* @param string $plugin_url The plugin asset URL.
* @param string $version The plugin version.
*
* @return array
*/
private static function get_admin_js_dependencies() {
private static function get_admin_js_dependencies( $page, $plugin_url, $version ) {
$dependencies = array(
'formidable_admin_global',
'jquery',
Expand All @@ -880,9 +886,55 @@ private static function get_admin_js_dependencies() {
$dependencies[] = 'formidable-color-picker';
}

$page_script = self::get_admin_page_script( $page );

if ( ! $page_script ) {
return $dependencies;
}

// Register page hooks before the shared script creates the public admin API.
wp_register_script( $page_script, $plugin_url . '/js/' . $page_script . '.js', array( 'jquery', 'wp-hooks', 'wp-i18n' ), $version, true );
wp_set_script_translations( $page_script, 'formidable' );
$dependencies[] = $page_script;

return $dependencies;
}

/**
* Get the script for the current Formidable admin screen.
*
* @param string $page The admin page slug.
*
* @return string
*/
private static function get_admin_page_script( $page ) {
if ( 'formidable-import' === $page ) {
return 'formidable-import-export';
}

if ( 'formidable-settings' === $page ) {
return 'formidable-global-settings';
}

if ( 'formidable' === $page ) {
$action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );

if ( '' === $action ) {
$action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_title' );
}

if ( in_array( $action, array( 'edit', 'create', 'update', 'duplicate' ), true ) ) {
return 'formidable_builder';
}

if ( in_array( $action, array( 'settings', 'update_settings' ), true ) ) {
return 'formidable-form-settings';
}
}

return '';
}

/**
* Enqueue the Form Builder assets.
*
Expand Down
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export default [
'js/formidable_styles.js',
'js/formidable-color-picker.js',
'js/formidable_admin.js',
'js/formidable_builder.js',
'js/formidable-form-settings.js',
'js/formidable-global-settings.js',
'js/formidable-import-export.js',
'js/bootstrap-multiselect.js',
'js/formidable-settings-components.js',
'js/formidable-web-components.js',
Expand Down
76 changes: 76 additions & 0 deletions js/admin/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,88 @@ wp.domReady( () => {
* the zebra striping accordingly.
*/
manageShowEmptyFieldsButton();
maybeInitEntriesListPage();

/**
* Opens the "Not spam" modal on a spam entry.
*/
manageNotSpamModal();

/**
* Enforce the maximum number of entries list columns dynamically.
*
* @since 6.24
*
* @return {void}
*/
function maybeInitEntriesListPage() {
if ( ! document.body.classList.contains( 'frm-admin-page-entries' ) ) {
return;
}

const screenOptionsWrapper = document.getElementById( 'screen-options-wrap' );
if ( ! screenOptionsWrapper ) {
return;
}

const maxSelectionsNote = frmDom.div( {
className: 'frm_warning_style',
text: wp.i18n.__( 'Only 10 columns can be selected at a time.', 'formidable' ),
} );
maxSelectionsNote.style.margin = 0;

const legend = screenOptionsWrapper.querySelector( 'legend' );
legend.parentNode.insertBefore( maxSelectionsNote, legend.nextElementSibling );

const checkboxes = Array.from( screenOptionsWrapper.querySelectorAll( 'input[type="checkbox"]' ) );
const maximumColumns = 10;
const getSelectedCount = () => {
return checkboxes.reduce( ( count, checkbox ) => {
return checkbox.checked ? count + 1 : count;
}, 0 );
};
const disableCheckboxesIfAtMax = () => {
if ( getSelectedCount() >= maximumColumns ) {
maxSelectionsNote.classList.remove( 'frm_hidden' );
checkboxes.forEach( checkbox => {
if ( ! checkbox.checked ) {
checkbox.parentNode.classList.add( 'frm_noallow' );
checkbox.disabled = true;
}
} );
} else {
maxSelectionsNote.classList.add( 'frm_hidden' );
}
};
const addCheckboxListeners = () => {
checkboxes.forEach(
checkbox => {
checkbox.addEventListener(
'change',
event => {
if ( event.target.checked ) {
disableCheckboxesIfAtMax();
} else {
maxSelectionsNote.classList.add( 'frm_hidden' );

// Enable all checkboxes when a checkbox is unchecked.
checkboxes.forEach(
checkbox => {
checkbox.parentNode.classList.remove( 'frm_noallow' );
checkbox.disabled = false;
}
);
}
}
);
}
);
};

disableCheckboxesIfAtMax();
addCheckboxListeners();
}

function manageShowEmptyFieldsButton() {
const showEmptyFieldsButton = document.getElementById( 'frm-entry-show-empty-fields' );

Expand Down
1 change: 1 addition & 0 deletions js/formidable-form-settings.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/formidable-global-settings.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/formidable-import-export.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions js/formidable_admin.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions js/formidable_builder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/frm_testing_mode.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/src/admin/addon-state.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { __ } from '@wordpress/i18n';
const { __ } = wp.i18n;

const { div, svg } = frmDom;

Expand Down
Loading