summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-01-24 05:14:44 +0000
committerBharat Mediratta <bharat@menalto.com>2009-01-24 05:14:44 +0000
commiteed57674f99621e5354a13543067e9556eb9c6d0 (patch)
tree563795ae826ea1e1175bef94ceab722807718c6a
parent20cd5df3a374f035bddf71ddf2b75c533f05bfac (diff)
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.
-rw-r--r--core/controllers/move.php64
-rw-r--r--core/libraries/ORM_MPTT.php14
-rw-r--r--core/models/item.php1
-rw-r--r--core/views/move_browse.html.php38
-rw-r--r--core/views/move_tree.html.php19
-rw-r--r--core/views/quick_pane.html.php2
-rw-r--r--themes/default/css/screen.css13
7 files changed, 150 insertions, 1 deletions
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 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Move_Controller extends Controller {
+ public function browse($source_id) {
+ $source = ORM::factory("item", $source_id);
+ access::required("edit", $source);
+
+ $view = new View("move_browse.html");
+ $view->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
@@ -103,6 +103,15 @@ class ORM_MPTT_Core extends ORM {
}
/**
+ * 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
*
* @return ORM
@@ -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 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<script type="text/javascript">
+ var load_tree = function(target_id, locked) {
+ var load_url = "<?= url::site("move/show_sub_tree/{$source->id}/__TARGETID__") ?>";
+ var node = $("#node_" + target_id);
+ $("#gMove .node a").removeClass("selected");
+ node.find("a:first").addClass("selected");
+ if (locked) {
+ $("#gMoveButton").attr("disabled", "disabled");
+ $("#gMove form input[name=target_id]").attr("value", "");
+ } else {
+ $("#gMoveButton").removeAttr("disabled");
+ $("#gMove form input[name=target_id]").attr("value", target_id);
+ }
+ var sub_tree = $("#tree_" + target_id);
+ if (sub_tree.length) {
+ sub_tree.toggle();
+ } else {
+ $.get(load_url.replace("__TARGETID__", target_id), {},
+ function(data) {
+ node.html(data);
+ node.find("a:first").addClass("selected");
+ });
+ }
+ }
+</script>
+<div id="gMove">
+ <ul id="tree_0">
+ <li id="node_1" class="node">
+ <?= $tree ?>
+ </li>
+ </ul>
+ <form method="post" action="<?= url::site("move/save/$source->id") ?>">
+ <?= access::csrf_form_field() ?>
+ <input type="hidden" name="target_id" value="" />
+ <input type="submit" id="gMoveButton" value="<?= t("Move") ?>" disabled="disabled"/>
+ </form>
+</div>
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 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<?= $parent->thumb_tag(array(), 25); ?>
+<? if (!access::can("edit", $parent) || $source->is_descendant($parent)): ?>
+<a href="javascript:load_tree('<?= $parent->id ?>',1)"> <?= $parent->title ?> <?= t("(locked)") ?> </a>
+<? else: ?>
+<a href="javascript:load_tree('<?= $parent->id ?>',0)"> <?= $parent->title ?></a>
+<? endif ?>
+<ul id="tree_<?= $parent->id ?>">
+ <? foreach ($children as $child): ?>
+ <li id="node_<?= $child->id ?>" class="node">
+ <?= $child->thumb_tag(array(), 25); ?>
+ <? if (!access::can("edit", $child) || $source->is_descendant($child)): ?>
+ <a href="javascript:load_tree('<?= $child->id ?>',1)"> <?= $child->title ?> <?= t("(locked)") ?></a>
+ <? else: ?>
+ <a href="javascript:load_tree('<?= $child->id ?>',0)"> <?= $child->title ?> </a>
+ <? endif ?>
+ </li>
+ <? endforeach ?>
+</ul>
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 @@
</a>
<? endif ?>
-<a class="move" href="<?= url::site("quick/form_edit/$item->id") ?>"
+<a class="move gDialogLink" href="<?= url::site("move/browse/$item->id") ?>"
title="<?= t("Move this item to another album") ?>">
<span>
<?= t("Move this item to another album") ?>
diff --git a/themes/default/css/screen.css b/themes/default/css/screen.css
index 4f8bdf49..e535fdab 100644
--- a/themes/default/css/screen.css
+++ b/themes/default/css/screen.css
@@ -763,3 +763,16 @@ form p.gError {
#gDialog legend {
display: none;
}
+
+
+
+
+/* STUFF THAT NEEDS A HOME */
+
+#gMove ul {
+ padding-left: 1em;
+}
+
+#gMove .selected {
+ background: #999;
+}