| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
function get_callbacks() |
|---|
| 52 |
|
|---|
| 53 |
$callbacks; |
|---|
| 54 |
$callbacks) |
|---|
| 55 |
|
|---|
| 56 |
$callbacks = array_merge(array( |
|---|
| 57 |
'uninitialized', 'loading', 'loaded', 'interactive', 'complete', 'failure', 'success' |
|---|
| 58 |
), range(100, 599)); |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
$callbacks; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
get_ajax_options() |
|---|
| 65 |
|
|---|
| 66 |
$ajax_options; |
|---|
| 67 |
$ajax_options) |
|---|
| 68 |
|
|---|
| 69 |
$ajax_options = array_merge(array( |
|---|
| 70 |
'before', 'after', 'condition', 'url', 'asynchronous', 'method', |
|---|
| 71 |
'insertion', 'position', 'form', 'with', 'update', 'script' |
|---|
| 72 |
), get_callbacks()); |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
$ajax_options; |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
function link_to_function($name, $function, $html_options = array()) |
|---|
| 87 |
|
|---|
| 88 |
$html_options = _parse_attributes($html_options); |
|---|
| 89 |
|
|---|
| 90 |
$html_options['href'] = isset($html_options['href']) ? $html_options['href'] : '#'; |
|---|
| 91 |
$html_options['confirm']) ) |
|---|
| 92 |
|
|---|
| 93 |
$confirm = escape_javascript($html_options['confirm']); |
|---|
| 94 |
$html_options['onclick'] = "if(window.confirm('$confirm')){ $function;}; return false;"; |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
$html_options['onclick'] = $function.'; return false;'; |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
content_tag('a', $name, $html_options); |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
function button_to_function($name, $function, $html_options = array()) |
|---|
| 112 |
|
|---|
| 113 |
$html_options = _parse_attributes($html_options); |
|---|
| 114 |
|
|---|
| 115 |
$html_options['onclick'] = $function.'; return false;'; |
|---|
| 116 |
$html_options['type'] = 'button'; |
|---|
| 117 |
$html_options['value'] = $name; |
|---|
| 118 |
|
|---|
| 119 |
tag('input', $html_options); |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
function button_to_remote($name, $options = array(), $html_options = array()) |
|---|
| 130 |
|
|---|
| 131 |
button_to_function($name, remote_function($options), $html_options); |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
function link_to_remote($name, $options = array(), $html_options = array()) |
|---|
| 231 |
|
|---|
| 232 |
link_to_function($name, remote_function($options), $html_options); |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
function periodically_call_remote($options = array()) |
|---|
| 241 |
|
|---|
| 242 |
$frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|---|
| 243 |
$code = 'new PeriodicalExecuter(function() {'.remote_function($options).'}, '.$frequency.')'; |
|---|
| 244 |
|
|---|
| 245 |
javascript_tag($code); |
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
function form_remote_tag($options = array(), $options_html = array()) |
|---|
| 271 |
|
|---|
| 272 |
$options = _parse_attributes($options); |
|---|
| 273 |
$options_html = _parse_attributes($options_html); |
|---|
| 274 |
|
|---|
| 275 |
$options['form'] = true; |
|---|
| 276 |
|
|---|
| 277 |
$options_html['onsubmit'] = remote_function($options).' return false;'; |
|---|
| 278 |
$options_html['action'] = isset($options_html['action']) ? $options_html['action'] : url_for($options['url']); |
|---|
| 279 |
$options_html['method'] = isset($options_html['method']) ? $options_html['method'] : 'post'; |
|---|
| 280 |
|
|---|
| 281 |
tag('form', $options_html, true); |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
function submit_to_remote($name, $value, $options = array(), $options_html = array()) |
|---|
| 289 |
|
|---|
| 290 |
$options = _parse_attributes($options); |
|---|
| 291 |
$options_html = _parse_attributes($options_html); |
|---|
| 292 |
|
|---|
| 293 |
$options['with'])) |
|---|
| 294 |
|
|---|
| 295 |
$options['with'] = 'Form.serialize(this.form)'; |
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
$options_html['type'] = 'button'; |
|---|
| 299 |
$options_html['onclick'] = remote_function($options).' return false;'; |
|---|
| 300 |
$options_html['name'] = $name; |
|---|
| 301 |
$options_html['value'] = $value; |
|---|
| 302 |
|
|---|
| 303 |
tag('input', $options_html, false); |
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
function submit_image_to_remote($name, $source, $options = array(), $options_html = array()) |
|---|
| 311 |
|
|---|
| 312 |
$options = _parse_attributes($options); |
|---|
| 313 |
$options_html = _parse_attributes($options_html); |
|---|
| 314 |
|
|---|
| 315 |
$options['with'])) |
|---|
| 316 |
|
|---|
| 317 |
$options['with'] = 'Form.serialize(this.form)'; |
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
$options_html['type'] = 'image'; |
|---|
| 321 |
$options_html['onclick'] = remote_function($options).' return false;'; |
|---|
| 322 |
$options_html['name'] = $name; |
|---|
| 323 |
$options_html['src'] = image_path($source); |
|---|
| 324 |
|
|---|
| 325 |
$options_html['alt'])) |
|---|
| 326 |
|
|---|
| 327 |
$path_pos = strrpos($source, '/'); |
|---|
| 328 |
$dot_pos = strrpos($source, '.'); |
|---|
| 329 |
$begin = $path_pos ? $path_pos + 1 : 0; |
|---|
| 330 |
$nb_str = ($dot_pos ? $dot_pos : strlen($source)) - $begin; |
|---|
| 331 |
$options_html['alt'] = ucfirst(substr($source, $begin, $nb_str)); |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
tag('input', $options_html, false); |
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
function update_element_function($element_id, $options = array()) |
|---|
| 382 |
|
|---|
| 383 |
sfContext::getInstance()->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 384 |
|
|---|
| 385 |
$content = escape_javascript(isset($options['content']) ? $options['content'] : ''); |
|---|
| 386 |
|
|---|
| 387 |
$value = isset($options['action']) ? $options['action'] : 'update'; |
|---|
| 388 |
$value) |
|---|
| 389 |
|
|---|
| 390 |
'update': |
|---|
| 391 |
$options['position']) && $options['position']) |
|---|
| 392 |
|
|---|
| 393 |
$javascript_function = "\$('$element_id').insert('$content','".$options['position']."')"; |
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
$javascript_function = "\$('$element_id').update('$content')"; |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
'empty': |
|---|
| 402 |
$javascript_function = "\$('$element_id').innerHTML = ''"; |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
'remove': |
|---|
| 406 |
$javascript_function = "\$('$element_id').remove()"; |
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
sfException('Invalid action, choose one of update, remove, empty.'); |
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
$javascript_function .= ";\n"; |
|---|
| 414 |
|
|---|
| 415 |
$options['binding']) ? $javascript_function.$options['binding'] : $javascript_function); |
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
function evaluate_remote_response() |
|---|
| 424 |
|
|---|
| 425 |
'eval(request.responseText)'; |
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
function remote_function($options) |
|---|
| 439 |
|
|---|
| 440 |
sfContext::getInstance()->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 441 |
|
|---|
| 442 |
$javascript_options = _options_for_ajax($options); |
|---|
| 443 |
|
|---|
| 444 |
$update = ''; |
|---|
| 445 |
$options['update']) && is_array($options['update'])) |
|---|
| 446 |
|
|---|
| 447 |
$update = array(); |
|---|
| 448 |
$options['update']['success'])) |
|---|
| 449 |
|
|---|
| 450 |
$update[] = "success:'".$options['update']['success']."'"; |
|---|
| 451 |
|
|---|
| 452 |
$options['update']['failure'])) |
|---|
| 453 |
|
|---|
| 454 |
$update[] = "failure:'".$options['update']['failure']."'"; |
|---|
| 455 |
|
|---|
| 456 |
$update = '{'.join(',', $update).'}'; |
|---|
| 457 |
|
|---|
| 458 |
$options['update'])) |
|---|
| 459 |
|
|---|
| 460 |
$update .= "'".$options['update']."'"; |
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
$function = !$update ? "new Ajax.Request(" : "new Ajax.Updater($update, "; |
|---|
| 464 |
|
|---|
| 465 |
$function .= '\''.url_for($options['url']).'\''; |
|---|
| 466 |
$function .= ', '.$javascript_options.')'; |
|---|
| 467 |
|
|---|
| 468 |
$options['before'])) |
|---|
| 469 |
|
|---|
| 470 |
$function = $options['before'].'; '.$function; |
|---|
| 471 |
|
|---|
| 472 |
$options['after'])) |
|---|
| 473 |
|
|---|
| 474 |
$function = $function.'; '.$options['after']; |
|---|
| 475 |
|
|---|
| 476 |
$options['condition'])) |
|---|
| 477 |
|
|---|
| 478 |
$function = 'if ('.$options['condition'].') { '.$function.'; }'; |
|---|
| 479 |
|
|---|
| 480 |
$options['confirm'])) |
|---|
| 481 |
|
|---|
| 482 |
$function = "if (confirm('".escape_javascript($options['confirm'])."')) { $function; }"; |
|---|
| 483 |
$options['cancel'])) |
|---|
| 484 |
|
|---|
| 485 |
$function = $function.' else { '.$options['cancel'].' }'; |
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
$function.';'; |
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
function observe_field($field_id, $options = array()) |
|---|
| 518 |
|
|---|
| 519 |
sfContext::getInstance()->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 520 |
|
|---|
| 521 |
$options['frequency']) && $options['frequency'] > 0) |
|---|
| 522 |
|
|---|
| 523 |
_build_observer('Form.Element.Observer', $field_id, $options); |
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
_build_observer('Form.Element.EventObserver', $field_id, $options); |
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
function observe_form($form_id, $options = array()) |
|---|
| 538 |
|
|---|
| 539 |
sfContext::getInstance()->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 540 |
|
|---|
| 541 |
$options['frequency']) && $options['frequency'] > 0) |
|---|
| 542 |
|
|---|
| 543 |
_build_observer('Form.Observer', $form_id, $options); |
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
_build_observer('Form.EventObserver', $form_id, $options); |
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
function visual_effect($name, $element_id = false, $js_options = array()) |
|---|
| 577 |
|
|---|
| 578 |
$response = sfContext::getInstance()->getResponse(); |
|---|
| 579 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 580 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/builder'); |
|---|
| 581 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| 582 |
|
|---|
| 583 |
$element = $element_id ? "'$element_id'" : 'element'; |
|---|
| 584 |
|
|---|
| 585 |
in_array($name, array('toggle_appear', 'toggle_blind', 'toggle_slide'))) |
|---|
| 586 |
|
|---|
| 587 |
"new Effect.toggle($element, '".substr($name, 7)."', "._options_for_javascript($js_options).");"; |
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
"new Effect.".sfInflector::camelize($name)."($element, "._options_for_javascript($js_options).");"; |
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
|
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
function sortable_element($element_id, $options = array()) |
|---|
| 614 |
|
|---|
| 615 |
$response = sfContext::getInstance()->getResponse(); |
|---|
| 616 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 617 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/builder'); |
|---|
| 618 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| 619 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/dragdrop'); |
|---|
| 620 |
|
|---|
| 621 |
$options['with'])) |
|---|
| 622 |
|
|---|
| 623 |
$options['with'] = "Sortable.serialize('$element_id')"; |
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
$options['onUpdate']) && isset($options['url'])) |
|---|
| 627 |
|
|---|
| 628 |
$options['onUpdate'] = "function(){".remote_function($options)."}"; |
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 |
get_ajax_options() as $key) |
|---|
| 632 |
|
|---|
| 633 |
$options[$key]); |
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
'tag', 'overlap', 'constraint', 'handle') as $option) |
|---|
| 637 |
|
|---|
| 638 |
$options[$option])) |
|---|
| 639 |
|
|---|
| 640 |
$options[$option] = "'{$options[$option]}'"; |
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
$options['containment'])) |
|---|
| 645 |
|
|---|
| 646 |
$options['containment'] = _array_or_string_for_javascript($options['containment']); |
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
$options['hoverclass'])) |
|---|
| 650 |
|
|---|
| 651 |
$options['hoverclass'] = "'{$options['hoverclass']}'"; |
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
$options['only'])) |
|---|
| 655 |
|
|---|
| 656 |
$options['only'] = _array_or_string_for_javascript($options['only']); |
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
$scrollPosition = ""; |
|---|
| 660 |
$options['scroll'])) |
|---|
| 661 |
|
|---|
| 662 |
$options['scroll'] = _array_or_string_for_javascript($options['scroll']); |
|---|
| 663 |
$scrollPosition = "Position.includeScrollOffsets = true;"; |
|---|
| 664 |
|
|---|
| 665 |
|
|---|
| 666 |
javascript_tag($scrollPosition."Sortable.create('$element_id', "._options_for_javascript($options).")"); |
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
|
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
|
|---|
| 680 |
function draggable_element($element_id, $options = array()) |
|---|
| 681 |
|
|---|
| 682 |
$response = sfContext::getInstance()->getResponse(); |
|---|
| 683 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 684 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/builder'); |
|---|
| 685 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| 686 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/dragdrop'); |
|---|
| 687 |
|
|---|
| 688 |
javascript_tag("new Draggable('$element_id', "._options_for_javascript($options).")"); |
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
function drop_receiving_element($element_id, $options = array()) |
|---|
| 705 |
|
|---|
| 706 |
$response = sfContext::getInstance()->getResponse(); |
|---|
| 707 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 708 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/builder'); |
|---|
| 709 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| 710 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/dragdrop'); |
|---|
| 711 |
|
|---|
| 712 |
$options['with'])) |
|---|
| 713 |
|
|---|
| 714 |
$options['with'] = "'id=' + encodeURIComponent(element.id)"; |
|---|
| 715 |
|
|---|
| 716 |
$options['onDrop'])) |
|---|
| 717 |
|
|---|
| 718 |
$options['onDrop'] = "function(element){".remote_function($options)."}"; |
|---|
| 719 |
|
|---|
| 720 |
|
|---|
| 721 |
get_ajax_options() as $key) |
|---|
| 722 |
|
|---|
| 723 |
$options[$key]); |
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
$options['accept'])) |
|---|
| 727 |
|
|---|
| 728 |
$options['accept'] = _array_or_string_for_javascript($options['accept']); |
|---|
| 729 |
|
|---|
| 730 |
|
|---|
| 731 |
$options['hoverclass'])) |
|---|
| 732 |
|
|---|
| 733 |
$options['hoverclass'] = "'{$options['hoverclass']}'"; |
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
javascript_tag("Droppables.add('$element_id', "._options_for_javascript($options).")"); |
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
function javascript_tag($content) |
|---|
| 746 |
|
|---|
| 747 |
content_tag('script', javascript_cdata_section($content), array('type' => 'text/javascript')); |
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
javascript_cdata_section($content) |
|---|
| 751 |
|
|---|
| 752 |
"\n//".cdata_section("\n$content\n//")."\n"; |
|---|
| 753 |
|
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
|
|---|
| 757 |
|
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 |
|
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 |
function input_auto_complete_tag($name, $value, $url, $tag_options = array(), $completion_options = array()) |
|---|
| 766 |
|
|---|
| 767 |
$context = sfContext::getInstance(); |
|---|
| 768 |
|
|---|
| 769 |
$tag_options = _convert_options($tag_options); |
|---|
| 770 |
|
|---|
| 771 |
$response = $context->getResponse(); |
|---|
| 772 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 773 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| 774 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/controls'); |
|---|
| 775 |
|
|---|
| 776 |
$comp_options = _convert_options($completion_options); |
|---|
| 777 |
$comp_options['use_style']) && $comp_options['use_style'] == true) |
|---|
| 778 |
|
|---|
| 779 |
$response->addStylesheet(sfConfig::get('sf_prototype_web_dir').'/css/input_auto_complete_tag'); |
|---|
| 780 |
|
|---|
| 781 |
|
|---|
| 782 |
$tag_options['id'] = get_id_from_name(isset($tag_options['id']) ? $tag_options['id'] : $name); |
|---|
| 783 |
|
|---|
| 784 |
$javascript = tag('input', array_merge(array('type' => 'text', 'name' => $name, 'value' => $value), _convert_options($tag_options))); |
|---|
| 785 |
$javascript .= content_tag('div', '' , array('id' => $tag_options['id'].'_auto_complete', 'class' => 'auto_complete')); |
|---|
| 786 |
$javascript .= _auto_complete_field($tag_options['id'], $url, $comp_options); |
|---|
| 787 |
|
|---|
| 788 |
$javascript; |
|---|
| 789 |
|
|---|
| 790 |
|
|---|
| 791 |
|
|---|
| 792 |
|
|---|
| 793 |
|
|---|
| 794 |
|
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
|
|---|
| 798 |
|
|---|
| 799 |
function input_in_place_editor_tag($name, $url, $editor_options = array()) |
|---|
| 800 |
|
|---|
| 801 |
$response = sfContext::getInstance()->getResponse(); |
|---|
| 802 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 803 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/effects'); |
|---|
| 804 |
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/controls'); |
|---|
| 805 |
|
|---|
| 806 |
$editor_options = _convert_options($editor_options); |
|---|
| 807 |
_in_place_editor($name, $url, $editor_options); |
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 812 |
|
|---|
| 813 |
|
|---|
| 814 |
function if_javascript() |
|---|
| 815 |
|
|---|
| 816 |
ob_start(); |
|---|
| 817 |
|
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 |
|
|---|
| 822 |
|
|---|
| 823 |
function end_if_javascript() |
|---|
| 824 |
|
|---|
| 825 |
$content = ob_get_clean(); |
|---|
| 826 |
|
|---|
| 827 |
javascript_tag("document.write('" . esc_js_no_entities($content) . "');"); |
|---|
| 828 |
|
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 |
|
|---|
| 832 |
|
|---|
| 833 |
|
|---|
| 834 |
|
|---|
| 835 |
|
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
|
|---|
| 845 |
|
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
|
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
|
|---|
| 861 |
|
|---|
| 862 |
function _in_place_editor($field_id, $url, $options = array()) |
|---|
| 863 |
|
|---|
| 864 |
$javascript = "new Ajax.InPlaceEditor("; |
|---|
| 865 |
|
|---|
| 866 |
$javascript .= "'$field_id', "; |
|---|
| 867 |
$javascript .= _array_or_string_for_javascript(url_for($url)); |
|---|
| 868 |
|
|---|
| 869 |
|
|---|
| 870 |
if (isset($options['cancel_text'])) |
|---|
| 871 |
|
|---|
| 872 |
$options['cancelText'] = _array_or_string_for_javascript($options['cancel_text']); |
|---|
| 873 |
$options['cancel_text']); |
|---|
| 874 |
|
|---|
| 875 |
$options['save_text'])) |
|---|
| 876 |
|
|---|
| 877 |
$options['okText'] = _array_or_string_for_javascript($options['save_text']); |
|---|
| 878 |
$options['save_text']); |
|---|
| 879 |
|
|---|
| 880 |
$options['external_control'])) |
|---|
| 881 |
|
|---|
| 882 |
$options['externalControl'] = _array_or_string_for_javascript($options['external_control']); |
|---|
| 883 |
$options['external_control']); |
|---|
| 884 |
|
|---|
| 885 |
$options['options'])) |
|---|
| 886 |
|
|---|
| 887 |
$options['ajaxOptions'] = $options['options']; |
|---|
| 888 |
$options['options']); |
|---|
| 889 |
|
|---|
| 890 |
$options['with'])) |
|---|
| 891 |
|
|---|
| 892 |
$options['callback'] = "function(form, value) { return ".$options['with']." }"; |
|---|
| 893 |
$options['with']); |
|---|
| 894 |
|
|---|
| 895 |
$options['highlightcolor'])) |
|---|
| 896 |
|
|---|
| 897 |
$options['highlightColor'] = _array_or_string_for_javascript($options['highlightcolor']); |
|---|
| 898 |
$options['highlightcolor']); |
|---|
| 899 |
|
|---|
| 900 |
$options['highlightendcolor'])) |
|---|
| 901 |
|
|---|
| 902 |
$options['highlightEndColor'] = _array_or_string_for_javascript($options['highlightendcolor']); |
|---|
| 903 |
$options['highlightendcolor']); |
|---|
| 904 |
|
|---|
| 905 |
$options['loadTextURL'])) |
|---|
| 906 |
|
|---|
| 907 |
$options['loadTextURL'] = _array_or_string_for_javascript($options['loadTextURL']); |
|---|
| 908 |
|
|---|
| 909 |
|
|---|
| 910 |
$javascript .= ', '._options_for_javascript($options); |
|---|
| 911 |
$javascript .= ');'; |
|---|
| 912 |
|
|---|
| 913 |
javascript_tag($javascript); |
|---|
| 914 |
|
|---|
| 915 |
|
|---|
| 916 |
|
|---|
| 917 |
|
|---|
| 918 |
|
|---|
| 919 |
|
|---|
| 920 |
|
|---|
| 921 |
|
|---|
| 922 |
|
|---|
| 923 |
function _auto_complete_field($field_id, $url, $options = array()) |
|---|
| 924 |
|
|---|
| 925 |
$javascript = "new Ajax.Autocompleter("; |
|---|
| 926 |
|
|---|
| 927 |
$javascript .= "'".get_id_from_name($field_id)."', "; |
|---|
| 928 |
$options['update'])) |
|---|
| 929 |
|
|---|
| 930 |
$javascript .= "'".$options['update']."', "; |
|---|
| 931 |
|
|---|
| 932 |
|
|---|
| 933 |
|
|---|
| 934 |
$javascript .= "'".get_id_from_name($field_id)."_auto_complete', "; |
|---|
| 935 |
|
|---|
| 936 |
|
|---|
| 937 |
$javascript .= _array_or_string_for_javascript(url_for($url)); |
|---|
| 938 |
|
|---|
| 939 |
$js_options = array(); |
|---|
| 940 |
$options['tokens'])) |
|---|
| 941 |
|
|---|
| 942 |
$js_options['tokens'] = _array_or_string_for_javascript($options['tokens']); |
|---|
| 943 |
|
|---|
| 944 |
$options['with'])) |
|---|
| 945 |
|
|---|
| 946 |
$js_options['callback'] = "function(element, value) { return ".$options['with']."}"; |
|---|
| 947 |
|
|---|
| 948 |
$options['indicator'])) |
|---|
| 949 |
|
|---|
| 950 |
$js_options['indicator'] = _array_or_string_for_javascript($options['indicator']); |
|---|
| 951 |
|
|---|
| 952 |
$options['on_show'])) |
|---|
| 953 |
|
|---|
| 954 |
$js_options['onShow'] = $options['on_show']; |
|---|
| 955 |
|
|---|
| 956 |
$options['on_hide'])) |
|---|
| 957 |
|
|---|
| 958 |
$js_options['onHide'] = $options['on_hide']; |
|---|
| 959 |
|
|---|
| 960 |
$options['min_chars'])) |
|---|
| 961 |
|
|---|
| 962 |
$js_options['minChars'] = $options['min_chars']; |
|---|
| 963 |
|
|---|
| 964 |
$options['frequency'])) |
|---|
| 965 |
|
|---|
| 966 |
$js_options['frequency'] = $options['frequency']; |
|---|
| 967 |
|
|---|
| 968 |
$options['update_element'])) |
|---|
| 969 |
|
|---|
| 970 |
$js_options['updateElement'] = $options['update_element']; |
|---|
| 971 |
|
|---|
| 972 |
$options['after_update_element'])) |
|---|
| 973 |
|
|---|
| 974 |
$js_options['afterUpdateElement'] = $options['after_update_element']; |
|---|
| 975 |
|
|---|
| 976 |
$options['param_name'])) |
|---|
| 977 |
|
|---|
| 978 |
$js_options['paramName'] = "'".$options['param_name']."'"; |
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 |
$javascript .= ', '._options_for_javascript($js_options).');'; |
|---|
| 982 |
|
|---|
| 983 |
javascript_tag($javascript); |
|---|
| 984 |
|
|---|
| 985 |
|
|---|
| 986 |
_options_for_javascript($options) |
|---|
| 987 |
|
|---|
| 988 |
$opts = array(); |
|---|
| 989 |
$options as $key => $value) |
|---|
| 990 |
|
|---|
| 991 |
$opts[] = $key.":"._boolean_for_javascript($value); |
|---|
| 992 |
|
|---|
| 993 |
sort($opts); |
|---|
| 994 |
|
|---|
| 995 |
'{'.join(', ', $opts).'}'; |
|---|
| 996 |
|
|---|
| 997 |
|
|---|
| 998 |
|
|---|
| 999 |
|
|---|
| 1000 |
|
|---|
| 1001 |
|
|---|
| 1002 |
|
|---|
| 1003 |
|
|---|
| 1004 |
|
|---|
| 1005 |
function _array_or_string_for_javascript($option) |
|---|
| 1006 |
|
|---|
| 1007 |
is_array($option)) |
|---|
| 1008 |
|
|---|
| 1009 |
"['".join('\',\'', $option)."']"; |
|---|
| 1010 |
|
|---|
| 1011 |
is_string($option) && $option[0] != "'") |
|---|
| 1012 |
|
|---|
| 1013 |
"'$option'"; |
|---|
| 1014 |
|
|---|
| 1015 |
$option; |
|---|
| 1016 |
|
|---|
| 1017 |
|
|---|
| 1018 |
|
|---|
| 1019 |
|
|---|
| 1020 |
|
|---|
| 1021 |
|
|---|
| 1022 |
|
|---|
| 1023 |
|
|---|
| 1024 |
|
|---|
| 1025 |
function _boolean_for_javascript($bool) |
|---|
| 1026 |
|
|---|
| 1027 |
is_bool($bool)) |
|---|
| 1028 |
|
|---|
| 1029 |
$bool===true ? 'true' : 'false'); |
|---|
| 1030 |
|
|---|
| 1031 |
$bool; |
|---|
| 1032 |
|
|---|
| 1033 |
|
|---|
| 1034 |
_options_for_ajax($options) |
|---|
| 1035 |
|
|---|
| 1036 |
$js_options = _build_callbacks($options); |
|---|
| 1037 |
|
|---|
| 1038 |
$js_options['asynchronous'] = (isset($options['type']) && ($options['type'] == 'synchronous')) ? false : true; |
|---|
| 1039 |
$options['method'])) $js_options['method'] = _array_or_string_for_javascript($options['method']); |
|---|
| 1040 |
$options['position'])) $js_options['insertion'] = "Insertion.".sfInflector::camelize($options['position']); |
|---|
| 1041 |
$js_options['evalScripts'] = (!isset($options['script']) || $options['script'] == '0' || $options['script'] == false) ? false : true; |
|---|
| 1042 |
|
|---|
| 1043 |
$options['form'])) |
|---|
| 1044 |
|
|---|
| 1045 |
$js_options['parameters'] = 'Form.serialize(this)'; |
|---|
| 1046 |
|
|---|
| 1047 |
$options['submit'])) |
|---|
| 1048 |
|
|---|
| 1049 |
$js_options['parameters'] = "Form.serialize(document.getElementById('{$options['submit']}'))"; |
|---|
| 1050 |
|
|---|
| 1051 |
$options['with'])) |
|---|
| 1052 |
|
|---|
| 1053 |
$js_options['parameters'] = $options['with']; |
|---|
| 1054 |
|
|---|
| 1055 |
|
|---|
| 1056 |
_options_for_javascript($js_options); |
|---|
| 1057 |
|
|---|
| 1058 |
|
|---|
| 1059 |
_build_observer($klass, $name, $options = array()) |
|---|
| 1060 |
|
|---|
| 1061 |
$options['with']) && isset($options['update'])) |
|---|
| 1062 |
|
|---|
| 1063 |
$options['with'] = 'value'; |
|---|
| 1064 |
|
|---|
| 1065 |
|
|---|
| 1066 |
$callback = remote_function($options); |
|---|
| 1067 |
|
|---|
| 1068 |
$javascript = 'new '.$klass.'("'.$name.'", '; |
|---|
| 1069 |
$options['frequency']) && $options['frequency'] > 0) |
|---|
| 1070 |
|
|---|
| 1071 |
$javascript .= $options['frequency'].", "; |
|---|
| 1072 |
|
|---|
| 1073 |
$javascript .= "function(element, value) {"; |
|---|
| 1074 |
$javascript .= $callback.'});'; |
|---|
| 1075 |
|
|---|
| 1076 |
javascript_tag($javascript); |
|---|
| 1077 |
|
|---|
| 1078 |
|
|---|
| 1079 |
_build_callbacks($options) |
|---|
| 1080 |
|
|---|
| 1081 |
$callbacks = array(); |
|---|
| 1082 |
get_callbacks() as $callback) |
|---|
| 1083 |
|
|---|
| 1084 |
$options[$callback])) |
|---|
| 1085 |
|
|---|
| 1086 |
$name = 'on'.ucfirst($callback); |
|---|
| 1087 |
$code = $options[$callback]; |
|---|
| 1088 |
$callbacks[$name] = 'function(request, json){'.$code.'}'; |
|---|
| 1089 |
|
|---|
| 1090 |
|
|---|
| 1091 |
|
|---|
| 1092 |
$callbacks; |
|---|
| 1093 |
|
|---|
| 1094 |
|
|---|