mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing request() callbacks. Starting test for prototype
This commit is contained in:
parent
87c5a5da6a
commit
5f7abae48c
7 changed files with 81 additions and 11 deletions
|
@ -35,8 +35,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
var $_optionMap = array(
|
||||
'request' => array(
|
||||
'type' => 'dataType',
|
||||
'complete' => 'success',
|
||||
'request' => 'beforeSend',
|
||||
'before' => 'beforeSend',
|
||||
),
|
||||
'sortable' => array(
|
||||
'complete' => 'stop',
|
||||
|
|
|
@ -562,7 +562,8 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
* ### Event Options
|
||||
*
|
||||
* - 'complete' - Callback to fire on complete.
|
||||
* - 'request' - Callback to fire on request initialization.
|
||||
* - 'success' - Callback to fire on success.
|
||||
* - 'before' - Callback to fire on request initialization.
|
||||
* - 'error' - Callback to fire on request failure.
|
||||
*
|
||||
* ### Options
|
||||
|
|
|
@ -38,7 +38,8 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
var $_optionMap = array(
|
||||
'request' => array(
|
||||
'complete' => 'onComplete',
|
||||
'request' => 'onRequest',
|
||||
'success' => 'onSuccess',
|
||||
'before' => 'onRequest',
|
||||
'error' => 'onFailure'
|
||||
),
|
||||
'sortable' => array(
|
||||
|
@ -185,7 +186,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
unset($options['type']);
|
||||
}
|
||||
$options['url'] = $url;
|
||||
$callbacks = array('onComplete', 'onFailure', 'onRequest');
|
||||
$callbacks = array('onComplete', 'onFailure', 'onRequest', 'onSuccess', 'onCancel', 'onException');
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
return "var jsRequest = new Request$type({{$options}}).send($data);";
|
||||
}
|
||||
|
|
|
@ -34,7 +34,13 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
* @var array
|
||||
**/
|
||||
var $_optionMap = array(
|
||||
|
||||
'request' => array(
|
||||
'async' => 'asyncrhronous',
|
||||
'data' => 'parameters',
|
||||
'before' => 'onCreate',
|
||||
'complete' => 'onSuccess',
|
||||
'error' => 'onFailure'
|
||||
)
|
||||
);
|
||||
/**
|
||||
* Create javascript selector for a CSS rule
|
||||
|
@ -153,7 +159,32 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
* @return string The completed ajax call.
|
||||
**/
|
||||
function request($url, $options = array()) {
|
||||
|
||||
$url = '"'. $this->url($url) . '"';
|
||||
$options = $this->_mapOptions('request', $options);
|
||||
$type = $data = null;
|
||||
/*if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
$type = '.JSON';
|
||||
if (!empty($options['data'])) {
|
||||
$data = $this->object($options['data']);
|
||||
unset($options['data']);
|
||||
}
|
||||
unset($options['type']);
|
||||
}*/
|
||||
if (isset($options['update'])) {
|
||||
$options['update'] = str_replace('#', '', $options['update']);
|
||||
$type = '.Updater';
|
||||
if (!empty($options['data'])) {
|
||||
$data = $this->_toQuerystring($options['data']);
|
||||
unset($options['data']);
|
||||
}
|
||||
unset($options['type']);
|
||||
}
|
||||
$callbacks = array('onComplete', 'onFailure', 'onRequest');
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
return "var jsRequest = new Ajax$type($url$options);";
|
||||
}
|
||||
/**
|
||||
* Create a sortable element.
|
||||
|
|
|
@ -146,12 +146,14 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
|
|||
|
||||
$result = $this->Jquery->request('/people/edit/1', array(
|
||||
'method' => 'post',
|
||||
'complete' => 'doSuccess',
|
||||
'before' => 'doBefore',
|
||||
'complete' => 'doComplete',
|
||||
'success' => 'doSuccess',
|
||||
'error' => 'handleError',
|
||||
'type' => 'json',
|
||||
'data' => array('name' => 'jim', 'height' => '185cm')
|
||||
));
|
||||
$expected = '$.ajax({data:"name=jim&height=185cm", dataType:"json", error:handleError, method:"post", success:doSuccess, url:"/people/edit/1"});';
|
||||
$expected = '$.ajax({beforeSend:doBefore, complete:doComplete, data:"name=jim&height=185cm", dataType:"json", error:handleError, method:"post", success:doSuccess, url:"/people/edit/1"});';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Jquery->request('/people/edit/1', array(
|
||||
|
|
|
@ -181,10 +181,13 @@ class MooEngineHelperTestCase extends CakeTestCase {
|
|||
|
||||
$result = $this->Moo->request('/people/edit/1', array(
|
||||
'method' => 'post',
|
||||
'complete' => 'doSuccess',
|
||||
'complete' => 'doComplete',
|
||||
'success' => 'doSuccess',
|
||||
'error' => 'doFailure',
|
||||
'before' => 'doBefore',
|
||||
'update' => 'update-zone'
|
||||
));
|
||||
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doSuccess, update:"update-zone", url:"/people/edit/1"}).send();';
|
||||
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doComplete, onFailure:doFailure, onRequest:doBefore, onSuccess:doSuccess, update:"update-zone", url:"/people/edit/1"}).send();';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -168,7 +168,40 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
|||
* @return void
|
||||
**/
|
||||
function testRequest() {
|
||||
$result = $this->Proto->request(array('controller' => 'posts', 'action' => 'view', 1));
|
||||
$expected = 'var jsRequest = new Ajax("/posts/view/1");';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->request('/posts/view/1', array('update' => 'content'));
|
||||
$expected = 'var jsRequest = new Ajax.Updater("/posts/view/1", {update:"content"});';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
/* $result = $this->Proto->request('/people/edit/1', array(
|
||||
'method' => 'post',
|
||||
'complete' => 'doSuccess',
|
||||
'error' => 'handleError',
|
||||
'type' => 'json',
|
||||
'data' => array('name' => 'jim', 'height' => '185cm')
|
||||
));
|
||||
$expected = 'var jsRequest = new Request.JSON({method:"post", onComplete:doSuccess, onFailure:handleError, url:"/people/edit/1"}).send({"name":"jim","height":"185cm"});';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->request('/people/edit/1', array(
|
||||
'method' => 'post',
|
||||
'complete' => 'doSuccess',
|
||||
'update' => '#update-zone'
|
||||
));
|
||||
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doSuccess, update:"update-zone", url:"/people/edit/1"}).send();';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Proto->request('/people/edit/1', array(
|
||||
'method' => 'post',
|
||||
'complete' => 'doSuccess',
|
||||
'update' => 'update-zone'
|
||||
));
|
||||
$expected = 'var jsRequest = new Request.HTML({method:"post", onComplete:doSuccess, update:"update-zone", url:"/people/edit/1"}).send();';
|
||||
$this->assertEqual($result, $expected);
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* test sortable list generation
|
||||
|
|
Loading…
Reference in a new issue