| 159 | | $content = escape_javascript(isset($options['content']) ? $options['content'] : ''); |
|---|
| 160 | | |
|---|
| 161 | | $value = isset($options['action']) ? $options['action'] : 'update'; |
|---|
| 162 | | switch ($value) |
|---|
| 163 | | { |
|---|
| 164 | | case 'update': |
|---|
| 165 | | $updateMethod = _update_method(isset($options['position']) ? $options['position'] : ''); |
|---|
| 166 | | $javascript_function = "jQuery('#$element_id').$updateMethod('$content')"; |
|---|
| 167 | | break; |
|---|
| 168 | | |
|---|
| 169 | | case 'empty': |
|---|
| 170 | | $javascript_function = "jQuery('#$element_id').empty()"; |
|---|
| 171 | | break; |
|---|
| 172 | | |
|---|
| 173 | | case 'remove': |
|---|
| 174 | | $javascript_function = "jQuery('#$element_id').remove()"; |
|---|
| 175 | | break; |
|---|
| 176 | | |
|---|
| 177 | | default: |
|---|
| 178 | | throw new sfException('Invalid action, choose one of update, remove, empty'); |
|---|
| 179 | | } |
|---|
| 180 | | |
|---|
| 181 | | $javascript_function .= ";\n"; |
|---|
| 182 | | |
|---|
| 183 | | return (isset($options['binding']) ? $javascript_function.$options['binding'] : $javascript_function); |
|---|
| | 159 | $content = escape_javascript(isset($options['content']) ? $options['content'] : ''); |
|---|
| | 160 | |
|---|
| | 161 | $value = isset($options['action']) ? $options['action'] : 'update'; |
|---|
| | 162 | switch ($value) |
|---|
| | 163 | { |
|---|
| | 164 | case 'update': |
|---|
| | 165 | $updateMethod = _update_method(isset($options['position']) ? $options['position'] : ''); |
|---|
| | 166 | $javascript_function = "jQuery('#$element_id').$updateMethod('$content')"; |
|---|
| | 167 | break; |
|---|
| | 168 | |
|---|
| | 169 | case 'empty': |
|---|
| | 170 | $javascript_function = "jQuery('#$element_id').empty()"; |
|---|
| | 171 | break; |
|---|
| | 172 | |
|---|
| | 173 | case 'remove': |
|---|
| | 174 | $javascript_function = "jQuery('#$element_id').remove()"; |
|---|
| | 175 | break; |
|---|
| | 176 | |
|---|
| | 177 | default: |
|---|
| | 178 | throw new sfException('Invalid action, choose one of update, remove, empty'); |
|---|
| | 179 | } |
|---|
| | 180 | |
|---|
| | 181 | $javascript_function .= ";\n"; |
|---|
| | 182 | |
|---|
| | 183 | return (isset($options['binding']) ? $javascript_function.$options['binding'] : $javascript_function); |
|---|
| 198 | | // Defining elements to update |
|---|
| 199 | | if (isset($options['update']) && is_array($options['update'])) |
|---|
| 200 | | { |
|---|
| 201 | | // On success, update the element with returned data |
|---|
| 202 | | if (isset($options['update']['success'])) $update_success = "#".$options['update']['success']; |
|---|
| 203 | | |
|---|
| 204 | | // On failure, execute a client-side function |
|---|
| 205 | | if (isset($options['update']['failure'])) $update_failure = $options['update']['failure']; |
|---|
| 206 | | } |
|---|
| 207 | | else if (isset($options['update'])) $update_success = "#".$options['update']; |
|---|
| 208 | | |
|---|
| 209 | | // Update method |
|---|
| 210 | | $updateMethod = _update_method(isset($options['position']) ? $options['position'] : ''); |
|---|
| 211 | | |
|---|
| 212 | | // Callbacks |
|---|
| 213 | | if (isset($options['loading'])) $callback_loading = $options['loading']; |
|---|
| 214 | | if (isset($options['complete'])) $callback_complete = $options['complete']; |
|---|
| 215 | | |
|---|
| 216 | | // POST or GET ? |
|---|
| 217 | | $method = 'POST'; |
|---|
| 218 | | if ((isset($options['method'])) && (strtoupper($options['method']) == 'GET')) $method = $options['method']; |
|---|
| 219 | | |
|---|
| 220 | | // async or sync, async is default |
|---|
| 221 | | if ((isset($options['type'])) && ($options['type'] == 'synchronous')) $type = 'false'; |
|---|
| 222 | | |
|---|
| 223 | | $execute = 'false'; |
|---|
| 224 | | if ((isset($options['script'])) && ($options['script'] == '1')) $execute = 'true'; |
|---|
| 225 | | |
|---|
| 226 | | // Is it a form submitting |
|---|
| 227 | | if (isset($options['form'])) $formData = 'jQuery(this).serialize()'; |
|---|
| 228 | | elseif (isset($options['submit'])) $formData = '{\'#'.$options['submit'].'\'}.serialize()'; |
|---|
| 229 | | elseif (isset($options['with'])) $formData = '\''.$options['with'].'\''; |
|---|
| 230 | | |
|---|
| 231 | | // build the function |
|---|
| 232 | | $function = "jQuery.ajax({"; |
|---|
| 233 | | $function .= 'type:\''.$method.'\''; |
|---|
| 234 | | if ($execute) $function .= ',dataType:\'html\'';else $function .= 'dataType:\'text\''; |
|---|
| 235 | | if (isset($type)) $function .= ',async:'.$type; |
|---|
| 236 | | if (isset($formData)) $function .= ',data:'.$formData; |
|---|
| 237 | | if (isset($update_success)) $function .= ',success:function(i){jQuery(\''.$update_success.'\').'.$updateMethod.'(i);}'; |
|---|
| 238 | | if (isset($update_failure)) $function .= ',error:function(){'.$update_failure.'}'; |
|---|
| 239 | | if (isset($callback_loading)) $function .= ',beforeSend:function(){'.$callback_loading.'}'; |
|---|
| 240 | | if (isset($callback_complete)) $function .= ',complete:function(request){'.$callback_complete.'}'; |
|---|
| 241 | | $function .= ',url:\''.url_for($options['url']).'\''; |
|---|
| 242 | | $function .= '})'; |
|---|
| 243 | | |
|---|
| 244 | | if (isset($options['before'])) |
|---|
| 245 | | { |
|---|
| 246 | | $function = $options['before'].'; '.$function; |
|---|
| 247 | | } |
|---|
| 248 | | if (isset($options['after'])) |
|---|
| 249 | | { |
|---|
| 250 | | $function = $function.'; '.$options['after']; |
|---|
| 251 | | } |
|---|
| 252 | | if (isset($options['condition'])) |
|---|
| 253 | | { |
|---|
| 254 | | $function = 'if ('.$options['condition'].') { '.$function.'; }'; |
|---|
| 255 | | } |
|---|
| 256 | | if (isset($options['confirm'])) |
|---|
| 257 | | { |
|---|
| 258 | | $function = "if (confirm('".escape_javascript($options['confirm'])."')) { $function; }"; |
|---|
| 259 | | if (isset($options['cancel'])) |
|---|
| 260 | | { |
|---|
| 261 | | $function = $function.' else { '.$options['cancel'].' }'; |
|---|
| 262 | | } |
|---|
| 263 | | } |
|---|
| 264 | | |
|---|
| 265 | | return $function; |
|---|
| | 198 | // Defining elements to update |
|---|
| | 199 | if (isset($options['update']) && is_array($options['update'])) |
|---|
| | 200 | { |
|---|
| | 201 | // On success, update the element with returned data |
|---|
| | 202 | if (isset($options['update']['success'])) $update_success = "#".$options['update']['success']; |
|---|
| | 203 | |
|---|
| | 204 | // On failure, execute a client-side function |
|---|
| | 205 | if (isset($options['update']['failure'])) $update_failure = $options['update']['failure']; |
|---|
| | 206 | } |
|---|
| | 207 | else if (isset($options['update'])) $update_success = "#".$options['update']; |
|---|
| | 208 | |
|---|
| | 209 | // Update method |
|---|
| | 210 | $updateMethod = _update_method(isset($options['position']) ? $options['position'] : ''); |
|---|
| | 211 | |
|---|
| | 212 | // Callbacks |
|---|
| | 213 | if (isset($options['loading'])) $callback_loading = $options['loading']; |
|---|
| | 214 | if (isset($options['complete'])) $callback_complete = $options['complete']; |
|---|
| | 215 | if (isset($options['success'])) $callback_success = $options['success']; |
|---|
| | 216 | |
|---|
| | 217 | // Data Type |
|---|
| | 218 | if (isset($options['dataType'])) |
|---|
| | 219 | { |
|---|
| | 220 | $dataType = $options['dataType']; |
|---|
| | 221 | } |
|---|
| | 222 | elseif ($execute) |
|---|
| | 223 | { |
|---|
| | 224 | $dataType = 'html'; |
|---|
| | 225 | } |
|---|
| | 226 | else |
|---|
| | 227 | { |
|---|
| | 228 | $dataType = 'text'; |
|---|
| | 229 | } |
|---|
| | 230 | |
|---|
| | 231 | // POST or GET ? |
|---|
| | 232 | $method = 'POST'; |
|---|
| | 233 | if ((isset($options['method'])) && (strtoupper($options['method']) == 'GET')) $method = $options['method']; |
|---|
| | 234 | |
|---|
| | 235 | // async or sync, async is default |
|---|
| | 236 | if ((isset($options['type'])) && ($options['type'] == 'synchronous')) $type = 'false'; |
|---|
| | 237 | |
|---|
| | 238 | $execute = 'false'; |
|---|
| | 239 | if ((isset($options['script'])) && ($options['script'] == '1')) $execute = 'true'; |
|---|
| | 240 | |
|---|
| | 241 | // Is it a form submitting |
|---|
| | 242 | if (isset($options['form'])) $formData = 'jQuery(this).serialize()'; |
|---|
| | 243 | elseif (isset($options['submit'])) $formData = '{\'#'.$options['submit'].'\'}.serialize()'; |
|---|
| | 244 | elseif (isset($options['with'])) $formData = $options['with']; |
|---|
| | 245 | |
|---|
| | 246 | // build the function |
|---|
| | 247 | $function = "jQuery.ajax({"; |
|---|
| | 248 | $function .= 'type:\''.$method.'\''; |
|---|
| | 249 | $function .= ',dataType:\'' . $dataType . '\''; |
|---|
| | 250 | if (isset($type)) $function .= ',async:'.$type; |
|---|
| | 251 | if (isset($formData)) $function .= ',data:'.$formData; |
|---|
| | 252 | if (isset($update_success) and !isset($callback_success)) $function .= ',success:function(i){jQuery(\''.$update_success.'\').'.$updateMethod.'(i);}'; |
|---|
| | 253 | if (isset($update_failure)) $function .= ',error:function(){'.$update_failure.'}'; |
|---|
| | 254 | if (isset($callback_loading)) $function .= ',beforeSend:function(){'.$callback_loading.'}'; |
|---|
| | 255 | if (isset($callback_complete)) $function .= ',complete:function(request){'.$callback_complete.'}'; |
|---|
| | 256 | if (isset($callback_success)) $function .= ',success:function(request){'.$callback_success.'}'; |
|---|
| | 257 | $function .= ',url:\''.url_for($options['url']).'\''; |
|---|
| | 258 | $function .= '})'; |
|---|
| | 259 | |
|---|
| | 260 | if (isset($options['before'])) |
|---|
| | 261 | { |
|---|
| | 262 | $function = $options['before'].'; '.$function; |
|---|
| | 263 | } |
|---|
| | 264 | if (isset($options['after'])) |
|---|
| | 265 | { |
|---|
| | 266 | $function = $function.'; '.$options['after']; |
|---|
| | 267 | } |
|---|
| | 268 | if (isset($options['condition'])) |
|---|
| | 269 | { |
|---|
| | 270 | $function = 'if ('.$options['condition'].') { '.$function.'; }'; |
|---|
| | 271 | } |
|---|
| | 272 | if (isset($options['confirm'])) |
|---|
| | 273 | { |
|---|
| | 274 | $function = "if (confirm('".escape_javascript($options['confirm'])."')) { $function; }"; |
|---|
| | 275 | if (isset($options['cancel'])) |
|---|
| | 276 | { |
|---|
| | 277 | $function = $function.' else { '.$options['cancel'].' }'; |
|---|
| | 278 | } |
|---|
| | 279 | } |
|---|
| | 280 | |
|---|
| | 281 | return $function; |
|---|
| 310 | | $options = _parse_attributes($options); |
|---|
| 311 | | $options_html = _parse_attributes($options_html); |
|---|
| 312 | | |
|---|
| 313 | | if (!isset($options['with'])) |
|---|
| 314 | | { |
|---|
| 315 | | $options['with'] = 'this.form.serialize()'; |
|---|
| 316 | | } |
|---|
| 317 | | |
|---|
| 318 | | $options_html['type'] = 'button'; |
|---|
| 319 | | $options_html['onclick'] = remote_function($options).'; return false;'; |
|---|
| 320 | | $options_html['name'] = $name; |
|---|
| 321 | | $options_html['value'] = $value; |
|---|
| 322 | | |
|---|
| 323 | | return tag('input', $options_html, false); |
|---|
| | 326 | $options = _parse_attributes($options); |
|---|
| | 327 | $options_html = _parse_attributes($options_html); |
|---|
| | 328 | |
|---|
| | 329 | if (!isset($options['with'])) |
|---|
| | 330 | { |
|---|
| | 331 | $options['with'] = 'this.form.serialize()'; |
|---|
| | 332 | } |
|---|
| | 333 | |
|---|
| | 334 | $options_html['type'] = 'button'; |
|---|
| | 335 | $options_html['onclick'] = remote_function($options).'; return false;'; |
|---|
| | 336 | $options_html['name'] = $name; |
|---|
| | 337 | $options_html['value'] = $value; |
|---|
| | 338 | |
|---|
| | 339 | return tag('input', $options_html, false); |
|---|