Permalink
Browse files

Updating prototype engine and test case for request()

  • Loading branch information...
1 parent 5f7abae commit 00f3c6f25dc403061a986134d55c144916995163 @markstory markstory committed Apr 6, 2009
View
16 cake/libs/view/helpers/prototype_engine.php
@@ -38,7 +38,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
'async' => 'asyncrhronous',
'data' => 'parameters',
'before' => 'onCreate',
- 'complete' => 'onSuccess',
+ 'success' => 'onSuccess',
+ 'complete' => 'onComplete',
'error' => 'onFailure'
)
);
@@ -161,7 +162,8 @@ function effect($name, $options = array()) {
function request($url, $options = array()) {
$url = '"'. $this->url($url) . '"';
$options = $this->_mapOptions('request', $options);
- $type = $data = null;
+ $type = '.Request';
+ $data = null;
/*if (isset($options['type']) && strtolower($options['type']) == 'json') {
$type = '.JSON';
if (!empty($options['data'])) {
@@ -171,15 +173,11 @@ function request($url, $options = array()) {
unset($options['type']);
}*/
if (isset($options['update'])) {
- $options['update'] = str_replace('#', '', $options['update']);
+ $url = '"' . str_replace('#', '', $options['update']) . '", ' . $url;
$type = '.Updater';
- if (!empty($options['data'])) {
- $data = $this->_toQuerystring($options['data']);
- unset($options['data']);
- }
- unset($options['type']);
+ unset($options['update'], $options['type']);
}
- $callbacks = array('onComplete', 'onFailure', 'onRequest');
+ $callbacks = array('onCreate', 'onComplete', 'onFailure', 'onRequest', 'onSuccess');
$options = $this->_parseOptions($options, $callbacks);
if (!empty($options)) {
$options = ', {' . $options . '}';
View
28 cake/tests/cases/libs/view/helpers/prototype_engine.test.php
@@ -114,7 +114,8 @@ function testEach() {
* @return void
**/
function testEffect() {
- $result = $this->Proto->get('#foo')->effect('show');
+ $this->Proto->get('#foo');
+ $result = $this->Proto->effect('show');
$expected = '$("foo").show();';
$this->assertEqual($result, $expected);
@@ -169,11 +170,30 @@ function testEffect() {
**/
function testRequest() {
$result = $this->Proto->request(array('controller' => 'posts', 'action' => 'view', 1));
- $expected = 'var jsRequest = new Ajax("/posts/view/1");';
+ $expected = 'var jsRequest = new Ajax.Request("/posts/view/1");';
$this->assertEqual($result, $expected);
-
+
+ $result = $this->Proto->request('/posts/view/1', array(
+ 'method' => 'post',
+ 'complete' => 'doComplete',
+ 'before' => 'doBefore',
+ 'success' => 'doSuccess',
+ 'error' => 'doError',
+ 'data' => array('name' => 'jim', 'height' => '185cm')
+ ));
+ $expected = 'var jsRequest = new Ajax.Request("/posts/view/1", {method:"post", onComplete:doComplete, onCreate:doBefore, onFailure:doError, onSuccess:doSuccess, parameters:{"name":"jim","height":"185cm"}});';
+ $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"});';
+ $expected = 'var jsRequest = new Ajax.Updater("content", "/posts/view/1");';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Proto->request('/people/edit/1', array(
+ 'method' => 'post',
+ 'complete' => 'doSuccess',
+ 'update' => '#update-zone'
+ ));
+ $expected = 'var jsRequest = new Ajax.Updater("update-zone", "/people/edit/1", {method:"post", onComplete:doSuccess});';
$this->assertEqual($result, $expected);
/* $result = $this->Proto->request('/people/edit/1', array(

0 comments on commit 00f3c6f

Please sign in to comment.