/** * Creates JavaScript function for remote AJAX call * * This function creates the javascript needed to make a remote call * it is primarily used as a helper for AjaxHelper::link. * * @param array $options options for javascript * @return string html code for link to remote action * @see AjaxHelper::link() for docs on options parameter. */ function remoteFunction($options) { if (isset($options['update'])) { if (!is_array($options['update'])) { $func = "new Ajax.Updater('{$options['update']}',"; } else { $func = "new Ajax.Updater(document.createElement('div'),"; } if (!isset($options['requestHeaders'])) { $options['requestHeaders'] = array(); } if (is_array($options['update'])) { $options['update'] = join(' ', $options['update']); } $options['requestHeaders']['X-Update'] = $options['update']; } else { $func = "new Ajax.Request("; } $func .= "'" . $this->url(isset($options['url']) ? $options['url'] : "") . "'"; $func .= ", " . $this->__optionsForAjax($options) . ")"; if (isset($options['before'])) { $func = "{$options['before']}; {$func}"; } if (isset($options['after'])) { $func = "{$func}; {$options['after']};"; } if (isset($options['condition'])) { $func = "if ({$options['condition']}) { {$func}; }"; } if (isset($options['confirm'])) { $func = "if (confirm('" . $this->Javascript->escapeString($options['confirm']) . "')) { {$func}; } else { event.returnValue = false; return false; }"; } return $func; }
/** * Creates JavaScript function for remote AJAX call * * This function creates the javascript needed to make a remote call * it is primarily used as a helper for AjaxHelper::link. * * @param array $options options for javascript * @return string html code for link to remote action * @see AjaxHelper::link() for docs on options parameter. */ function remoteFunction($options) { if (isset($options['update'])) { if (isset($options['position'])){ $position = $options['position']; unset($options['position']); } else{ $position = 'html'; } if (!is_array($options['update'])) { $func = "$.ajax("; if (!isset($options['complete'])){ $options['complete'] = ''; } $options['complete'] = "$('#" . $options['update'] . "').$position(request.responseText); " . $options['complete']; } else { $func = "$.ajax("; if (!isset($options['complete'])){ $options['complete'] = ''; } $selectors = ''; foreach($options['update'] as $selector){ $selectors .= '#' . $selector . ', '; } $options['complete'] = "$('" . $selectors . "').$position(request.responseText); " . $options['complete']; } if (is_array($options['update'])) { $options['update'] = join(' ', $options['update']); } } else { $func = "$.ajax("; } $options['url'] = $this->url(isset($options['url']) ? $options['url'] : ""); $func .= $this->__optionsForAjax($options) . ")"; if (isset($options['before'])) { $func = "{$options['before']}; $func"; } if (isset($options['after'])) { $func = "$func; {$options['after']};"; } if (isset($options['condition'])) { $func = "if ({$options['condition']}) { $func; }"; } if (isset($options['confirm'])) { $func = "if (confirm('" . $this->Javascript->escapeString($options['confirm']) . "')) { $func; } else { return false; }"; } return $func; }