/**
* 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)) {
// 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];
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) {
})
// 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._);