Skip to content
Permalink
Browse files

Fixing request() callbacks. Starting test for prototype

  • Loading branch information...
markstory committed Apr 6, 2009
1 parent 87c5a5d commit 5f7abae48c59475de7dbb19cd9315e51e74d3970
@@ -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 @@ function effect($name, $options) {
* ### 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 @@ function request($url, $options = array()) {
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 @@ function effect($name, $options = array()) {
* @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 @@ function testRequest() {
$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 @@ function testRequest() {
$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 @@ function testEffect() {
* @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

0 comments on commit 5f7abae

Please sign in to comment.
You can’t perform that action at this time.