From b4f92c7de69466b2d4ec0c41b9b22e4511314a24 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 29 Jan 2009 09:26:39 +0000 Subject: Add delete support as a quick-edit option --- core/controllers/quick.php | 19 +++++++++++++++++++ core/helpers/dir.php | 2 +- core/js/quick.js | 6 +++++- core/models/item.php | 15 +++++++++++---- core/views/quick_pane.html.php | 4 ++-- 5 files changed, 38 insertions(+), 8 deletions(-) (limited to 'core') diff --git a/core/controllers/quick.php b/core/controllers/quick.php index b9a8fb82..20072044 100644 --- a/core/controllers/quick.php +++ b/core/controllers/quick.php @@ -93,6 +93,25 @@ class Quick_Controller extends Controller { print json_encode(array("result" => "success")); } + public function delete($id) { + access::verify_csrf(); + $item = ORM::factory("item", $id); + access::required("edit", $item); + + $parent = $item->parent(); + + if ($item->type == "album") { + $msg = t("Deleted album %title", array("title" => $item->title)); + } else { + $msg = t("Deleted photo %title", array("title" => $item->title)); + } + + $item->delete(); + message::success($msg); + + print json_encode(array("result" => "success", "reload" => 1)); + } + public function form_edit($id) { $item = ORM::factory("item", $id); access::required("edit", $item); diff --git a/core/helpers/dir.php b/core/helpers/dir.php index 33767f87..e9fe4ea7 100644 --- a/core/helpers/dir.php +++ b/core/helpers/dir.php @@ -27,7 +27,7 @@ class dir_Core { } else if ($resource->isFile()) { unlink($resource->getPathName()); } else if ($resource->isDir()) { - directory::unlink($resource->getRealPath()); + dir::unlink($resource->getRealPath()); } unset($resource); } diff --git a/core/js/quick.js b/core/js/quick.js index e662f77f..457b6d4a 100644 --- a/core/js/quick.js +++ b/core/js/quick.js @@ -49,6 +49,7 @@ var quick_do = function(cont, pane, img) { dataType: "json", success: function(data) { img.css("opacity", "1"); + cont.removeClass("gLoadingLarge"); if (data.src) { img.attr("width", data.width); img.attr("height", data.height); @@ -58,8 +59,11 @@ var quick_do = function(cont, pane, img) { } else { img.css("margin-top", 0); } + } else if (data.location) { + window.location = data.location; + } else if (data.reload) { + window.location.reload(); } - cont.removeClass("gLoadingLarge"); } }); } diff --git a/core/models/item.php b/core/models/item.php index e5e8c556..f78d50b3 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -85,16 +85,23 @@ class Item_Model extends ORM_MPTT { } public function delete() { - $path = $this->file_path(); - parent::delete(); + $original_path = $this->file_path(); + $original_resize_path = $this->resize_path(); + $original_thumb_path = $this->thumb_path(); + // If there is no name, the path is invalid so don't try to delete if (!empty($this->name)) { if ($this->is_album()) { - dir::unlink($path); + dir::unlink(dirname($original_path)); + dir::unlink(dirname($original_resize_path)); + dir::unlink(dirname($original_thumb_path)); } else { - unlink($path); + unlink($original_path); + unlink($original_resize_path); + unlink($original_thumb_path); } } + parent::delete(); } /** diff --git a/core/views/quick_pane.html.php b/core/views/quick_pane.html.php index 35c9dcf1..78a6c1ce 100644 --- a/core/views/quick_pane.html.php +++ b/core/views/quick_pane.html.php @@ -35,14 +35,14 @@ - -id?csrf=" . access::csrf_token()) ?>" title=""> + "> -- cgit v1.2.3