2005-06-21 23:44:49 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-06-21 23:44:49 +00:00
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-07 01:52:45 +00:00
|
|
|
* Helper for AJAX operations.
|
2005-08-22 04:15:57 +00:00
|
|
|
*
|
2005-09-07 01:52:45 +00:00
|
|
|
* Helps doing AJAX using the Prototype library.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
2006-01-20 07:46:14 +00:00
|
|
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
2005-12-23 21:57:26 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-08-22 04:15:57 +00:00
|
|
|
* @filesource
|
2006-01-20 07:46:14 +00:00
|
|
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
2005-12-23 21:57:26 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
|
|
* @since CakePHP v 0.10.0.1076
|
2005-08-21 06:49:02 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-21 06:49:02 +00:00
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
|
|
|
* AjaxHelper helper library.
|
2005-08-22 04:15:57 +00:00
|
|
|
*
|
2005-09-07 01:52:45 +00:00
|
|
|
* Helps doing AJAX using the Prototype library.
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
|
|
* @since CakePHP v 0.10.0.1076
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-08-21 20:01:32 +00:00
|
|
|
class AjaxHelper extends Helper
|
2005-06-21 23:44:49 +00:00
|
|
|
{
|
2005-08-21 20:01:32 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Included helpers.
|
|
|
|
*
|
|
|
|
* @var array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
[1210]
Author: phpnut
Date: 4:44:45 AM, Wednesday, October 26, 2005
Message:
AJAX is now available as a by default in the $html variable in the templates.
You access it like this:
$html->Ajax->xxx();
Updated default templates.
[1208]
Author: phpnut
Date: 6:49:26 PM, Tuesday, October 25, 2005
Message:
Adding fix in Controller::generateFieldNames();
[1203]
Author: phpnut
Date: 10:40:28 AM, Tuesday, October 25, 2005
Message:
Changes made to core templates and css.
Fixed added for Ticket #60
[1202]
Author: phpnut
Date: 2:30:58 AM, Tuesday, October 25, 2005
Message:
Fix for cake error templates
Fixed a key for tables that are underscored in scaffolded code.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1211 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-26 10:55:44 +00:00
|
|
|
var $helpers = array('Html', 'Javascript');
|
2005-09-19 17:20:24 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Names of Javascript callback functions.
|
|
|
|
*
|
|
|
|
* @var array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
var $callbacks = array('uninitialized', 'loading', 'loaded', 'interactive', 'complete');
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Names of AJAX options.
|
|
|
|
*
|
|
|
|
* @var array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-02-28 07:35:01 +00:00
|
|
|
var $ajaxOptions = array('type', 'confirm', 'condition', 'before', 'after', 'fallback', 'update', 'loading', 'loaded', 'interactive', 'complete', 'with', 'url', 'method', 'position', 'form', 'parameters', 'evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive', 'insertion');
|
2005-09-19 17:20:24 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Options for draggable.
|
|
|
|
*
|
|
|
|
* @var array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
var $dragOptions = array('handle', 'revert', 'constraint', 'change');
|
2006-01-12 02:10:47 +00:00
|
|
|
|
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Options for droppable.
|
|
|
|
*
|
|
|
|
* @var array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
var $dropOptions = array('accept', 'containment', 'overlap', 'greedy', 'hoverclass', 'onHover', 'onDrop');
|
2006-01-12 02:10:47 +00:00
|
|
|
|
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Options for sortable.
|
|
|
|
*
|
|
|
|
* @var array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
var $sortOptions = array('tag', 'only', 'overlap', 'constraint', 'containment', 'handle', 'hoverClass', 'ghosting', 'dropOnEmpty', 'onUpdate', 'onChange');
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2006-02-07 02:19:53 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Options for slider.
|
|
|
|
*
|
|
|
|
* @var array
|
2006-02-07 02:19:53 +00:00
|
|
|
*/
|
2006-02-08 15:25:34 +00:00
|
|
|
var $sliderOptions = array('axis', 'increment', 'maximum', 'minimum', 'alignX', 'alignY', 'sliderValue', 'disabled', 'handleImage', 'handleDisabled', 'values', 'onSlide', 'onChange');
|
|
|
|
|
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Options for in-place editor.
|
|
|
|
*
|
|
|
|
* @var array
|
2006-02-08 15:25:34 +00:00
|
|
|
*/
|
2006-02-19 22:14:21 +00:00
|
|
|
var $editorOptions = array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'rows', 'cols', 'size', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'callback', 'ajaxOptions', 'clickToEditText');
|
2006-02-07 02:19:53 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2005-12-27 03:33:44 +00:00
|
|
|
* Returns link to remote action
|
|
|
|
*
|
|
|
|
* Returns a link to a remote action defined by <i>options[url]</i>
|
|
|
|
* (using the urlFor format) that's called in the background using
|
|
|
|
* XMLHttpRequest. The result of that request can then be inserted into a
|
|
|
|
* DOM object whose id can be specified with <i>options[update]</i>.
|
|
|
|
* Usually, the result would be a partial prepared by the controller with
|
|
|
|
* either renderPartial or renderPartialCollection.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* <code>
|
2006-01-12 04:08:19 +00:00
|
|
|
* link("Delete this post",
|
2005-12-27 03:33:44 +00:00
|
|
|
* array("update" => "posts", "url" => "delete/{$postid->id}"));
|
2006-01-12 04:08:19 +00:00
|
|
|
* link(imageTag("refresh"),
|
2005-12-27 03:33:44 +00:00
|
|
|
* array("update" => "emails", "url" => "list_emails" ));
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* By default, these remote requests are processed asynchronous during
|
|
|
|
* which various callbacks can be triggered (for progress indicators and
|
|
|
|
* the likes).
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* <code>
|
2006-02-18 23:42:21 +00:00
|
|
|
* link (word,
|
|
|
|
* array("url" => "undo", "n" => word_counter),
|
|
|
|
* array("complete" => "undoRequestCompleted(request)"));
|
2005-12-27 03:33:44 +00:00
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* The callbacks that may be specified are:
|
|
|
|
*
|
2006-02-18 23:42:21 +00:00
|
|
|
* - <i>loading</i>:: Called when the remote document is being
|
|
|
|
* loaded with data by the browser.
|
2005-12-27 03:33:44 +00:00
|
|
|
* - <i>loaded</i>:: Called when the browser has finished loading
|
2006-02-18 23:42:21 +00:00
|
|
|
* the remote document.
|
|
|
|
* - <i>interactive</i>:: Called when the user can interact with the
|
|
|
|
* remote document, even though it has not
|
|
|
|
* finished loading.
|
2005-12-27 03:33:44 +00:00
|
|
|
* - <i>complete</i>:: Called when the XMLHttpRequest is complete.
|
|
|
|
*
|
|
|
|
* If you for some reason or another need synchronous processing (that'll
|
|
|
|
* block the browser while the request is happening), you can specify
|
|
|
|
* <i>options[type] = synchronous</i>.
|
|
|
|
*
|
|
|
|
* You can customize further browser side call logic by passing
|
|
|
|
* in Javascript code snippets via some optional parameters. In
|
|
|
|
* their order of use these are:
|
|
|
|
*
|
|
|
|
* - <i>confirm</i>:: Adds confirmation dialog.
|
|
|
|
* -<i>condition</i>:: Perform remote request conditionally
|
|
|
|
* by this expression. Use this to
|
|
|
|
* describe browser-side conditions when
|
|
|
|
* request should not be initiated.
|
2006-02-18 23:42:21 +00:00
|
|
|
* - <i>before</i>:: Called before request is initiated.
|
2005-12-27 03:33:44 +00:00
|
|
|
* - <i>after</i>:: Called immediately after request was
|
2006-02-18 23:42:21 +00:00
|
|
|
* initiated and before <i>loading</i>.
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
|
|
|
* @param string $title Title of link
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param string $href Href string "/products/view/12"
|
|
|
|
* @param array $options Options for JavaScript function
|
2006-02-18 23:42:21 +00:00
|
|
|
* @param string $confirm Confirmation message. Calls up a JavaScript confirm() message.
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param boolean $escapeTitle Escaping the title string to HTML entities
|
|
|
|
*
|
2006-02-18 23:42:21 +00:00
|
|
|
* @return string HTML code for link to remote action
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-02-01 13:26:23 +00:00
|
|
|
function link($title, $href = null, $options = array(), $confirm = null, $escapeTitle = true)
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-12 04:08:19 +00:00
|
|
|
if (!isset($href))
|
|
|
|
{
|
|
|
|
$href = $title;
|
|
|
|
}
|
|
|
|
|
2006-01-25 22:40:17 +00:00
|
|
|
if (!isset($options['url']))
|
|
|
|
{
|
|
|
|
$options['url'] = $href;
|
|
|
|
}
|
|
|
|
|
2006-01-12 04:08:19 +00:00
|
|
|
if (isset($confirm))
|
|
|
|
{
|
|
|
|
$options['confirm'] = $confirm;
|
|
|
|
unset($confirm);
|
|
|
|
}
|
|
|
|
|
|
|
|
$htmlOptions = $this->__getHtmlOptions($options);
|
|
|
|
if (empty($options['fallback']) || !isset($options['fallback']))
|
|
|
|
{
|
|
|
|
$options['fallback'] = $href;
|
|
|
|
}
|
|
|
|
if (isset($options['id']))
|
|
|
|
{
|
|
|
|
$htmlOptions['onclick'] = ' return false;';
|
2006-02-17 10:12:15 +00:00
|
|
|
return $this->Html->link($title, $href, $htmlOptions) . $this->Javascript->event("$('{$options['id']}')", "click", $this->remoteFunction($options));
|
2006-01-12 04:08:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$htmlOptions['onclick'] = $this->remoteFunction($options) . '; return false;';
|
2006-02-01 13:26:23 +00:00
|
|
|
return $this->Html->link($title, $href, $htmlOptions, null, $escapeTitle);
|
2006-01-12 04:08:19 +00:00
|
|
|
}
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 04:08:19 +00:00
|
|
|
function linkToRemote ($title, $options = array(), $html_options = array())
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
//trigger_error('Deprecated function: use AjaxHelper::link', E_USER_WARNING);
|
2006-01-12 04:08:19 +00:00
|
|
|
$href = '#';
|
|
|
|
if (!empty($options['fallback']) && isset($options['fallback']))
|
|
|
|
{
|
|
|
|
$href = $options['fallback'];
|
|
|
|
}
|
|
|
|
if (isset($html_options['id']))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
return $this->Html->link($title, $href, $html_options) . $this->Javascript->event("$('{$html_options['id']}')", "click", $this->remoteFunction($options));
|
2006-01-12 04:08:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-01 13:26:23 +00:00
|
|
|
$html_options['onclick'] = $this->remoteFunction($options) . "; return false;";
|
2006-01-12 04:08:19 +00:00
|
|
|
return $this->Html->link($title, $href, $html_options);
|
|
|
|
}
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* 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 linkToRemote.
|
|
|
|
*
|
|
|
|
* @see linkToRemote() for docs on options parameter.
|
|
|
|
*
|
|
|
|
* @param array $options options for javascript
|
|
|
|
* @return string html code for link to remote action
|
|
|
|
*/
|
2006-01-12 02:10:47 +00:00
|
|
|
function remoteFunction ($options = null)
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-12 04:08:19 +00:00
|
|
|
$javascript_options = $this->__optionsForAjax($options);
|
2005-09-19 17:20:24 +00:00
|
|
|
$func = isset($options['update']) ? "new Ajax.Updater('{$options['update']}'," : "new Ajax.Request(";
|
|
|
|
|
[1210]
Author: phpnut
Date: 4:44:45 AM, Wednesday, October 26, 2005
Message:
AJAX is now available as a by default in the $html variable in the templates.
You access it like this:
$html->Ajax->xxx();
Updated default templates.
[1208]
Author: phpnut
Date: 6:49:26 PM, Tuesday, October 25, 2005
Message:
Adding fix in Controller::generateFieldNames();
[1203]
Author: phpnut
Date: 10:40:28 AM, Tuesday, October 25, 2005
Message:
Changes made to core templates and css.
Fixed added for Ticket #60
[1202]
Author: phpnut
Date: 2:30:58 AM, Tuesday, October 25, 2005
Message:
Fix for cake error templates
Fixed a key for tables that are underscored in scaffolded code.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1211 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-26 10:55:44 +00:00
|
|
|
$func .= "'" . $this->Html->url(isset($options['url']) ? $options['url'] : "") . "'";
|
2006-02-08 15:25:34 +00:00
|
|
|
$func .= ", $javascript_options)";
|
2005-09-19 17:20:24 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
if (isset($options['before']))
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-22 05:12:28 +00:00
|
|
|
$func = "{$options['before']}; $func";
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
if (isset($options['after']))
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2005-09-21 05:48:09 +00:00
|
|
|
$func = "$func; {$options['after']};";
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
if (isset($options['condition']))
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
$func = "if ({$options['condition']}) { $func; }";
|
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
if (isset($options['confirm']))
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-12 04:08:19 +00:00
|
|
|
$func = "if (confirm('" . $this->Javascript->escapeString($options['confirm']) . "')) { $func; } else { return false; }";
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
return $func;
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Periodically call remote url via AJAX.
|
|
|
|
*
|
|
|
|
* Periodically calls the specified url (<i>options[url]</i>) every <i>options[frequency]</i> seconds (default is 10).
|
|
|
|
* Usually used to update a specified div (<i>options[update]</i>) with the results of the remote call.
|
|
|
|
* The options for specifying the target with url and defining callbacks is the same as linkToRemote.
|
|
|
|
*
|
|
|
|
* @param array $options Callback options
|
|
|
|
* @return string Javascript code
|
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function remoteTimer ($options = null)
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
$frequency = (isset($options['frequency']))? $options['frequency'] : 10;
|
2006-01-12 04:08:19 +00:00
|
|
|
$code = "new PeriodicalExecuter(function() {" . $this->remoteFunction($options) . "}, $frequency)";
|
[1210]
Author: phpnut
Date: 4:44:45 AM, Wednesday, October 26, 2005
Message:
AJAX is now available as a by default in the $html variable in the templates.
You access it like this:
$html->Ajax->xxx();
Updated default templates.
[1208]
Author: phpnut
Date: 6:49:26 PM, Tuesday, October 25, 2005
Message:
Adding fix in Controller::generateFieldNames();
[1203]
Author: phpnut
Date: 10:40:28 AM, Tuesday, October 25, 2005
Message:
Changes made to core templates and css.
Fixed added for Ticket #60
[1202]
Author: phpnut
Date: 2:30:58 AM, Tuesday, October 25, 2005
Message:
Fix for cake error templates
Fixed a key for tables that are underscored in scaffolded code.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1211 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-26 10:55:44 +00:00
|
|
|
return $this->Javascript->codeBlock($code);
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Returns form tag that will submit using Ajax.
|
|
|
|
*
|
|
|
|
* Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular
|
|
|
|
* reloading POST arrangement. Even though it's using Javascript to serialize the form elements, the form submission
|
|
|
|
* will work just like a regular submission as viewed by the receiving side (all elements available in params).
|
|
|
|
* The options for specifying the target with :url and defining callbacks is the same as link_to_remote.
|
|
|
|
*
|
|
|
|
* @param array $params Form id
|
|
|
|
* @param array $type How form data is posted: 'get' or 'post'
|
|
|
|
* @param array $options Callback/HTML options
|
|
|
|
* @return string JavaScript/HTML code
|
|
|
|
*/
|
2006-01-18 04:38:21 +00:00
|
|
|
function form($params = null, $type = 'post', $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-18 04:38:21 +00:00
|
|
|
if (is_array($params))
|
|
|
|
{
|
|
|
|
extract($params, EXTR_OVERWRITE);
|
|
|
|
if (!isset($action))
|
|
|
|
{
|
|
|
|
$action = null;
|
|
|
|
}
|
|
|
|
if (!isset($type))
|
|
|
|
{
|
|
|
|
$type = 'post';
|
|
|
|
}
|
|
|
|
if (!isset($options))
|
|
|
|
{
|
|
|
|
$options = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$action = $params;
|
|
|
|
}
|
|
|
|
|
2006-01-12 04:08:19 +00:00
|
|
|
$htmlOptions = $this->__getHtmlOptions($options);
|
2006-01-18 04:38:21 +00:00
|
|
|
$htmlOptions['action'] = $action;
|
|
|
|
|
|
|
|
if(!isset($htmlOptions['id']))
|
|
|
|
{
|
|
|
|
$htmlOptions['id'] = 'form'.intval(rand());
|
|
|
|
}
|
2006-01-12 04:08:19 +00:00
|
|
|
$htmlOptions['onsubmit'] = "return false;";
|
2006-01-18 04:38:21 +00:00
|
|
|
|
|
|
|
if(!isset($options['with']))
|
|
|
|
{
|
2006-02-08 15:25:34 +00:00
|
|
|
$options['with'] = "Form.serialize('{$htmlOptions['id']}')";
|
2006-01-18 04:38:21 +00:00
|
|
|
}
|
|
|
|
$options['url'] = $action;
|
2006-01-22 05:12:28 +00:00
|
|
|
|
2006-02-17 10:12:15 +00:00
|
|
|
return $this->Html->formTag($htmlOptions['action'], $type, $htmlOptions) . $this->Javascript->event("$('".$htmlOptions['id']."')", "submit", $this->remoteFunction($options));
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Returns a button input tag that will submit using Ajax
|
|
|
|
*
|
|
|
|
* Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular
|
|
|
|
* reloading POST arrangement. <i>options</i> argument is the same as in <i>form_remote_tag</i>
|
|
|
|
*
|
|
|
|
* @param string $title Input button title
|
|
|
|
* @param array $options Callback options
|
|
|
|
* @return string Ajaxed input button
|
|
|
|
*/
|
2006-02-17 10:12:15 +00:00
|
|
|
function submit ($title = 'Submit', $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-12 04:08:19 +00:00
|
|
|
$htmlOptions = $this->__getHtmlOptions($options);
|
2006-02-17 10:12:15 +00:00
|
|
|
$htmlOptions['value'] = $title;
|
2006-01-12 04:08:19 +00:00
|
|
|
|
|
|
|
if (!isset($options['with']))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
$options['with'] = 'Form.serialize(Event.element(event).form)';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isset($htmlOptions['id']))
|
|
|
|
{
|
|
|
|
$htmlOptions['id'] = 'submit'.intval(rand());
|
2006-01-12 04:08:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-17 10:12:15 +00:00
|
|
|
$htmlOptions['onclick'] = "return false;";
|
|
|
|
return $this->Html->submit($title, $htmlOptions) .
|
|
|
|
$this->Javascript->event('$("'.$htmlOptions['id'].'")', 'click', $this->remoteFunction($options));
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Observe field and call ajax on change.
|
|
|
|
*
|
|
|
|
* Observes the field with the DOM ID specified by <i>field_id</i> and makes
|
|
|
|
* an Ajax when its contents have changed.
|
|
|
|
*
|
|
|
|
* Required +options+ are:
|
|
|
|
* - <i>frequency</i>:: The frequency (in seconds) at which changes to
|
|
|
|
* this field will be detected.
|
|
|
|
* - <i>url</i>:: @see urlFor() -style options for the action to call
|
|
|
|
* when the field has changed.
|
|
|
|
*
|
|
|
|
* Additional options are:
|
|
|
|
* - <i>update</i>:: Specifies the DOM ID of the element whose
|
|
|
|
* innerHTML should be updated with the
|
|
|
|
* XMLHttpRequest response text.
|
|
|
|
* - <i>with</i>:: A Javascript expression specifying the
|
|
|
|
* parameters for the XMLHttpRequest. This defaults
|
|
|
|
* to Form.Element.serialize('$field_id'), which can be
|
|
|
|
* accessed from params['form']['field_id'].
|
|
|
|
*
|
|
|
|
* Additionally, you may specify any of the options documented in
|
|
|
|
* @see linkToRemote().
|
|
|
|
*
|
|
|
|
* @param string $field_id DOM ID of field to observe
|
|
|
|
* @param array $options ajax options
|
|
|
|
* @return string ajax script
|
|
|
|
*/
|
2006-01-12 04:08:19 +00:00
|
|
|
function observeField ($field_id, $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (!isset($options['with']))
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
$options['with'] = "Form.Element.serialize('$field_id')";
|
|
|
|
}
|
[1210]
Author: phpnut
Date: 4:44:45 AM, Wednesday, October 26, 2005
Message:
AJAX is now available as a by default in the $html variable in the templates.
You access it like this:
$html->Ajax->xxx();
Updated default templates.
[1208]
Author: phpnut
Date: 6:49:26 PM, Tuesday, October 25, 2005
Message:
Adding fix in Controller::generateFieldNames();
[1203]
Author: phpnut
Date: 10:40:28 AM, Tuesday, October 25, 2005
Message:
Changes made to core templates and css.
Fixed added for Ticket #60
[1202]
Author: phpnut
Date: 2:30:58 AM, Tuesday, October 25, 2005
Message:
Fix for cake error templates
Fixed a key for tables that are underscored in scaffolded code.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1211 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-26 10:55:44 +00:00
|
|
|
return $this->Javascript->codeBlock($this->_buildObserver('Form.Element.Observer', $field_id, $options));
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Observe entire form and call ajax on change.
|
|
|
|
*
|
|
|
|
* Like @see observeField(), but operates on an entire form identified by the
|
|
|
|
* DOM ID <b>form_id</b>. <b>options</b> are the same as <b>observe_field</b>, except
|
|
|
|
* the default value of the <i>with</i> option evaluates to the
|
|
|
|
* serialized (request string) value of the form.
|
|
|
|
*
|
|
|
|
* @param string $field_id DOM ID of field to observe
|
|
|
|
* @param array $options ajax options
|
|
|
|
* @return string ajax script
|
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function observeForm ($field_id, $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
if (!isset($options['with']))
|
|
|
|
{
|
|
|
|
$options['with'] = 'Form.serialize(this.form)';
|
|
|
|
}
|
[1210]
Author: phpnut
Date: 4:44:45 AM, Wednesday, October 26, 2005
Message:
AJAX is now available as a by default in the $html variable in the templates.
You access it like this:
$html->Ajax->xxx();
Updated default templates.
[1208]
Author: phpnut
Date: 6:49:26 PM, Tuesday, October 25, 2005
Message:
Adding fix in Controller::generateFieldNames();
[1203]
Author: phpnut
Date: 10:40:28 AM, Tuesday, October 25, 2005
Message:
Changes made to core templates and css.
Fixed added for Ticket #60
[1202]
Author: phpnut
Date: 2:30:58 AM, Tuesday, October 25, 2005
Message:
Fix for cake error templates
Fixed a key for tables that are underscored in scaffolded code.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1211 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-26 10:55:44 +00:00
|
|
|
return $this->Javascript->codeBlock($this->_buildObserver('Form.Observer', $field_id, $options));
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Create a text field with Autocomplete.
|
|
|
|
*
|
|
|
|
* Creates an autocomplete field with the given ID and options.
|
|
|
|
*
|
|
|
|
* options['with'] defaults to "Form.Element.serialize('$field_id')",
|
|
|
|
* but can be any valid javascript expression defining the
|
|
|
|
*
|
|
|
|
* @param string $field_id DOM ID of field to observe
|
|
|
|
* @param string $url URL for the autocomplete action
|
|
|
|
* @param array $options Ajax options
|
|
|
|
* @return string Ajax script
|
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function autoComplete ($field, $url = "", $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-12 02:10:47 +00:00
|
|
|
if (!isset($options['id']))
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2006-01-12 04:08:19 +00:00
|
|
|
$options['id'] = r("/", "_", $field);
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-15 12:18:57 +00:00
|
|
|
$htmlOptions = $this->__getHtmlOptions($options);
|
2005-09-19 17:20:24 +00:00
|
|
|
|
|
|
|
$htmlOptions['autocomplete'] = "off";
|
|
|
|
|
2006-01-12 04:08:19 +00:00
|
|
|
if(!isset($options['class']))
|
|
|
|
{
|
2006-01-25 22:40:17 +00:00
|
|
|
$options['class'] = "auto_complete";
|
2006-01-12 04:08:19 +00:00
|
|
|
}
|
2005-09-19 17:20:24 +00:00
|
|
|
|
2006-01-12 04:08:19 +00:00
|
|
|
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => $options['class']);
|
2005-10-03 04:48:00 +00:00
|
|
|
|
[1210]
Author: phpnut
Date: 4:44:45 AM, Wednesday, October 26, 2005
Message:
AJAX is now available as a by default in the $html variable in the templates.
You access it like this:
$html->Ajax->xxx();
Updated default templates.
[1208]
Author: phpnut
Date: 6:49:26 PM, Tuesday, October 25, 2005
Message:
Adding fix in Controller::generateFieldNames();
[1203]
Author: phpnut
Date: 10:40:28 AM, Tuesday, October 25, 2005
Message:
Changes made to core templates and css.
Fixed added for Ticket #60
[1202]
Author: phpnut
Date: 2:30:58 AM, Tuesday, October 25, 2005
Message:
Fix for cake error templates
Fixed a key for tables that are underscored in scaffolded code.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1211 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-26 10:55:44 +00:00
|
|
|
return $this->Html->input($field, $htmlOptions) .
|
2006-02-08 15:25:34 +00:00
|
|
|
$this->Html->tag("div", $divOptions, true) . "</div>" .
|
|
|
|
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" .
|
|
|
|
$divOptions['id'] . "', '" . $this->Html->url($url) . "', " . $this->__optionsForAjax($options) . ");");
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
2006-01-12 04:08:19 +00:00
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $id
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param array $options
|
2006-01-12 02:10:47 +00:00
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function drag($id, $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
$options = $this->_optionsForDraggable($options);
|
2006-02-08 15:25:34 +00:00
|
|
|
return $this->Javascript->codeBlock("new Draggable('$id', $options);");
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Private helper method to return an array of options for draggable.
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @return array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
function _optionsForDraggable ($options)
|
|
|
|
{
|
|
|
|
$options = $this->_optionsToString($options, array('handle','constraint'));
|
|
|
|
return $this->_buildOptions($options, $this->dragOptions);
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* For a reference on the options for this function, check out
|
|
|
|
* http://wiki.script.aculo.us/scriptaculous/show/Droppables.add
|
|
|
|
*
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param unknown_type $id
|
2006-02-18 23:42:21 +00:00
|
|
|
* @param array $options
|
|
|
|
* @return array
|
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function drop($id, $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
$options = $this->_optionsForDroppable($options);
|
2006-02-08 15:25:34 +00:00
|
|
|
return $this->Javascript->codeBlock("Droppables.add('$id', $options);");
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $options
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
function _optionsForDroppable ($options)
|
2006-01-12 02:10:47 +00:00
|
|
|
{
|
2005-09-19 17:20:24 +00:00
|
|
|
$options = $this->_optionsToString($options, array('accept','overlap','hoverclass'));
|
|
|
|
return $this->_buildOptions($options, $this->dropOptions);
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $id
|
|
|
|
* @param unknown_type $options
|
|
|
|
* @param unknown_type $ajaxOptions
|
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function dropRemote($id, $options = array(), $ajaxOptions = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
2005-10-03 04:48:00 +00:00
|
|
|
$options['onDrop'] = "function(element){" . $this->remoteFunction($ajaxOptions) . "}";
|
2006-01-13 05:56:04 +00:00
|
|
|
$options = $this->_optionsForDroppable($options);
|
2006-02-08 15:25:34 +00:00
|
|
|
return $this->Javascript->codeBlock("Droppables.add('$id', $options);");
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Makes a slider control.
|
|
|
|
*
|
|
|
|
* @param string $id DOM ID of slider handle
|
|
|
|
* @param string $track_id DOM ID of slider track
|
|
|
|
* @param array $options Array of options to control the slider
|
|
|
|
* @link http://wiki.script.aculo.us/scriptaculous/show/Slider
|
|
|
|
*/
|
2006-02-07 02:19:53 +00:00
|
|
|
function slider($id, $track_id, $options = array())
|
|
|
|
{
|
|
|
|
$options = $this->_optionsToString($options, array('axis','handleImage','handleDisabled'));
|
2006-02-08 15:25:34 +00:00
|
|
|
if (isset($options['change']))
|
|
|
|
{
|
|
|
|
$options['onChange'] = $options['change'];
|
|
|
|
unset($options['change']);
|
|
|
|
}
|
|
|
|
if (isset($options['slide']))
|
|
|
|
{
|
|
|
|
$options['onSlide'] = $options['slide'];
|
|
|
|
unset($options['slide']);
|
|
|
|
}
|
2006-02-07 02:19:53 +00:00
|
|
|
$options = $this->_buildOptions($options, $this->sliderOptions);
|
2006-02-08 15:25:34 +00:00
|
|
|
return $this->Javascript->codeBlock("var $id = new Control.Slider('$id', '$track_id', $options);");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Makes an Ajax In Place editor control.
|
|
|
|
*
|
|
|
|
* @param string $id DOM ID of input element
|
|
|
|
* @param string $url Postback URL of saved data
|
|
|
|
* @param array $options Array of options to control the editor, including ajaxOptions (see link).
|
|
|
|
* @link http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor
|
|
|
|
*/
|
2006-02-08 15:25:34 +00:00
|
|
|
function editor($id, $url, $options = array())
|
|
|
|
{
|
|
|
|
$url = $this->Html->url($url);
|
|
|
|
$options['ajaxOptions'] = $this->__optionsForAjax($options);
|
|
|
|
foreach ($this->ajaxOptions as $opt)
|
|
|
|
{
|
|
|
|
if (isset($options[$opt]))
|
|
|
|
{
|
|
|
|
unset($options[$opt]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($options['callback']))
|
|
|
|
{
|
2006-02-17 10:12:15 +00:00
|
|
|
$options['callback'] = 'function(form, value) {'.$options['callback'].'}';
|
2006-02-08 15:25:34 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 22:14:21 +00:00
|
|
|
$options = $this->_optionsToString($options, array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'clickToEditText'));
|
2006-02-08 15:25:34 +00:00
|
|
|
$options = $this->_buildOptions($options, $this->editorOptions);
|
|
|
|
return $this->Javascript->codeBlock("new Ajax.InPlaceEditor('{$id}', '{$url}', {$options});");
|
2006-02-07 02:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Makes a list or group of floated objects sortable.
|
|
|
|
*
|
|
|
|
* @param string $id DOM ID of parent
|
|
|
|
* @param array $options Array of options to control sort.http://wiki.script.aculo.us/scriptaculous/show/Sortable.create
|
|
|
|
* @link http://wiki.script.aculo.us/scriptaculous/show/Sortable.create
|
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function sortable($id, $options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
if (!empty($options['url']))
|
|
|
|
{
|
|
|
|
$options['with'] = "Sortable.serialize('$id')";
|
2005-10-03 04:48:00 +00:00
|
|
|
$options['onUpdate'] = 'function(sortable){' . $this->remoteFunction($options).'}';
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
2006-01-12 04:08:19 +00:00
|
|
|
$options = $this->__optionsForSortable($options);
|
2006-02-08 15:25:34 +00:00
|
|
|
return $this->Javascript->codeBlock("Sortable.create('$id', $options);");
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
2006-01-12 02:10:47 +00:00
|
|
|
|
|
|
|
/**
|
2006-01-12 04:08:19 +00:00
|
|
|
* Private method; generates sortables code from array options
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param array $options
|
2006-01-12 02:10:47 +00:00
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-01-12 04:08:19 +00:00
|
|
|
function __optionsForSortable ($options)
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
$options = $this->_optionsToString($options, array('handle','tag','constraint','ghosting'));
|
|
|
|
return $this->_buildOptions($options, $this->sortOptions);
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Private helper function for Javascript.
|
|
|
|
*
|
|
|
|
*/
|
2006-01-12 04:08:19 +00:00
|
|
|
function __optionsForAjax ($options = array())
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
$js_options = $this->_buildCallbacks($options);
|
2006-02-08 15:25:34 +00:00
|
|
|
if (!isset($js_options['asynchronous']))
|
|
|
|
{
|
|
|
|
$js_options['asynchronous'] = 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($js_options['evalScripts']))
|
|
|
|
{
|
|
|
|
$js_options['evalScripts'] = 'true';
|
|
|
|
}
|
|
|
|
|
2005-09-19 17:20:24 +00:00
|
|
|
$options = $this->_optionsToString($options, array('method'));
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2005-09-19 17:20:24 +00:00
|
|
|
foreach($options as $key => $value)
|
|
|
|
{
|
|
|
|
switch($key)
|
|
|
|
{
|
|
|
|
case 'type':
|
2006-01-12 04:08:19 +00:00
|
|
|
$js_options['asynchronous'] = ($value == 'synchronous') ? 'false' : 'true';
|
2005-09-19 17:20:24 +00:00
|
|
|
break;
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2005-09-19 17:20:24 +00:00
|
|
|
case 'position':
|
2006-01-12 04:08:19 +00:00
|
|
|
$js_options['insertion'] = "Insertion." . Inflector::camelize($options['position']);
|
2005-09-19 17:20:24 +00:00
|
|
|
break;
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2005-09-19 17:20:24 +00:00
|
|
|
case 'with':
|
2006-01-12 04:08:19 +00:00
|
|
|
$js_options['parameters'] = $options['with'];
|
2005-09-19 17:20:24 +00:00
|
|
|
break;
|
2006-01-12 02:10:47 +00:00
|
|
|
|
2005-09-19 17:20:24 +00:00
|
|
|
case 'form':
|
2006-01-12 04:08:19 +00:00
|
|
|
$js_options['parameters'] = 'Form.serialize(this)';
|
2005-09-19 17:20:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_buildOptions($js_options, $this->ajaxOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-15 12:18:57 +00:00
|
|
|
function __getHtmlOptions($options, $extra = array())
|
2006-01-12 04:08:19 +00:00
|
|
|
{
|
2006-01-15 12:18:57 +00:00
|
|
|
foreach($this->ajaxOptions as $key)
|
|
|
|
{
|
|
|
|
unset($options[$key]);
|
|
|
|
}
|
|
|
|
foreach($extra as $key)
|
2006-01-12 04:08:19 +00:00
|
|
|
{
|
|
|
|
unset($options[$key]);
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Returns a string of JavaScript with the given option data as a JavaScript options hash.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param array $options Options in the shape of keys and values
|
|
|
|
* @param array $acceptable Array of legal keys in this options context
|
|
|
|
* @return string String of Javascript array definition
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
|
|
|
function _buildOptions ($options, $acceptable) {
|
2005-09-19 17:20:24 +00:00
|
|
|
if(is_array($options))
|
|
|
|
{
|
|
|
|
$out = array();
|
|
|
|
foreach ($options as $k => $v)
|
|
|
|
{
|
|
|
|
if(in_array($k, $acceptable))
|
|
|
|
{
|
|
|
|
$out[] = "$k:$v";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$out = join(', ', $out);
|
2006-02-08 15:25:34 +00:00
|
|
|
$out = '{' . $out . '}';
|
2005-09-19 17:20:24 +00:00
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Return JavaScript text for an observer...
|
|
|
|
*
|
|
|
|
* @param string $klass Name of JavaScript class
|
|
|
|
* @param string $name
|
|
|
|
* @param array $options Ajax options
|
|
|
|
* @return string Formatted JavaScript
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2005-10-03 04:48:00 +00:00
|
|
|
function _buildObserver ($klass, $name, $options=null)
|
2005-09-19 17:20:24 +00:00
|
|
|
{
|
|
|
|
if(!isset($options['with']) && isset($options['update']))
|
|
|
|
{
|
|
|
|
$options['with'] = 'value';
|
|
|
|
}
|
|
|
|
|
2005-10-03 04:48:00 +00:00
|
|
|
$callback = $this->remoteFunction($options);
|
2005-09-19 17:20:24 +00:00
|
|
|
$javascript = "new $klass('$name', ";
|
|
|
|
$javascript .= (isset($options['frequency']) ? $options['frequency'] : 2) . ", function(element, value) {";
|
|
|
|
$javascript .= "$callback})";
|
|
|
|
return $javascript;
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here... Return JavaScript text for all callbacks...
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @return array
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
function _buildCallbacks($options)
|
|
|
|
{
|
|
|
|
$callbacks = array();
|
|
|
|
foreach($this->callbacks as $callback)
|
|
|
|
{
|
|
|
|
if(isset($options[$callback]))
|
|
|
|
{
|
|
|
|
$name = 'on' . ucfirst($callback);
|
|
|
|
$code = $options[$callback];
|
|
|
|
$callbacks[$name] = "function(request){".$code."}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $callbacks;
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:10:47 +00:00
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Returns a string of JavaScript with a string representation of given options array.
|
2006-01-12 02:10:47 +00:00
|
|
|
*
|
2006-02-07 02:19:53 +00:00
|
|
|
* @param array $options Ajax options array
|
|
|
|
* @param array $stringOpts Options as strings in an array
|
|
|
|
* @access private
|
|
|
|
* @return array
|
2006-01-12 02:10:47 +00:00
|
|
|
*/
|
2005-09-19 17:20:24 +00:00
|
|
|
function _optionsToString ($options, $stringOpts = array())
|
|
|
|
{
|
|
|
|
foreach ($stringOpts as $option)
|
|
|
|
{
|
2006-02-18 23:42:21 +00:00
|
|
|
if(isset($options[$option]) && !$options[$option][0] != "'")
|
|
|
|
{
|
|
|
|
$options[$option] = "'{$options[$option]}'";
|
|
|
|
}
|
2005-09-19 17:20:24 +00:00
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2005-06-21 23:44:49 +00:00
|
|
|
}
|
2005-09-19 17:20:24 +00:00
|
|
|
?>
|