From 7e9fdecf37ce237620fc395dee80573abe78b1cf Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 5 Jun 2014 19:52:32 +0100 Subject: [PATCH] CRM-12872 - Search js - toward popup actions --- CRM/Core/Form.php | 6 ++++-- CRM/Core/StateMachine.php | 2 +- js/crm.ajax.js | 2 +- js/crm.searchForm.js | 20 +++++++++++++++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 89c88a26dc..f26ce82e24 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -296,13 +296,15 @@ class CRM_Core_Form extends HTML_QuickForm_Page { /** * This function is just a wrapper, so that we can call all the hook functions + * @param bool $allowAjax - FIXME: This feels kind of hackish, ideally we would take the json-related code from this function + * and bury it deeper down in the controller */ - function mainProcess() { + function mainProcess($allowAjax = TRUE) { $this->postProcess(); $this->postProcessHook(); // Respond with JSON if in AJAX context (also support legacy value '6') - if (!empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) { + if ($allowAjax && !empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) { $this->ajaxResponse['buttonName'] = str_replace('_qf_' . $this->getAttribute('id') . '_', '', $this->controller->getButtonName()); $this->ajaxResponse['action'] = $this->_action; if (isset($this->_id) || isset($this->id)) { diff --git a/CRM/Core/StateMachine.php b/CRM/Core/StateMachine.php index b1cd60f620..7a0517a29e 100644 --- a/CRM/Core/StateMachine.php +++ b/CRM/Core/StateMachine.php @@ -159,7 +159,7 @@ class CRM_Core_StateMachine { // the page is valid, process it if we are jumping to the next state if ($type == 'Next') { - $page->mainProcess(); + $page->mainProcess(FALSE); // we get the state again, since postProcess might have changed it // this bug took me forever to find :) Lobo $state = &$this->_states[$pageName]; diff --git a/js/crm.ajax.js b/js/crm.ajax.js index f3ffbac15b..2968acb308 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -468,7 +468,7 @@ e.preventDefault(); }; /** - * An event callback for CRM.popup or a standalone function to refresh the content around a popup link + * An event callback for CRM.popup or a standalone function to refresh the content around a given element * @param e event|selector */ CRM.refreshParent = function(e) { diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index d94ea93aa2..b02a340362 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -98,7 +98,25 @@ }) // When selecting a task .on('change', 'select#task', function() { - $(this).siblings('input[type=submit]').click(); + var $form = $(this).closest('form'), + $go = $('input.crm-search-go-button', $form); + if (1) { + $go.click(); + } + // The following code can load the task in a popup, however not all tasks function correctly with this + // So it's disabled pending a per-task opt-in mechanism + else { + var data = $form.serialize() + '&' + $go.attr('name') + '=' + $go.attr('value'); + var url = $form.attr('action'); + url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=json'; + clearTaskMenu(); + $.post(url, data, function(data) { + CRM.loadForm(data.userContext).on('crmFormSuccess', function() { + CRM.refreshParent($form); + }); + enableTaskMenu(); + }, 'json'); + } }); })(CRM.$, CRM._); -- 2.25.1