Fixing AjaxHelper::sortable() options and filtering Ajax callbacks from link options in AjaxHelper::link(), fixes #4279, fixes #4274

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6576 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-03-15 22:48:46 +00:00
parent 38c7dab9f5
commit 07d2b0d2d3
2 changed files with 23 additions and 9 deletions

View file

@ -641,10 +641,12 @@ class AjaxHelper extends AppHelper {
$block = $options['block']; $block = $options['block'];
unset($options['block']); unset($options['block']);
} }
$strings = array('tag', 'constraint', 'only', 'handle', 'hoverclass', 'tree', 'treeTag', 'update', 'overlap');
if (isset($options['scroll']) && $options['scroll'] != 'window' && strpos($options['scroll'], '$(') !== 0) {
$strings[] = 'scroll';
}
$options = $this->_optionsToString($options, array( $options = $this->_optionsToString($options, $strings);
'tag', 'constraint', 'only', 'handle', 'hoverclass', 'scroll', 'tree', 'treeTag', 'update', 'overlap'
));
$options = array_merge($options, $this->_buildCallbacks($options)); $options = array_merge($options, $this->_buildCallbacks($options));
$options = $this->_buildOptions($options, $this->sortOptions); $options = $this->_buildOptions($options, $this->sortOptions);
$result = "Sortable.create('$id', $options);"; $result = "Sortable.create('$id', $options);";
@ -724,12 +726,7 @@ class AjaxHelper extends AppHelper {
* @access private * @access private
*/ */
function __getHtmlOptions($options, $extra = array()) { function __getHtmlOptions($options, $extra = array()) {
foreach ($this->ajaxOptions as $key) { foreach (array_merge($this->ajaxOptions, $this->callbacks, $extra) as $key) {
if (isset($options[$key])) {
unset($options[$key]);
}
}
foreach ($extra as $key) {
if (isset($options[$key])) { if (isset($options[$key])) {
unset($options[$key]); unset($options[$key]);
} }

View file

@ -195,6 +195,18 @@ class AjaxTest extends UnitTestCase {
$result = $this->Ajax->sortable('div', array('block' => false)); $result = $this->Ajax->sortable('div', array('block' => false));
$expected = "Sortable.create('div', {});"; $expected = "Sortable.create('div', {});";
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => 'someID'));
$expected = "Sortable.create('div', {scroll:'someID'});";
$this->assertEqual($result, $expected);
$result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => 'window'));
$expected = "Sortable.create('div', {scroll:window});";
$this->assertEqual($result, $expected);
$result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => '$("someElement")'));
$expected = "Sortable.create('div', {scroll:$(\"someElement\")});";
$this->assertEqual($result, $expected);
} }
function testSubmitWithIndicator() { function testSubmitWithIndicator() {
@ -290,6 +302,11 @@ class AjaxTest extends UnitTestCase {
$this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result); $this->assertNoPattern('/<script[^<>]+[^type]=[^<>]*>/', $result);
$this->assertPattern('/Event.observe\(\'\w+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result); $this->assertPattern('/Event.observe\(\'\w+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, onFailure:function\(request\) {failure\(\);}, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result); $this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, onFailure:function\(request\) {failure\(\);}, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result);
$result = $this->Ajax->link('Ajax Link', '/test', array('complete' => 'test'));
$this->assertPattern('/^<a[^<>]+>Ajax Link<\/a><script [^<>]+>\s*' . str_replace('/', '\\/', preg_quote('//<![CDATA[')) . '\s*[^<>]+\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result);
$this->assertPattern("/Event.observe\('link[0-9]+', [\w\d,'\(\)\s{}]+Ajax\.Request\([\w\d\s,'\(\){}:\/]+onComplete:function\(request, json\) {test}/", $result);
$this->assertNoPattern('/^<a[^<>]+complete="test"[^<>]*>Ajax Link<\/a>/', $result);
} }
function testRemoteTimer() { function testRemoteTimer() {