Skip to content

Commit

Permalink
Applying patch from 'evilbloodydemon'. Fixes JqueryEngine::request() …
Browse files Browse the repository at this point in the history
…when wrapCallbacks is true. Test cases added. Fixes #20
  • Loading branch information
markstory committed Aug 12, 2009
1 parent 6b57567 commit c02a8fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -240,7 +240,13 @@ function request($url, $options = array()) {
}
$options['url'] = $url;
if (isset($options['update'])) {
$options['success'] = 'function (msg, status) {$("' . $options['update'] . '").html(msg);}';
$wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
if ($wrapCallbacks) {
$success = '$("' . $options['update'] . '").html(data);';
} else {
$success = 'function (data, textStatus) {$("' . $options['update'] . '").html(data);}';
}
$options['success'] = $success;
unset($options['update']);
}
$callbacks = array('success', 'error', 'beforeSend', 'complete');
Expand Down
10 changes: 8 additions & 2 deletions cake/tests/cases/libs/view/helpers/jquery_engine.test.php
Expand Up @@ -160,6 +160,12 @@ function testRequest() {
$expected = '$.ajax({url:"\\/posts\\/view\\/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array(
'update' => '#content'
));
$expected = '$.ajax({success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request('/people/edit/1', array(
'method' => 'post',
'before' => 'doBefore',
Expand All @@ -179,7 +185,7 @@ function testRequest() {
'method' => 'post',
'wrapCallbacks' => false
));
$expected = '$.ajax({success:function (msg, status) {$("#updated").html(msg);}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request('/people/edit/1', array(
Expand All @@ -190,7 +196,7 @@ function testRequest() {
'data' => '$("#someId").serialize()',
'wrapCallbacks' => false
));
$expected = '$.ajax({data:$("#someId").serialize(), success:function (msg, status) {$("#updated").html(msg);}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({data:$("#someId").serialize(), success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request('/people/edit/1', array(
Expand Down

0 comments on commit c02a8fa

Please sign in to comment.