예제 #1
0
 function remoteFunction(&$controller, $options)
 {
     $javascript_options = JavascriptHelper::optionsForAjax($options);
     $update = '';
     if (isset($options['update']) && is_string($options['update'])) {
         require_once 'vendor/spyc.php';
         $val = @Spyc::YAMLLoad($options['update']);
         if (!empty($val)) {
             // it's a YAML array, so load it into options['update']
             $options['update'] = $val;
         }
     }
     if (isset($options['update']) && is_array($options['update'])) {
         $update = array();
         if (isset($options['update']['success'])) {
             $update[] = "success:'{$options['update']['success']}'";
         }
         if (isset($options['update']['failure'])) {
             $update[] = "failure:'{$options['update']['failure']}'";
         }
         $update = implode(',', $update);
     } else {
         if (isset($options['update'])) {
             $update = $options['update'];
         }
     }
     $function = isset($options['update']) ? "new Ajax.Updater('{$update}', " : 'new Ajax.Request(';
     $function .= "'" . UrlHelper::urlFor($controller, $options['url']) . "'";
     $function .= ', ' . $javascript_options . ')';
     $function = (isset($options['before']) ? "{$options['before']}; " : '') . $function;
     $function .= isset($options['after']) ? "; {$options['after']};" : '';
     $function = isset($options['condition']) ? 'if(' . $options['condition'] . '){' . $function . '}' : $function;
     $function = isset($options['confirm']) ? 'if(confirm' . $options['condition'] . '){' . $function . '}' : $function;
     return $function;
 }