CRM-12872 - Search js - toward popup actions
authorColeman Watts <coleman@civicrm.org>
Thu, 5 Jun 2014 18:52:32 +0000 (19:52 +0100)
committerColeman Watts <coleman@civicrm.org>
Thu, 5 Jun 2014 21:36:00 +0000 (22:36 +0100)
CRM/Core/Form.php
CRM/Core/StateMachine.php
js/crm.ajax.js
js/crm.searchForm.js

index 89c88a26dcd8f6a1a04748e01b99251a84119ade..f26ce82e2454c8c57c75b9bdeccf001fcd214b4c 100644 (file)
@@ -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)) {
index b1cd60f6201c0509b761b5c4377fe4b98a946ac7..7a0517a29e08690bb0310fce49565a926b286902 100644 (file)
@@ -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];
index f3ffbac15b31185079f1bf0a92fbb7a4e6db8863..2968acb30829ff32b3e79983cde8f756ba9a9b42 100644 (file)
     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) {
index d94ea93aa236c62d8812720cba7848a7e0b9eccc..b02a340362f9537f69133d552063963e8dfa51cc 100644 (file)
     })
     // 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._);