Skip to content

Commit

Permalink
Adding sortables to mootools engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 28, 2009
1 parent d59a704 commit 9708b2d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cake/libs/view/helpers/mootools_engine.php
Expand Up @@ -40,6 +40,10 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'complete' => 'onComplete',
'request' => 'onRequest',
'error' => 'onFailure'
),
'sortable' => array(
'distance' => 'snap',
'containment' => 'constrain',
)
);
/**
Expand Down Expand Up @@ -150,6 +154,9 @@ function effect($name, $options = array()) {
}
/**
* Create an new Request.
*
* Requires ```Request```. If you wish to use 'update' key you must have ```Request.HTML```
* if you wish to do Json requests you will need ```JSON``` and ```Request.JSON```.
*
* @param mixed $url
* @param array $options
Expand Down Expand Up @@ -180,5 +187,20 @@ function request($url, $options = array()) {
$options = $this->_parseOptions($options, $callbacks);
return "var jsRequest = new Request$type({{$options}}).send($data);";
}
/**
* Create a sortable element.
*
* Requires both the ```Sortables``` plugin from MootoolsMore
*
* @param array $options Array of options for the sortable.
* @return string Completed sortable script.
* @see JsHelper::sortable() for options list.
**/
function sortable($options = array()) {
$options = $this->_mapOptions('sortable', $options);
$callbacks = array('start', 'sort', 'complete');
$options = $this->_parseOptions($options, $callbacks);
return 'var mooSortable = new Sortables(' . $this->selection . ', {' . $options . '});';
}
}
?>
16 changes: 16 additions & 0 deletions cake/tests/cases/libs/view/helpers/mootools_engine.test.php
Expand Up @@ -171,5 +171,21 @@ function testRequest() {
$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);
}
/**
* test sortable list generation
*
* @return void
**/
function testSortable() {
$result = $this->Moo->get('#myList')->sortable(array(
'distance' => 5,
'containment' => 'parent',
'start' => 'onStart',
'complete' => 'onStop',
'sort' => 'onSort',
));
$expected = 'var mooSortable = new Sortables($("myList"), {start:onStart, complete:onStop, sort:onSort, snap:5, constrain:"parent"});';
$this->assertEqual($result, $expected);
}
}
?>

0 comments on commit 9708b2d

Please sign in to comment.