Permalink
Browse files

Adding sortables to mootools engine.

  • Loading branch information...
1 parent d59a704 commit 9708b2dc50d3e99a1bcf51231825e7c81aa95037 @markstory markstory committed Mar 28, 2009
View
22 cake/libs/view/helpers/mootools_engine.php
@@ -40,6 +40,10 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'complete' => 'onComplete',
'request' => 'onRequest',
'error' => 'onFailure'
+ ),
+ 'sortable' => array(
+ 'distance' => 'snap',
+ 'containment' => 'constrain',
)
);
/**
@@ -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
@@ -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 . '});';
+ }
}
?>
View
16 cake/tests/cases/libs/view/helpers/mootools_engine.test.php
@@ -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.