summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/rearrange/controllers/rearrange.php26
-rw-r--r--modules/rearrange/js/jquery.gallery.rearrange.tree.js18
2 files changed, 32 insertions, 12 deletions
diff --git a/modules/rearrange/controllers/rearrange.php b/modules/rearrange/controllers/rearrange.php
index 59c1b069..6118e07e 100644
--- a/modules/rearrange/controllers/rearrange.php
+++ b/modules/rearrange/controllers/rearrange.php
@@ -22,14 +22,26 @@ class Rearrange_Controller extends Controller {
public function show($id=null) {
$view = new View("rearrange_item_list.html");
- if (empty($id)) {
- $item = ORM::factory("item", 1);
- $view->children = array($item);
- } else {
- $item = ORM::factory("item", $id);
- $view->children = $item->children();
- }
+ $isRoot = empty($id);
+ $item = ORM::factory("item", $isRoot ? 1 : $id);
+
+ $view->children = $isRoot ? array($item) : $item->children();
print $view;
}
+
+ public function move($source_id, $target_id) {
+ $source = ORM_MPTT::factory("item", $source_id);
+ $target = ORM_MPTT::factory("item", $target_id);
+
+ try {
+ $source->moveTo($target);
+ print "success";
+ } catch (Exception $e) {
+ Kohana::log("error", $e->getMessage() . "\n" + $e->getTraceAsString());
+ header("HTTP/1.1 500");
+ print $e->getMessage();
+ }
+ }
+
} \ No newline at end of file
diff --git a/modules/rearrange/js/jquery.gallery.rearrange.tree.js b/modules/rearrange/js/jquery.gallery.rearrange.tree.js
index 09284a25..c423becd 100644
--- a/modules/rearrange/js/jquery.gallery.rearrange.tree.js
+++ b/modules/rearrange/js/jquery.gallery.rearrange.tree.js
@@ -70,9 +70,19 @@ if(jQuery) (function($){
hoverClass: "droppable-hover",
drop: function(ev, ui) {
source_element = ui.draggable;
- source_parent = source_element.parent();
+ source_parent = getParent(source_element);
target = ui.element;
- alert(source_element.attr("id") + "\n" + target.attr("id"));
+
+ $.ajax({
+ url: "rearrange/move/" + source_element.attr("id") + "/" + target.attr("id"),
+ success: function(data, textStatus) {
+ collapse(source_parent);
+ showTree(source_parent, source_parent.attr("id"));
+ },
+ error: function(xhr, textStatus, errorThrown) {
+ alert("Http Error Code: " + xhr.status + "Text Status: " + textStatus);
+ }
+ });
}
});
bindTree(c);
@@ -168,9 +178,7 @@ if(jQuery) (function($){
showTree(parent, parent.attr("id"));
},
error: function(xhr, textStatus, errorThrown) {
- alert(xhr.status);
- alert(textStatus);
- alert(errorThrown);
+ alert("Http Error Code: " + xhr.status + "Text Status: " + textStatus);
},
type: "DELETE"
});