From 71d8f97ba4063a914d9ed309a1263f298a5c3c66 Mon Sep 17 00:00:00 2001 From: robertgarrigos Date: Thu, 17 Oct 2024 18:27:09 +0200 Subject: [PATCH 1/3] Fixes #37: search dialog now works as in Drupal --- js/search-reference.js | 19 +++++---- references_dialog.module | 90 +++++++++++++++++++++++++--------------- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/js/search-reference.js b/js/search-reference.js index 10f4fb5..8740383 100644 --- a/js/search-reference.js +++ b/js/search-reference.js @@ -5,16 +5,21 @@ // We can't combine all of these, since that causes // JQuery.each() to freak ut.' var selector = null; - if ($('table.views-table').size() > 0) { - selector = $('table.views-table tbody tr:not(.views-table-row-select-all)'); + // Check for elements matching any of the desired selectors. + if ($('table.views-table', context).length > 0) { + // Use the views-table if found. + selector = $('table.views-table tbody tr:not(.views-table-row-select-all)', context); } - else if ($('table.views-view-grid').size() > 0) { - selector = $('table.views-view-grid td'); + else if ($('table.views-view-grid', context).length > 0) { + // Use views-view-grid if found. + selector = $('table.views-view-grid td', context); } - else if ($('.views-row').size() > 0) { - selector = $('.views-row'); + else if ($('.views-row', context).length > 0) { + // Use views-row if found. + selector = $('.views-row', context); } else { + // If no elements match any of the selectors, exit. return; } selector.each(function(index) { @@ -38,7 +43,7 @@ // For links within the Views table, or those with a destination // parameter, open in a new window instead. - if (href.indexOf('destination=') >= 0 || $(element).parents('table.views-table tbody').size() > 0) { + if (href.indexOf('destination=') >= 0 || $(element).parents('table.views-table tbody').length > 0) { $(element).attr('target', '_blank'); return; } diff --git a/references_dialog.module b/references_dialog.module index 771bdf2..9f4d0dd 100644 --- a/references_dialog.module +++ b/references_dialog.module @@ -5,6 +5,43 @@ * This the main module file. */ +/** + * Implements hook_autoload_info(). + */ +function references_dialog_autoload_info() { + return array( + 'references_dialog_plugin_display' => 'views/references_dialog_plugin_display.inc', + ); +} + +/** + * Implements hook_menu(). + */ +function references_dialog_menu() { + $items = array(); + // This redirect callback is used when adding and editing content in + // the overlay. When content is created or edited, we are directed here, + // so we can act properly on entities. + $items['references-dialog/redirect/%/%'] = array( + 'page callback' => 'references_dialog_redirect_page', + 'page arguments' => array(2, 3), + 'access callback' => 'references_dialog_redirect_access', + 'access arguments' => array(2, 3), + ); + return $items; +} + +/** + * Implements hook_theme(). + */ +function references_dialog_theme() { + return array( + 'references_dialog_links' => array( + 'variables' => array('links' => NULL), + ), + ); +} + /** * Implements hook_element_info(). */ @@ -42,32 +79,6 @@ function references_dialog_element_info_alter(&$info) { } } -/** - * Implements hook_autoload_info(). - */ -function references_dialog_autoload_info() { - return array( - 'references_dialog_plugin_display' => 'views/references_dialog_plugin_display.inc', - ); -} - -/** - * Implements hook_menu(). - */ -function references_dialog_menu() { - $items = array(); - // This redirect callback is used when adding and editing content in - // the overlay. When content is created or edited, we are directed here, - // so we can act properly on entities. - $items['references-dialog/redirect/%/%'] = array( - 'page callback' => 'references_dialog_redirect_page', - 'page arguments' => array(2, 3), - 'access callback' => 'references_dialog_redirect_access', - 'access arguments' => array(2, 3), - ); - return $items; -} - /** * Implements hook_admin_paths(). */ @@ -394,14 +405,14 @@ function references_dialog_js_settings($id, array $settings) { } /** - * Implements hook_theme(). + * Process variables for references_dialog_page. */ -function references_dialog_theme() { - return array( - 'references_dialog_links' => array( - 'variables' => array('links' => NULL), - ), - ); +function template_process_references_dialog_page(&$variables) { + // Generate messages last in order to capture as many as possible for the + // current page. + if (!isset($variables['messages'])) { + $variables['messages'] = $variables['page']['#show_messages'] ? theme('status_messages') : ''; + } } /** @@ -543,6 +554,19 @@ function references_dialog_get_views_search_links($attachable) { return $links; } +/** + * Implements hook_preprocess_page(). + */ +function references_dialog_preprocess_page(&$variables) { + + if (references_dialog_in_dialog()) { + unset($variables['page_bottom']); + $variables['page'] = '
' . $variables['page'] . '
'; + backdrop_add_js('file', '/js/search-reference.js',); + } +} + + /** * Check if we are in a references dialog. * @return boolean if we are in a dialog. From a6a24b078722ba23ccb01f0e38e59eac5151ba60 Mon Sep 17 00:00:00 2001 From: Robert Garrigos Date: Thu, 17 Oct 2024 18:50:49 +0200 Subject: [PATCH 2/3] Deletes unused theme preprocess function --- references_dialog.module | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/references_dialog.module b/references_dialog.module index 9f4d0dd..8f6aeef 100644 --- a/references_dialog.module +++ b/references_dialog.module @@ -404,17 +404,6 @@ function references_dialog_js_settings($id, array $settings) { ); } -/** - * Process variables for references_dialog_page. - */ -function template_process_references_dialog_page(&$variables) { - // Generate messages last in order to capture as many as possible for the - // current page. - if (!isset($variables['messages'])) { - $variables['messages'] = $variables['page']['#show_messages'] ? theme('status_messages') : ''; - } -} - /** * Implements hook_entity_insert(). */ From 487914bd50671ae3db31f2afc870bcba37003e03 Mon Sep 17 00:00:00 2001 From: robertgarrigos Date: Sun, 20 Oct 2024 22:19:58 +0200 Subject: [PATCH 3/3] show apply button only when needed. no DB error. --- references_dialog.module | 1 - views/references_dialog_plugin_display.inc | 2 -- 2 files changed, 3 deletions(-) diff --git a/references_dialog.module b/references_dialog.module index 8f6aeef..a5f7e67 100644 --- a/references_dialog.module +++ b/references_dialog.module @@ -549,7 +549,6 @@ function references_dialog_get_views_search_links($attachable) { function references_dialog_preprocess_page(&$variables) { if (references_dialog_in_dialog()) { - unset($variables['page_bottom']); $variables['page'] = '
' . $variables['page'] . '
'; backdrop_add_js('file', '/js/search-reference.js',); } diff --git a/views/references_dialog_plugin_display.inc b/views/references_dialog_plugin_display.inc index fb203a5..77d4c9d 100644 --- a/views/references_dialog_plugin_display.inc +++ b/views/references_dialog_plugin_display.inc @@ -152,8 +152,6 @@ class references_dialog_plugin_display extends views_plugin_display { return $items; } - function uses_exposed() { return TRUE; } - /** * Override references_plugin_display, and * allow for other style types.