Applying patch from 'hashmich' to make jQueryEngine not override the success callback. This allows you to provide a success callback and still get the html insertion when used with the update key.

Tests updated.
Fixes #1158
This commit is contained in:
mark_story 2010-10-01 22:43:46 -04:00
parent 5e26d282a1
commit 5c27abd35f
2 changed files with 10 additions and 11 deletions

View file

@ -256,14 +256,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
$options['url'] = $url;
if (isset($options['update'])) {
$wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
if ($wrapCallbacks) {
$success = $this->jQueryObject . '("' . $options['update'] . '").html(data);';
} else {
$success = sprintf(
'function (data, textStatus) {%s("%s").html(data);}',
$this->jQueryObject,
$options['update']
);
$success = '';
if(isset($options['success']) AND !empty($options['success'])) {
$success .= $options['success'];
}
$success .= $this->jQueryObject . '("' . $options['update'] . '").html(data);';
if (!$wrapCallbacks) {
$success = 'function (data, textStatus) {' . $success . '}';
}
$options['dataType'] = 'html';
$options['success'] = $success;

View file

@ -184,7 +184,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
'method' => 'post',
'wrapCallbacks' => false
));
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);
$result = $this->Jquery->request('/people/edit/1', array(
@ -195,7 +195,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
'data' => '$("#someId").serialize()',
'wrapCallbacks' => false
));
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);
$result = $this->Jquery->request('/people/edit/1', array(
@ -225,7 +225,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
'data' => '$j("#someId").serialize()',
'wrapCallbacks' => false
));
$expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);
}