From eed57674f99621e5354a13543067e9556eb9c6d0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 24 Jan 2009 05:14:44 +0000 Subject: Add move support. Use the move icon in the quick pane. You can't move an item into its own hierarchy, or into an album where you don't have edit permission. --- core/controllers/move.php | 64 +++++++++++++++++++++++++++++++++++++++++ core/libraries/ORM_MPTT.php | 14 +++++++++ core/models/item.php | 1 + core/views/move_browse.html.php | 38 ++++++++++++++++++++++++ core/views/move_tree.html.php | 19 ++++++++++++ core/views/quick_pane.html.php | 2 +- 6 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 core/controllers/move.php create mode 100644 core/views/move_browse.html.php create mode 100644 core/views/move_tree.html.php (limited to 'core') diff --git a/core/controllers/move.php b/core/controllers/move.php new file mode 100644 index 00000000..2171d492 --- /dev/null +++ b/core/controllers/move.php @@ -0,0 +1,64 @@ +source = $source; + $view->tree = $this->_get_tree_html($source, ORM::factory("item", 1)); + print $view; + } + + public function save($source_id) { + access::verify_csrf(); + $source = ORM::factory("item", $source_id); + access::required("edit", $source); + $target = ORM::factory("item", $this->input->post("target_id")); + access::required("edit", $target); + $source->move_to($target); + print json_encode( + array("result" => "success", + "location" => url::site("albums/{$target->id}"))); + } + + public function show_sub_tree($source_id, $target_id) { + $source = ORM::factory("item", $source_id); + $target = ORM::factory("item", $target_id); + access::required("edit", $source); + access::required("view", $target); + + print $this->_get_tree_html($source, $target); + } + + private function _get_tree_html($source, $target) { + $view = new View("move_tree.html"); + $view->source = $source; + $view->parent = $target; + $view->children = ORM::factory("item") + ->viewable() + ->where("type", "album") + ->where("parent_id", $target->id) + ->find_all(); + return $view; + } + +} diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php index e8411db0..e67478a7 100644 --- a/core/libraries/ORM_MPTT.php +++ b/core/libraries/ORM_MPTT.php @@ -102,6 +102,15 @@ class ORM_MPTT_Core extends ORM { parent::delete(); } + /** + * Return true if the target is descendant of this item. + * @param ORM $target + * @return boolean + */ + function is_descendant($target) { + return ($this->left <= $target->left && $this->right >= $target->right); + } + /** * Return the parent of this node * @@ -203,6 +212,11 @@ class ORM_MPTT_Core extends ORM { throw new Exception("@todo INVALID_SOURCE root album"); } + if ($this->left <= $target->left && + $this->right >= $target->right) { + throw new Exception("@todo INVALID_TARGET can't move item inside itself"); + } + $number_to_move = (int)(($this->right - $this->left) / 2 + 1); $size_of_hole = $number_to_move * 2; $original_left = $this->left; diff --git a/core/models/item.php b/core/models/item.php index 5654b36f..ed82da52 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -110,6 +110,7 @@ class Item_Model extends ORM_MPTT { $original_thumb_path = $this->thumb_path(); parent::move_to($target, true); + $this->relative_path = null; rename($original_path, $this->file_path()); if ($this->is_album()) { diff --git a/core/views/move_browse.html.php b/core/views/move_browse.html.php new file mode 100644 index 00000000..5a0a1f56 --- /dev/null +++ b/core/views/move_browse.html.php @@ -0,0 +1,38 @@ + + +
+ +
id") ?>"> + + + " disabled="disabled"/> +
+
diff --git a/core/views/move_tree.html.php b/core/views/move_tree.html.php new file mode 100644 index 00000000..a3a4bc8f --- /dev/null +++ b/core/views/move_tree.html.php @@ -0,0 +1,19 @@ + +thumb_tag(array(), 25); ?> +is_descendant($parent)): ?> + title ?> + + title ?> + + diff --git a/core/views/quick_pane.html.php b/core/views/quick_pane.html.php index d3977a39..8d39d214 100644 --- a/core/views/quick_pane.html.php +++ b/core/views/quick_pane.html.php @@ -21,7 +21,7 @@ -id") ?>" +id") ?>" title=""> -- cgit v1.2.3