mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-01 09:36:18 +00:00
Applying patch from 'evilbloodydemon'. Fixes JqueryEngine::request() when wrapCallbacks is true. Test cases added. Fixes #20
This commit is contained in:
parent
6b575673f7
commit
c02a8faebd
2 changed files with 15 additions and 3 deletions
|
@ -240,7 +240,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
||||||
}
|
}
|
||||||
$options['url'] = $url;
|
$options['url'] = $url;
|
||||||
if (isset($options['update'])) {
|
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']);
|
unset($options['update']);
|
||||||
}
|
}
|
||||||
$callbacks = array('success', 'error', 'beforeSend', 'complete');
|
$callbacks = array('success', 'error', 'beforeSend', 'complete');
|
||||||
|
|
|
@ -160,6 +160,12 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
|
||||||
$expected = '$.ajax({url:"\\/posts\\/view\\/1"});';
|
$expected = '$.ajax({url:"\\/posts\\/view\\/1"});';
|
||||||
$this->assertEqual($result, $expected);
|
$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(
|
$result = $this->Jquery->request('/people/edit/1', array(
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'before' => 'doBefore',
|
'before' => 'doBefore',
|
||||||
|
@ -179,7 +185,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'wrapCallbacks' => false
|
'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);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->Jquery->request('/people/edit/1', array(
|
$result = $this->Jquery->request('/people/edit/1', array(
|
||||||
|
@ -190,7 +196,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
|
||||||
'data' => '$("#someId").serialize()',
|
'data' => '$("#someId").serialize()',
|
||||||
'wrapCallbacks' => false
|
'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);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->Jquery->request('/people/edit/1', array(
|
$result = $this->Jquery->request('/people/edit/1', array(
|
||||||
|
|
Loading…
Add table
Reference in a new issue