From 5b3b675b6d8a1cd9a5f2b9455c551791e18d88ff Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 16 Jul 2009 11:19:34 -0700 Subject: Non-trivial changes to the event handling code: 1) The item_updated event no longer takes the old and new items. Instead we overload ORM to track the original data and make that available via the item. This will allow us to move event publishing down into the API methods which in turn will give us more stability since we won't require each controller to remember to do it. 2) ORM class now tracks the original values. It doesn't track the original relationships (no need for that, yet) 3) Added new events: item_deleted group_deleted user_deleted --- modules/organize/controllers/organize.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 6792573d..54e04071 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -279,7 +279,7 @@ class Organize_Controller extends Controller { $item->rename($form->dirname->value); $item->save(); - module::event("item_updated", $orig, $item); + module::event("item_updated", $item); if ($item->is_album()) { log::success("content", "Updated album", "id\">view"); @@ -322,7 +322,7 @@ class Organize_Controller extends Controller { $item->sort_order = $form->direction->value; $item->save(); - module::event("item_updated", $orig, $item); + module::event("item_updated", $item); log::success("content", "Updated album", "id\">view"); $message = t("Saved album %album_title", array("album_title" => p::purify($item->title))); -- cgit v1.2.3 From 0f766b149d0cee7af664f2321fddc6f04cda70ac Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 16 Jul 2009 12:29:16 -0700 Subject: Second non-trivial change to the event code. We now publish model related events from within the model handling code. The only exception to this currently is item_created which is challenging because we have to save the item using ORM_MPTT::add_to_parent() before the object itself is fully set up. When we get that down to one call to save() we can publish that event from within the model also. --- modules/comment/controllers/admin_comments.php | 4 ---- modules/comment/controllers/comments.php | 1 - modules/comment/helpers/comment.php | 5 ----- modules/comment/models/comment.php | 17 ++++++++++++++++- modules/exif/helpers/exif_event.php | 4 +++- modules/gallery/controllers/albums.php | 3 --- modules/gallery/controllers/movies.php | 3 --- modules/gallery/controllers/photos.php | 3 --- modules/gallery/helpers/album.php | 2 ++ modules/gallery/helpers/movie.php | 2 ++ modules/gallery/helpers/photo.php | 2 ++ modules/gallery/models/item.php | 7 ++++++- modules/organize/controllers/organize.php | 4 ---- modules/user/helpers/group.php | 1 - modules/user/helpers/user.php | 1 - modules/user/models/group.php | 13 +++++++++++++ modules/user/models/user.php | 13 +++++++++++++ 17 files changed, 57 insertions(+), 28 deletions(-) (limited to 'modules/organize') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index ea76b188..a164f79f 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -113,10 +113,6 @@ class Admin_Comments_Controller extends Admin_Controller { if ($comment->loaded) { $comment->state = $state; $comment->save(); - module::event("comment_updated", $comment); - if ($comment->original("state") == "published" || $comment->state == "published") { - module::event("item_related_update", $comment->item()); - } } } diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index 02c38491..9fb4796e 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -152,7 +152,6 @@ class Comments_Controller extends REST_Controller { $comment->url = $form->edit_comment->url->value; $comment->text = $form->edit_comment->text->value; $comment->save(); - module::event("comment_updated", $comment); print json_encode( array("result" => "success", diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 08cba096..3d743325 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -61,11 +61,6 @@ class comment_Core { $comment->server_remote_port = substr($input->server("REMOTE_PORT"), 0, 16); $comment->save(); - module::event("comment_created", $comment); - if ($comment->state == "published") { - module::event("item_related_update", $comment->item()); - } - return $comment; } diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index 22c465df..551fb245 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -61,8 +61,23 @@ class Comment_Model extends ORM { $this->updated = time(); if (!$this->loaded && empty($this->created)) { $this->created = $this->updated; + $created = true; } } - return parent::save(); + parent::save(); + + if (isset($created)) { + module::event("comment_created", $this); + } else { + module::event("comment_updated", $this); + } + + // We only notify on the related items if we're making a visible change, which means moving in + // or out of a published state + if ($this->original("state") == "published" || $this->state == "published") { + module::event("item_related_update", $this->item()); + } + + return $this; } } diff --git a/modules/exif/helpers/exif_event.php b/modules/exif/helpers/exif_event.php index 24243f4d..826ec959 100644 --- a/modules/exif/helpers/exif_event.php +++ b/modules/exif/helpers/exif_event.php @@ -19,7 +19,9 @@ */ class exif_event_Core { static function item_created($item) { - exif::extract($item); + if (!$item->is_album()) { + exif::extract($item); + } } static function item_deleted($item) { diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index c378e3ce..9980b676 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -182,7 +182,6 @@ class Albums_Controller extends Items_Controller { } if ($valid) { - $orig = clone $album; $album->title = $form->edit_album->title->value; $album->description = $form->edit_album->description->value; $album->sort_column = $form->edit_album->sort_order->column->value; @@ -192,8 +191,6 @@ class Albums_Controller extends Items_Controller { } $album->save(); - module::event("item_updated", $album); - log::success("content", "Updated album", "id\">view"); message::success( t("Saved album %album_title", array("album_title" => p::clean($album->title)))); diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index fc511082..d954ad8d 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -85,14 +85,11 @@ class Movies_Controller extends Items_Controller { } if ($valid) { - $orig = clone $photo; $photo->title = $form->edit_photo->title->value; $photo->description = $form->edit_photo->description->value; $photo->rename($form->edit_photo->filename->value); $photo->save(); - module::event("item_updated", $photo); - log::success("content", "Updated photo", "id\">view"); message::success( t("Saved photo %photo_title", array("photo_title" => p::clean($photo->title)))); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 77627009..9ce6ed23 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -78,14 +78,11 @@ class Photos_Controller extends Items_Controller { } if ($valid) { - $orig = clone $photo; $photo->title = $form->edit_photo->title->value; $photo->description = $form->edit_photo->description->value; $photo->rename($form->edit_photo->filename->value); $photo->save(); - module::event("item_updated", $photo); - log::success("content", "Updated photo", "id\">view"); message::success( t("Saved photo %photo_title", array("photo_title" => p::clean($photo->title)))); diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 1197f243..f1a6c060 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -71,6 +71,8 @@ class album_Core { mkdir(dirname($album->thumb_path())); mkdir(dirname($album->resize_path())); + // @todo: publish this from inside Item_Model::save() when we refactor to the point where + // there's only one save() happening here. module::event("item_created", $album); return $album; diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index d62ead76..4f4169d5 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -102,6 +102,8 @@ class movie_Core { copy($filename, $movie->file_path()); + // @todo: publish this from inside Item_Model::save() when we refactor to the point where + // there's only one save() happening here. module::event("item_created", $movie); // Build our thumbnail diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index e8a4f357..ce964c14 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -105,6 +105,8 @@ class photo_Core { copy($filename, $photo->file_path()); + // @todo: publish this from inside Item_Model::save() when we refactor to the point where + // there's only one save() happening here. module::event("item_created", $photo); // Build our thumbnail/resizes diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 80f19d26..94e2fcf7 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -350,9 +350,14 @@ class Item_Model extends ORM_MPTT { $this->created = $this->updated; $r = ORM::factory("item")->select("MAX(weight) as max_weight")->find(); $this->weight = $r->max_weight + 1; + $created = 1; } } - return parent::save(); + parent::save(); + if (!isset($created)) { + module::event("item_updated", $this); + } + return $this; } /** diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 54e04071..27852904 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -279,8 +279,6 @@ class Organize_Controller extends Controller { $item->rename($form->dirname->value); $item->save(); - module::event("item_updated", $item); - if ($item->is_album()) { log::success("content", "Updated album", "id\">view"); $message = t("Saved album %album_title", array("album_title" => p::purify($item->title))); @@ -322,8 +320,6 @@ class Organize_Controller extends Controller { $item->sort_order = $form->direction->value; $item->save(); - module::event("item_updated", $item); - log::success("content", "Updated album", "id\">view"); $message = t("Saved album %album_title", array("album_title" => p::purify($item->title))); print json_encode(array("form" => $form->__toString(), "message" => $message)); diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 1dace840..04e6efd6 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -39,7 +39,6 @@ class group_Core { $group->name = $name; $group->save(); - module::event("group_created", $group); return $group; } diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php index a59588f8..4105d745 100644 --- a/modules/user/helpers/user.php +++ b/modules/user/helpers/user.php @@ -202,7 +202,6 @@ class user_Core { $user->add(group::registered_users()); $user->save(); - module::event("user_created", $user); return $user; } diff --git a/modules/user/models/group.php b/modules/user/models/group.php index e0724e30..bb3fb58b 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -32,4 +32,17 @@ class Group_Model extends ORM { parent::delete($id); module::event("group_deleted", $old); } + + public function save() { + if (!$this->loaded) { + $created = 1; + } + parent::save(); + if (isset($created)) { + module::event("group_created", $this); + } else { + module::event("group_updated", $this); + } + return $this; + } } \ No newline at end of file diff --git a/modules/user/models/user.php b/modules/user/models/user.php index e3260270..0234f186 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -59,4 +59,17 @@ class User_Model extends ORM { return sprintf("http://www.gravatar.com/avatar/%s.jpg?s=%d&r=pg%s", md5($this->email), $size, $default ? "&d=" . urlencode($default) : ""); } + + public function save() { + if (!$this->loaded) { + $created = 1; + } + parent::save(); + if (isset($created)) { + module::event("user_created", $this); + } else { + module::event("user_updated", $this); + } + return $this; + } } \ No newline at end of file -- cgit v1.2.3 From 5a0424f458323578a6b2e5395a58f3d2bfc034dc Mon Sep 17 00:00:00 2001 From: Shai Ben-Naphtali Date: Tue, 21 Jul 2009 03:30:21 +0800 Subject: Fix some consistency in text. This fixes ticket #546 Signed-off-by: Bharat Mediratta --- modules/organize/controllers/organize.php | 4 ++-- modules/server_add/controllers/server_add.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 27852904..898be509 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -516,7 +516,7 @@ class Organize_Controller extends Controller { break; case "delete": - return array("description" => t("Delete selected photos and albums"), + return array("description" => t("Delete selected photos / albums"), "name" => t("Delete images in %name", array("name" => $item->title)), "type" => "delete", "runningMsg" => t("Delete images in progress"), @@ -537,4 +537,4 @@ class Organize_Controller extends Controller { throw new Exception("Operation '$operation' is not implmented"); } } -} \ No newline at end of file +} diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 0be0f698..f68392ce 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -239,7 +239,7 @@ class Server_Add_Controller extends Admin_Controller { $entry->save(); } $task->set("completed_files", $completed_files); - $task->status = t("Adding photos and albums (%completed of %total)", + $task->status = t("Adding photos / albums (%completed of %total)", array("completed" => $completed_files, "total" => $total_files)); $task->percent_complete = 10 + 100 * ($completed_files / $total_files); @@ -252,7 +252,7 @@ class Server_Add_Controller extends Admin_Controller { $task->percent_complete = 100; ORM::factory("server_add_file")->where("task_id", $task->id)->delete_all(); message::info(t2("Successfully added one photo / album", - "Successfully added %count photos and albums", + "Successfully added %count photos / albums", $task->get("completed_files"))); } } -- cgit v1.2.3 From 050c82cf80b06a555252efaf701434b0cfd59bed Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 21 Jul 2009 11:09:23 -0700 Subject: Escape bare & symbols so that we use valid entities. Fixes ticket #577. --- modules/organize/views/organize.html.php | 2 +- modules/server_add/views/admin_server_add.html.php | 2 +- modules/server_add/views/server_add_tree_dialog.html.php | 2 +- modules/user/views/login.html.php | 2 +- themes/admin_default/views/admin.html.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/views/organize.html.php b/modules/organize/views/organize.html.php index 65d67d04..1686d255 100644 --- a/modules/organize/views/organize.html.php +++ b/modules/organize/views/organize.html.php @@ -33,7 +33,7 @@ var CONFIRM_DELETE = "
"> + ref="">
    diff --git a/modules/server_add/views/admin_server_add.html.php b/modules/server_add/views/admin_server_add.html.php index 588a9fca..30ab3536 100644 --- a/modules/server_add/views/admin_server_add.html.php +++ b/modules/server_add/views/admin_server_add.html.php @@ -11,7 +11,7 @@
    -
      +
        ">
    diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 28b45be0..d64410d8 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,11 +1,11 @@
  • - "> -
    gBranchText"> + + title) ?>
    @@ -13,7 +13,9 @@
      "> - + + +
  • -- cgit v1.2.3 From e37526f94df74a52a9cf36f0a5a5e641958ebbb3 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 09:23:01 -0700 Subject: Revert "Enable the expand/collapse of branches by clicking on the plus/minus" This reverts commit 869c3de9612a598dae0ce400991bdbe173a2decc. --- modules/organize/controllers/organize.php | 59 +++++++++---------------- modules/organize/css/organize.css | 8 ---- modules/organize/js/organize.js | 28 +----------- modules/organize/views/organize_dialog.html.php | 2 +- modules/organize/views/organize_tree.html.php | 10 ++--- 5 files changed, 27 insertions(+), 80 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index e10e33b5..d7854c53 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -50,27 +50,6 @@ class Organize_Controller extends Controller { print $v->__toString(); } - function children($item_id) { - $item = ORM::factory("item", $item_id); - access::required("view", $item); - access::required("edit", $item); - - $albums = $item->children(null, 0, "album", array("title" => "ASC")); - - $children = ""; - foreach ($albums as $album) { - $v = new View("organize_tree.html"); - $v->album = $album; - $v->selected = false; - $v->children = array(); - $v->album_icon = $album->children_count("album") ? "ui-icon-plus" : "gBranchEmpty"; - - $children .= $v->__toString(); - } - - print $children; - } - private function _get_micro_thumb_grid($item, $offset=0) { $v = new View("organize_thumb_grid.html"); $v->item_id = $item->id; @@ -81,30 +60,34 @@ class Organize_Controller extends Controller { return $v; } - private function _tree($item, $parent, $depth=0) { - $albums = $parent->children(null, 0, "album", array("title" => "ASC")); + private function _tree($item, $parent, $selected=false) { + access::required("view", $item); + access::required("edit", $item); + + $albums = ORM::factory("item") + ->where(array("parent_id" => $parent->id, "type" => "album")) + ->orderby(array("title" => "ASC")) + ->find_all(); $v = new View("organize_tree.html"); $v->album = $parent; - if ($parent->id == $item->id) { - $v->selected = true; - $depth = 1; - } else { - $v->selected = false; - } - $v->children = array(); - $v->album_icon = "gBranchEmpty"; - if ($albums->count()) { - $v->album_icon = "ui-icon-plus"; + $v->selected = false; + $v->children = ""; + $v->album_icon = "ui-icon-plus"; + if (!$selected) { + $v->selected = $parent->id == $item->id; - if ($depth <= 1) { + if ($albums->count() && ($parent->id == 1 || $v->selected) ) { $v->album_icon = "ui-icon-minus"; - foreach ($albums as $album) { - $v->children[] = $this->_tree($item, $album, ++$depth); - } + } + + foreach ($albums as $album) { + $v->children .= $this->_tree($item, $album, $v->selected); } } - return $v; + return $v->__toString(); } + + } diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 7c2d9c5b..4568a707 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -41,14 +41,6 @@ padding-left: 1.2em; } -.gBranchText:hover { - border: 1px dashed #999; -} - -.gBranchEmpty { - visibility: hidden; -} - .gBranchSelected { background-color: #cfdeff !important; border-bottom: 1px solid #999 !important; diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 74b02569..e84afd03 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -37,6 +37,7 @@ * Dynamically initialize the organize dialog when it is displayed */ function _init(data) { + // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 $(".sf-menu li.sfHover ul").css("z-index", 70); @@ -63,8 +64,6 @@ $.gallery_reload(); }); - $(".gBranchText span").click(_collapse_or_expanded_tree); - //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); //$(".gBranchText").droppable(treeDroppable); //$(".gBranchText").click(organizeOpenFolder); @@ -110,31 +109,6 @@ $("#gOrganizeDialog").dialog("close"); }; - /** - * Open or close a branch. If the children is a div placeholder, replace with
      - */ - function _collapse_or_expanded_tree(event) { - var id = $(event.currentTarget).attr("ref"); - if ($(event.currentTarget).hasClass("ui-icon-minus")) { - $(event.currentTarget).removeClass("ui-icon-minus"); - $(event.currentTarget).addClass("ui-icon-plus"); - $("#gOrganizeChildren-" + id).hide(); - } else { - if ($("#gOrganizeChildren-" + id).is("div")) { - $("#gOrganizeChildren-" + id).remove(); - $("#gOrganizeBranch-" + id).after("
        "); - var url = $("#gOrganizeAlbumTree").attr("ref").replace("__ITEM_ID__", id); - $.get(url, function(data) { - $("#gOrganizeChildren-" + id).html(data); - $(".gBranchText span").click(_collapse_or_expanded_tree); - });; - } - $("#gOrganizeChildren-" + id).show(); - $(event.currentTarget).removeClass("ui-icon-plus"); - $(event.currentTarget).addClass("ui-icon-minus"); - } - } - })(jQuery); $("document").ready(function() { diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 1e6646e4..cf3fd478 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -12,7 +12,7 @@
      -
        "> +
      diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index d64410d8..28b45be0 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,11 +1,11 @@
    • + "> +
      gBranchText"> - - title) ?>
      @@ -13,9 +13,7 @@
        "> - - - +
    • -- cgit v1.2.3 From 397468c47b8fc3fefeb54ff19a73980ed1dd8c20 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 09:23:32 -0700 Subject: Revert "Checkpoint the organize module rewrite. At this point, it doesn't really do" This reverts commit a25f08d433d504a53763feb358a1aa7f5f798de6. --- modules/organize/controllers/organize.php | 507 ++++++++++++++- modules/organize/css/organize.css | 184 +++++- modules/organize/helpers/organize_task.php | 131 ++++ modules/organize/helpers/organize_theme.php | 3 +- modules/organize/js/organize.js | 697 ++++++++++++++++++--- modules/organize/js/organize_init.js | 29 + modules/organize/views/organize.html.php | 53 ++ modules/organize/views/organize_album.html.php | 17 + .../organize/views/organize_button_pane.html.php | 49 +- modules/organize/views/organize_dialog.html.php | 37 -- modules/organize/views/organize_edit.html.php | 14 + .../organize/views/organize_thumb_grid.html.php | 23 +- modules/organize/views/organize_tree.html.php | 20 +- 13 files changed, 1532 insertions(+), 232 deletions(-) create mode 100644 modules/organize/helpers/organize_task.php create mode 100644 modules/organize/js/organize_init.js create mode 100644 modules/organize/views/organize.html.php create mode 100644 modules/organize/views/organize_album.html.php delete mode 100644 modules/organize/views/organize_dialog.html.php create mode 100644 modules/organize/views/organize_edit.html.php (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index d7854c53..898be509 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -19,48 +19,54 @@ */ class Organize_Controller extends Controller { private static $_MICRO_THUMB_SIZE = 90; - private static $_MICRO_THUMB_PADDING = 10; + private static $_MICRO_THUMB_PADDING = 5; - function index($item_id) { + function index($item_id=1) { $item = ORM::factory("item", $item_id); $root = ($item->id == 1) ? $item : ORM::factory("item", 1); access::required("view", $item); access::required("edit", $item); - $v = new View("organize_dialog.html"); + $v = new View("organize.html"); $v->root = $root; $v->item = $item; - $v->album_tree = $this->_tree($item, $root); - $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item); + $v->album_tree = $this->tree($item, $root); $v->button_pane = new View("organize_button_pane.html"); - $buttons = (object)array("left" => array(), "middle" =>array(), "right" => array(), - "item" => $item); - module::event("organize_format_button_pane", $buttons); - - $v->button_pane->buttons = $buttons; print $v; } - function content($item_id, $offset=0) { + function content($item_id) { $item = ORM::factory("item", $item_id); access::required("view", $item); access::required("edit", $item); - $v = $this->_get_micro_thumb_grid($item, $offset); - print $v->__toString(); - } + $width = $this->input->get("width"); + $height = $this->input->get("height"); + $offset = $this->input->get("offset", 0); + $thumbsize = self::$_MICRO_THUMB_SIZE + 2 * self::$_MICRO_THUMB_PADDING; + $page_size = ceil($width / $thumbsize) * ceil($height / $thumbsize); - private function _get_micro_thumb_grid($item, $offset=0) { $v = new View("organize_thumb_grid.html"); - $v->item_id = $item->id; - $v->children = $item->children(25, $offset); + $v->children = $item->children($page_size, $offset); $v->thumbsize = self::$_MICRO_THUMB_SIZE; - $v->offset = $offset + 25; + $v->padding = self::$_MICRO_THUMB_PADDING; + $v->offset = $offset; + + print json_encode(array("count" => $v->children->count(), + "data" => $v->__toString())); + } + + function header($item_id) { + $item = ORM::factory("item", $item_id); + access::required("view", $item); + access::required("edit", $item); - return $v; + print json_encode( + array("title" => p::purify($item->title), + "description" => empty($item->description) ? "" : p::purify($item->description))); } - private function _tree($item, $parent, $selected=false) { + function tree($item, $parent) { access::required("view", $item); access::required("edit", $item); @@ -69,25 +75,466 @@ class Organize_Controller extends Controller { ->orderby(array("title" => "ASC")) ->find_all(); - $v = new View("organize_tree.html"); + $v = new View("organize_album.html"); $v->album = $parent; + $v->selected = $parent->id == $item->id; + + if ($albums->count()) { + $v->album_icon = $parent->id == 1 || $v->selected ? "ui-icon-minus" : "ui-icon-plus"; + } else { + $v->album_icon = ""; + } - $v->selected = false; $v->children = ""; - $v->album_icon = "ui-icon-plus"; - if (!$selected) { - $v->selected = $parent->id == $item->id; + foreach ($albums as $album) { + $v->children .= $this->tree($item, $album); + } + return $v->__toString(); + } + + function startTask($operation, $id) { + access::verify_csrf(); + $items = $this->input->post("item"); + + $item = ORM::factory("item", $id); + access::required("view", $item); + access::required("edit", $item); + + $definition = $this->_getOperationDefinition($item, $operation); + + $task_def = Task_Definition::factory() + ->callback("organize_task::run") + ->description($definition["description"]) + ->name($definition["name"]); + $task = task::create($task_def, array("items" => $items, "position" => 0, "target" => $id, + "type" => $definition["type"], + "batch" => ceil(count($items) * .1))); + // @todo If there is only one item then call task_run($task->id); Maybe even change js so + // we can call finish as well. + batch::start(); + print json_encode( + array("result" => "started", + "runningMsg" => $definition["runningMsg"], + "pauseMsg" => "
      {$definition['pauseMsg']}
      ", + "resumeMsg" => "
      {$definition['resumeMsg']}
      ", + "task" => array("id" => $task->id, + "percent_complete" => $task->percent_complete, + "type" => $task->get("type"), + "status" => $task->status, + "state" => $task->state, + "done" => $task->done))); + } + + function runTask($task_id) { + access::verify_csrf(); + + $task = task::run($task_id); + if (!$task->loaded || $task->owner_id != user::active()->id) { + access::forbidden(); + } + + print json_encode(array("result" => $task->done ? $task->state : "in_progress", + "task" => array("id" => $task->id, + "percent_complete" => $task->percent_complete, + "type" => $task->get("type"), + "post_process" => $task->get("post_process"), + "status" => $task->status, + "state" => $task->state, + "done" => $task->done))); + } + + function finishTask($task_id) { + access::verify_csrf(); + + $task = ORM::factory("task", $task_id); + if (!$task->loaded || $task->owner_id != user::active()->id) { + access::forbidden(); + } - if ($albums->count() && ($parent->id == 1 || $v->selected) ) { - $v->album_icon = "ui-icon-minus"; + if ($task->done) { + $item = ORM::factory("item", (int)$task->get("target")); + $type = $task->get("type"); + switch ($type) { + case "albumCover": + $task->status = t("Album cover set for '%album'", array("album" => $item->title)); + break; + case "delete": + $task->status = t("Selection deleted"); + break; + case "move": + $task->status = t("Move to '%album' completed", array("album" => $item->title)); + break; + case "rearrange": + try { + $item->sort_column = "weight"; + $item->save(); + $task->status = t("Rearrange for '%album' completed", array("album" => $item->title)); + } catch (Exception $e) { + $task->state = "error"; + $task->status = $e->getMessage(); + } + break; + case "rotateCcw": + case "rotateCw": + $task->status = t("Rotation completed"); + break; } + $task->save(); + } - foreach ($albums as $album) { - $v->children .= $this->_tree($item, $album, $v->selected); + batch::stop(); + print json_encode(array("result" => "success", + "task" => array( + "id" => $task->id, + "percent_complete" => $task->percent_complete, + "status" => $task->status, + "state" => $task->state, + "done" => $task->done))); + } + + function cancelTask($task_id) { + access::verify_csrf(); + + $task = ORM::factory("task", $task_id); + if (!$task->loaded || $task->owner_id != user::active()->id) { + access::forbidden(); + } + + if (!$task->done) { + $task->done = 1; + $task->state = "cancelled"; + $type = $task->get("type"); + switch ($type) { + case "move": + $task->status = t("Move to album was cancelled prior to completion"); + break; + case "rearrange": + $task->status = t("Rearrange album was cancelled prior to completion"); + case "rotateCcw": + case "rotateCw": + $task->status = t("Rotation was cancelled prior to completion"); + break; } + $task->save(); } - return $v->__toString(); + + batch::stop(); + print json_encode(array("result" => "success", + "task" => array( + "id" => $task->id, + "percent_complete" => $task->percent_complete, + "status" => $task->status, + "state" => $task->state, + "done" => $task->done))); + } + + function editForm() { + $event_parms = new stdClass(); + $event_parms->panes = array(); + $event_parms->itemids = $this->input->get("item"); + + // The following code should be done more dynamically i.e. use the event mechanism + if (count($event_parms->itemids) == 1) { + $item = ORM::factory("item") + ->in("id", $event_parms->itemids[0]) + ->find(); + + access::required("view", $item); + access::required("edit", $item); + + $event_parms->panes[] = array( + "label" => $item->is_album() ? t("Edit Album") : t("Edit Photo"), + "content" => organize::get_general_edit_form($item)); + + if ($item->is_album()) { + $event_parms->panes[] = array("label" => t("Sort Order"), + "content" => organize::get_sort_edit_form($item)); + } + } + + $event_parms->panes[] = array("label" => t("Manage Tags"), + "content" => organize::get_tag_form($event_parms->itemids)); + + $v = new View("organize_edit.html"); + $v->panes = $event_parms->panes; + print $v->render(); + } + + // Handlers for the album/photo edit. Probably should be in modules/gallery + public function general() { + access::verify_csrf(); + + $itemids = $this->input->post("item"); + $item = ORM::factory("item") + ->in("id", $itemids[0]) + ->find(); + access::required("view", $item); + access::required("edit", $item); + + $form = organize::get_general_edit_form($item); + if ($form->validate()) { + $orig = clone $item; + $item->title = $form->title->value; + $item->description = $form->description->value; + $item->rename($form->dirname->value); + $item->save(); + + if ($item->is_album()) { + log::success("content", "Updated album", "id\">view"); + $message = t("Saved album %album_title", array("album_title" => p::purify($item->title))); + } else { + log::success("content", "Updated photo", "id\">view"); + $message = t("Saved photo %photo_title", array("photo_title" => p::purify($item->title))); + } + print json_encode(array("form" => $form->__toString(), "message" => $message)); + } else { + print json_encode(array("form" => $form->__toString())); + } + } + + public function reset_general() { + $itemids = Input::instance()->get("item"); + $item = ORM::factory("item") + ->in("id", $itemids[0]) + ->find(); + access::required("view", $item); + access::required("edit", $item); + + print organize::get_general_edit_form($item); + } + + public function sort() { + access::verify_csrf(); + + $itemids = $this->input->post("item"); + $item = ORM::factory("item") + ->in("id", $itemids[0]) + ->find(); + access::required("view", $item); + access::required("edit", $item); + + $form = organize::get_sort_edit_form($item); + if ($form->validate()) { + $orig = clone $item; + $item->sort_column = $form->column->value; + $item->sort_order = $form->direction->value; + $item->save(); + + log::success("content", "Updated album", "id\">view"); + $message = t("Saved album %album_title", array("album_title" => p::purify($item->title))); + print json_encode(array("form" => $form->__toString(), "message" => $message)); + } else { + print json_encode(array("form" => $form->__toString())); + } + } + + public function reset_sort() { + $itemids = Input::instance()->get("item"); + $item = ORM::factory("item") + ->in("id", $itemids[0]) + ->find(); + access::required("view", $item); + access::required("edit", $item); + + print organize::get_sort_edit_form($item); + } + + public function edit_tags() { + access::verify_csrf(); + + $itemids = explode("|", $this->input->post("item")); + $form = organize::get_tag_form($itemids); + $old_tags = $form->tags->value; + if ($form->validate()) { + + $old_tags = preg_split("/[;,\s]+/", $old_tags); + sort($old_tags); + $new_tags = preg_split("/[;,\s]+/", $form->tags->value); + sort($new_tags); + + $HIGH_VALUE_STRING = "\256"; + for ($old_index = $new_index = 0;;) { + $old_tag = $old_index >= count($old_tags) ? $HIGH_VALUE_STRING : $old_tags[$old_index]; + $new_tag = $new_index >= count($new_tags) ? $HIGH_VALUE_STRING : $new_tags[$new_index]; + if ($old_tag == $HIGH_VALUE_STRING && $new_tag == $HIGH_VALUE_STRING) { + break; + } + $matches = array(); + $old_star = false; + if (preg_match("/(.*)(\*)$/", $old_tag, $matches)) { + $old_star = true; + $old_tag = $matches[1]; + } + $new_star = false; + if (preg_match("/(.*)(\*)$/", $new_tag, $matches)) { + $new_star = true; + $new_tag = $matches[1]; + } + if ($old_tag > $new_tag) { + // Its missing in the old list so add it + $this->_add_tag($new_tag, $itemids); + $new_index++; + } else if ($old_tag < $new_tag) { + // Its missing in the new list so its been removed + $this->_delete_tag($old_tag, $itemids); + $old_index++; + } else { + if ($old_star && !$new_star) { + // User wants tag to apply to all items, originally only on some of selected + $this->_update_tag($old_tag, $itemids); + } // Not changed ignore + $old_index++; + $new_index++; + } + } + } + print json_encode(array("form" => $form->__toString(), "message" => t("Tags updated"))); } + public function reset_edit_tags() { + $itemids = $this->input->get("item"); + + print organize::get_tag_form($itemids); + } + + private function _add_tag($new_tag, $itemids) { + // Super lame security stopgap. This code is going to get rewritten anyway. + foreach ($itemids as $item_id) { + $item = ORM::factory("item", $item_id); + access::required("view", $item); + access::required("edit", $item); + } + $tag = ORM::factory("tag") + ->where("name", $new_tag) + ->find(); + if ($tag->loaded) { + $tag->count += count($itemids); + } else { + $tag->name = $new_tag; + $tag->count = count($itemids); + } + $tag->save(); + + $db = Database::instance(); + foreach ($itemids as $item_id) { + $db->query("INSERT INTO {items_tags} SET item_id = $item_id, tag_id = {$tag->id};"); + } + } + + private function _delete_tag($new_tag, $itemids) { + // Super lame security stopgap. This code is going to get rewritten anyway. + foreach ($itemids as $item_id) { + $item = ORM::factory("item", $item_id); + access::required("view", $item); + access::required("edit", $item); + } + + $tag = ORM::factory("tag") + ->where("name", $new_tag) + ->find(); + $tag->count -= count($itemids); + if ($tag->count > 0) { + $tag->save(); + } else { + $tag->delete(); + } + + $ids = implode(", ", $itemids); + Database::instance()->query( + "DELETE FROM {items_tags} WHERE tag_id = {$tag->id} AND item_id IN ($ids);"); + } + + private function _update_tag($new_tag, $itemids) { + // Super lame security stopgap. This code is going to get rewritten anyway. + foreach ($itemids as $item_id) { + $item = ORM::factory("item", $item_id); + access::required("view", $item); + access::required("edit", $item); + } + + $tag = ORM::factory("tag") + ->where("name", $new_tag) + ->find(); + + $db = Database::instance(); + $ids = implode(", ", $itemids); + $result = $db->query( + "SELECT item_id FROM {items_tags} + WHERE tag_id = {$tag->id} + AND item_id IN ($ids)"); + + $add_items = array_fill_keys($itemids, 1); + foreach($result as $row) { + unset($add_items[$row->item_id]); + } + $add_items = array_keys($add_items); + $tag->count += count($add_items); + $tag->save(); + foreach ($add_items as $item_id) { + $db->query("INSERT INTO {items_tags} SET item_id = $item_id, tag_id = {$tag->id};"); + } + } + + private function _getOperationDefinition($item, $operation) { + switch ($operation) { + case "move": + return array("description" => + t("Move albums and photos to '%name'", array("name" => $item->title)), + "name" => t("Move to '%name'", array("name" => $item->title)), + "type" => "move", + "runningMsg" => t("Move in progress"), + "pauseMsg" => t("The move operation was paused"), + "resumeMsg" => t("The move operation was resumed")); + break; + + case "rearrange": + return array("description" => t("Rearrange the order of albums and photos"), + "name" => t("Rearrange: %name", array("name" => $item->title)), + "type" => "rearrange", + "runningMsg" => t("Rearrange in progress"), + "pauseMsg" => t("The rearrange operation was paused"), + "resumeMsg" => t("The rearrange operation was resumed")); + break; + + case "rotateCcw": + return array("description" => t("Rotate the selected photos counter clockwise"), + "name" => t("Rotate images in %name", array("name" => $item->title)), + "type" => "rotateCcw", + "runningMsg" => t("Rotate Counter Clockwise in progress"), + "pauseMsg" => t("The rotate operation was paused"), + "resumeMsg" => t("The rotate operation was resumed")); + break; + + case "rotateCw": + return array("description" => t("Rotate the selected photos clockwise"), + "name" => t("Rotate images in %name", array("name" => $item->title)), + "type" => "rotateCw", + "runningMsg" => t("Rotate Clockwise in progress"), + "pauseMsg" => t("The rotate operation was paused"), + "resumeMsg" => t("The rotate operation was resumed")); + break; + + case "delete": + return array("description" => t("Delete selected photos / albums"), + "name" => t("Delete images in %name", array("name" => $item->title)), + "type" => "delete", + "runningMsg" => t("Delete images in progress"), + "pauseMsg" => t("The delete operation was paused"), + "resumeMsg" => t("The delete operation was resumed")); + break; + + case "albumCover": + return array("description" => t("Reset Album Cover"), + "name" => t("Reset Album cover for %name", array("name" => $item->title)), + "type" => "albumCover", + "runningMsg" => t("Reset Album Cover in progress"), + "pauseMsg" => t("Reset album cover was paused"), + "resumeMsg" => t("Reset album cover was resumed")); + break; + + default: + throw new Exception("Operation '$operation' is not implmented"); + } + } } diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 4568a707..e58cd5a5 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -1,44 +1,41 @@ +/* @todo move to theme css */ /******************************************************************* * Dialog wide stylings */ -#gOrganizeDialog { - text-align: left; -} - -#gOrganize { - overflow: hidden; +#gMessage { + margin-bottom: .4em; } -#gOrganize .yui-u { - width: 75%; +#gMessage .gInfo { + background-color: transparent; + background-image: none; + padding-left: .4em; } -#gOrganize .yui-gf .first { - width: 25%; +#gOrganizeProgressDialog { + text-align: left; } -#gOrganize .yui-gf #gMessage { - margin-bottom: .4em; - width: 75%; +#gDialog .yui-gf div.first { + width: 20%; } -#gMessage .gInfo { - font-weight: bold; - padding-left: 2em; +#gDialog .yui-gf .yui-u { + width: 80%; } - /******************************************************************* * Album Tree styling */ #gOrganizeTreeContainer { - overflow: auto; + overflow-y: auto; margin: 0 !important; padding: 0 !important; } -#gOrganizeTreeContainer ul ul li { - padding-left: 1.2em; +#gOrganizeAlbumDescription { + height: 2em; + overflow-y: auto; } .gBranchSelected { @@ -48,21 +45,37 @@ padding: .3em 0; } +.gBranchDroppable { + border: 1px dotted; +} + +.gBranchText { + cursor: pointer; + width: auto; +} + .gBranchCollapsed { display: none; } -.gOrganizeBranch span { - cursor: pointer; +.gBranchEmpty { + visibility: hidden; } -.gBranchText { - cursor: pointer; - width: auto; +#gOrganizeTreeContainer ul ul li { + padding-left: 1.2em; } + /******************************************************************* * Album Panel Styles */ + +#gMicroThumbUnselectAll, +#gMicroThumbSelectAll { + font-size: 1em; + font-weight: bold; +} + #gMicroThumbPanel { margin: 0 !important; padding: 0 !important; @@ -70,27 +83,33 @@ border: 1px solid #999 !important; border-top: none !important; border-left: none !important; + margin-left: -1em !important; overflow-x: hidden; overflow-y: auto; } #gMicroThumbGrid { + padding: .5em; } .gMicroThumbContainer { -// padding: 0 .5em; -// opacity: .4; -} - -.gMicroThumb { display: block; float: left; -// font-size: .7em; + font-size: .7em; height: 9em; margin-bottom: 1em; margin-left: 1em; - text-align: center; + opacity: .4; + padding: 0 .5em; +} + +.gMicroThumb { + height: 9em; width: 9em; + background-color: #fff; + display: block; + float: left; + text-align: center; } #gMicroThumbPanel #gMicroThumbGrid .gAlbum { @@ -101,12 +120,35 @@ opacity: 1; } +.gMicroThumbContainer.ui-selected { + opacity: 1; +} + +#gDragHelper .gMicroThumbGrid { + background-color: transparent; + padding: 0; + overflow: visible; +} + +#gDragHelper .gMicroThumbContainer { + display: block; + margin: 0; + padding: 0; +} + +#gDragHelper .gMicroThumb { + background-color: transparent; + height: auto; + width: auto; +} + + /**************************************************************** * Organize Edit Drawer styling */ #gOrganizeEditDrawer { background-color: #13A; - width: 100% !important; + width: 90%; } #gOrganizeEditDrawerPanel { @@ -162,3 +204,79 @@ height: 30px; width: 15px; } + +#gOrganizeFormButtons { + bottom: 0.5em; +} + +#gOrganizeFormButtons .submit { + display: inline; + float: none; + left: 0.5em; + position: relative; +} + +/* yui-u gives 80% width, but then we wrap so do it ourselves */ +#gOrganizeEditForm { + float: right; + width: 79%; + // height: 100px; +} + +#gOrganizeFormThumbs { + overflow: hidden; +} + +#gOrganizeFormThumbs div { + margin: 0; + text-align: center; + background: transparent none repeat scroll 0 0; +} + +#gOrganizeFormThumbs .gMicroThumbContainer { + display: block; + float: left; + opacity: 1; + position: absolute; +} + +/**************************************************************** + * Organize Edit From tabs styling + */ +#gOrganizeEditForm.ui-tabs .ui-tabs-hide { + display: block !important; + left: -10000px; + position: absolute; +} + +#gOrganizeEditForm.ui-widget { + font-size: .75em; +} + +.gOrganizeEditPane { + height: 135px; + overflow-y: auto; +} + +.textbox, +.textarea { + border: 1px solid #e8e8e8; + border-top-color: #ccc; + border-left-color: #ccc; + color: #333; + width: 100%; +} + +.textarea { + height: 6em; +} + +.textbox { + height: 1.3em; + width: 50% +} + +.gTagGroup { + float:left; + margin: .5em; +} diff --git a/modules/organize/helpers/organize_task.php b/modules/organize/helpers/organize_task.php new file mode 100644 index 00000000..dc474818 --- /dev/null +++ b/modules/organize/helpers/organize_task.php @@ -0,0 +1,131 @@ +context); + $taskType = $context["type"]; + + try { + $target = ORM::factory("item", $context["target"]); + $total = count($context["items"]); + $stop = min($total - $context["position"], $context["batch"]); + $context["post_process"] = array(); + for ($offset = 0; $offset < $stop; $offset++) { + $current_id = $context["position"] + $offset; + $id = $context["items"][$current_id]; + switch ($taskType) { + case "move": + $source = ORM::factory("item", $id); + access::required("view", $source); + access::required("view", $target); + access::required("edit", $source); + access::required("edit", $target); + + item::move($source, $target); + break; + + case "rearrange": + $item = ORM::factory("item", $id); + access::required("view", $item); + access::required("edit", $item); + + Database::instance() + ->query("Update {items} set weight = {$context["position"]} where id=$id;"); + break; + + case "rotateCcw": + case "rotateCw": + $item = ORM::factory("item", $id); + access::required("view", $item); + access::required("edit", $item); + + if ($item->is_photo()) { + $context["post_process"]["reload"][] = + self::_do_rotation($item, $taskType == "rotateCcw" ? -90 : 90); + } + break; + + case "albumCover": + $item = ORM::factory("item", $id); + access::required("view", $item); + access::required("view", $item->parent()); + access::required("edit", $item->parent()); + + item::make_album_cover($item); + break; + + case "delete": + $item = ORM::factory("item", $id); + access::required("view", $item); + access::required("edit", $item); + + $item->delete(); + $context["post_process"]["remove"][] = array("id" => $id); + break; + + default: + throw new Exception("Task '$taskType' is not implemented"); + } + } + $context["position"] += $stop; + $task->state = "success"; + } catch(Exception $e) { + $task->status = $e->getMessage(); + $task->state = "error"; + $task->save(); + throw $e; + } + $task->context = serialize($context); + $total = count($context["items"]); + $task->percent_complete = $context["position"] / (float)$total * 100; + $task->done = $context["position"] == $total || $task->state == "error"; + } + + private static function _do_rotation($item, $degrees) { + // This code is copied from Quick_Controller::rotate + graphics::rotate($item->file_path(), $item->file_path(), array("degrees" => $degrees)); + + list($item->width, $item->height) = getimagesize($item->file_path()); + $item->resize_dirty= 1; + $item->thumb_dirty= 1; + $item->save(); + + graphics::generate($item); + + $parent = $item->parent(); + if ($parent->album_cover_item_id == $item->id) { + copy($item->thumb_path(), $parent->thumb_path()); + $parent->thumb_width = $item->thumb_width; + $parent->thumb_height = $item->thumb_height; + $parent->save(); + } + list ($height, $width) = $item->scale_dimensions(90); + $margin_top = (90 - $height) / 20; + + return array("src" => $item->thumb_url() . "?rnd=" . rand(), + "id" => $item->id, + "marginTop" => "{$margin_top}em", "width" => $width, "height" => $height); + } +} \ No newline at end of file diff --git a/modules/organize/helpers/organize_theme.php b/modules/organize/helpers/organize_theme.php index f01ab88b..e4feba2b 100644 --- a/modules/organize/helpers/organize_theme.php +++ b/modules/organize/helpers/organize_theme.php @@ -19,7 +19,8 @@ */ class organize_theme { static function head($theme) { - //$theme->script("organize_init.js"); + // @tdo remove the addition css and organize.js (just here to test) + $theme->script("organize_init.js"); $theme->script("organize.js"); $theme->css("organize.css"); } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index e84afd03..12d8a5b5 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -1,116 +1,621 @@ -(function($) { - $.fn.organize = function(options) { - var size = $.getViewportSize(); - var height = size.height() - 100; // Leave 50 pixels on the top and bottom of the dialog - var width = size.width() - 100; // Leave 50 pixels on the left and right of the dialog - var opts = $.extend({}, $.fn.organize.defaults, {width: width, height: height}, options); - return this.each(function() { - $(this).click(function(event) { - var href = event.target.href; - var size = $.getViewportSize(); - - $("body").append('
      '); - - $("#gOrganizeDialog").dialog(opts); - // Pass the approx height and width of the thumb grid to optimize thumb retrieval - $.get(href, _init); - return false; +/* + * @todo Trap resize of dialog and resize the child areas (tree, grid and edit form) + */ +var url; +var paused = false; +var task = null; +var transitItems = []; +var heightMicroThumbPanel; + +// ************************************************************************** +// JQuery UI Widgets +// Draggable +var draggable = { + handle: ".gMicroThumbContainer.ui-selected", + revert: true, + zindex: 2000, + distance: 10, + helper: function(event, ui) { + if (!$(event.currentTarget).hasClass("ui-selected")) { + $(event.currentTarget).addClass("ui-selected"); + setDrawerButtonState(); + } + $("#gMicroThumbPanel").append("
        "); + var beginTop = event.pageY; + var beginLeft = event.pageX; + var zindex = $(".gMicroThumbContainer").draggable("option", "zindex"); + $("#gDragHelper").css('top', event.pageY - 22.5); + $("#gDragHelper").css('left', event.pageX + 22.5); + var placeHolder = $(this).clone(); + $(placeHolder).attr("id", "gPlaceHolder"); + $(placeHolder).css("visibility", "hidden"); + $(placeHolder).removeClass("ui-selected"); + $(placeHolder).removeClass("ui-draggable"); + $(this).after(placeHolder); + + $("li.ui-selected").each(function(i) { + var clone = $(this).clone(); + $(clone).attr("id", "drag_clone_" + $(this).attr("ref")); + $("#gDragHelper ul").append(clone); + $(clone).css("position", "absolute"); + $(clone).css("top", beginTop); + $(clone).css("left", beginLeft); + $(clone).css("z-index", zindex--); + $(this).hide(); + + var children = $(clone).find(".gMicroThumb .gThumbnail"); + var width = new String(children.css("width")).replace(/[^0-9]/g,"") * .5; + var height = new String(children.css("height")).replace(/[^0-9]/g,"") * .5; + var marginTop = new String(children.css("margin-top")).replace(/[^\.0-9]/g,"") * .5; + children.attr("width", width); + children.attr("height", height); + children.css("margin-top", marginTop); + if (i < 9) { + beginTop -= 5; + beginLeft += 5; + } + }); + return $("#gDragHelper"); + }, + stop: function(event, ui) { + $("#gDragHelper li").each(function(i) { + $("#thumb_" + $(this).attr("ref")).show(); + }); + $(".gMicroThumbContainer.ui-selected").css("z-index", null); + $("#gDragHelper").remove(); + $("#gPlaceHolder").remove(); + } +}; + +// Thumbnail Grid Droppable +var thumbDroppable = { + tolerance: "pointer", + over: function(event, ui) { + $("#gPlaceHolder").show(); + }, + out: function(event, ui) { + $("#gPlaceHolder").hide(); + }, + drop: function(event, ui) { + $("#gDragHelper").hide(); + $("#gPlaceHolder").hide(); + var newOrder = ""; + $("#gMicroThumbGrid .gMicroThumbContainer").each(function(i) { + if ($(this).attr("id") == "gPlaceHolder") { + $("#gDragHelper li").each(function(i) { + newOrder += "&item[]=" + $(this).attr("ref"); + }); + } else if ($(this).css("display") != "none") { + newOrder += "&item[]=" + $(this).attr("ref"); + } else { + // If its not displayed then its one of the ones being moved so ignore. + } + }); + $("#gDragHelper li").each(function(i) { + $("#gPlaceHolder").before($("#thumb_" + $(this).attr("ref")).show()); + }); + $.ajax({ + data: newOrder, + dataType: "json", + success: operationCallback, + type: "POST", + url: get_organize_url("organize/startTask/rearrange", {item_id: item_id}) + }); + } +}; + +// Album Tree Droppable +var treeDroppable = { + tolerance: "pointer", + greedy: true, + hoverClass: "gBranchDroppable", + drop: function(event, ui) { + $("#gDragHelper").hide(); + var targetItemId = $(this).attr("ref"); + if ($(this).hasClass("gBranchSelected")) { + $("#gMessage").empty().append(INVALID_DROP_TARGET); + ui.draggable.trigger("stop", event); + return false; + } + var postData = serializeItemIds("#gDragHelper li"); + var okToMove = true; + $("#gDragHelper li").each(function(i) { + okToMove &= targetItemId != $(this).attr("ref"); + }); + if (!okToMove) { + $("#gMessage").empty().append(INVALID_DROP_TARGET); + ui.draggable.trigger("stop", event); + return false; + } + $("#gDragHelper li").each(function(i) { + $("#thumb_" + $(this).attr("ref")).remove(); + }); + $.ajax({ + data: postData, + dataType: "json", + success: operationCallback, + type: "POST", + url: get_organize_url("organize/startTask/move", {item_id: targetItemId}) + }); + return true; + } +}; + +// Selectable +var selectable = { + filter: ".gMicroThumbContainer", + selected: function(event, ui) { + setDrawerButtonState(); + }, + unselected: function(event, ui) { + setDrawerButtonState(); + }, + stop: function(event, ui) { + getEditForm(); + } +}; + +// ************************************************************************** +// Event Handlers +// MicroThumbContainer mouseup +var onMicroThumbContainerMouseup = function(event) { + // For simplicity always remove the ui-selected class. If it was unselected + // it will get added back + $(this).toggleClass("ui-selected"); + + setDrawerButtonState(); + if ($("#gMicroThumbGrid li.ui-selected").length > 0) { + getEditForm(); + } +}; + +// MicroThumbContainer mousemove +var onMicroThumbContainerMousemove = function(event) { + if ($("#gDragHelper").length > 0 && $(this).attr("id") != "gPlaceHolder") { + if (event.pageX < $(this).offset().left + $(this).width() / 2) { + $(this).before($("#gPlaceHolder")); + } else { + $(this).after($("#gPlaceHolder")); + } + var container = $("#gMicroThumbPanel").get(0); + var scrollHeight = container.scrollHeight; + var scrollTop = container.scrollTop; + var height = $(container).height(); + if (event.pageY > height + scrollTop) { + container.scrollTop = this.offsetTop; + } else if (event.pageY < scrollTop) { + container.scrollTop -= height; + } + } +}; + +// Handle click events on the buttons on the drawer handle +function drawerHandleButtonsClick(event) { + event.preventDefault(); + if (!$(this).attr("disabled")) { + var operation = $(this).attr("ref"); + switch (operation) { + case "edit": + case "close": + $("#gOrganizeEditDrawerPanel").animate( + {"height": "toggle", "display": "block"}, + {duration: "fast", + complete: function() { + setSelectedThumbs(); + if (operation == "close") { + $("#gOrganizeEditHandleButtonsLeft a[ref='edit']").css("display", "inline-block"); + $("#gOrganizeEditHandleButtonsLeft a[ref='close']").css("display", "none"); + $("#gOrganizeEditHandleButtonsMiddle a").css("display", "none"); + } else { + $("#gOrganizeEditHandleButtonsLeft a[ref='edit']").css("display", "none"); + $("#gOrganizeEditHandleButtonsLeft a[ref='close']").css("display", "inline-block"); + $("#gOrganizeEditHandleButtonsMiddle a").css("display", "inline-block"); + } + }, + step: function() { + $("#gMicroThumbPanel").height(heightMicroThumbPanel - $(this).height()); + } + }); + break; + case "select-all": + $("#gMicroThumbGrid li").addClass("ui-selected"); + $("#gMicroThumbSelectAll").hide(); + $("#gMicroThumbUnselectAll").show(); + setDrawerButtonState(); + getEditForm(); + break; + case "unselect-all": + $("#gMicroThumbGrid li").removeClass("ui-selected"); + $("#gMicroThumbSelectAll").show(); + $("#gMicroThumbUnselectAll").hide(); + setDrawerButtonState(); + break; + case "done": + $("#gDialog").dialog("close"); + break; + case "submit": + var currentTab = $("#gOrganizeEditForm").tabs("option", "selected"); + var form = $("#pane-"+currentTab+" form"); + var url = $(form).attr("action") + .replace("__FUNCTION__", $(form).attr("ref")); + $.ajax({ + data: $(form).serialize(), + dataType: "json", + success: function (data, textStatus) { + $("#pane-"+currentTab).children("form").replaceWith(data.form); + if (data.message) { + $("#gMessage").empty().append("
        " + data.message + "
        "); + } + }, + type: "POST", + url: url + }); + break; + case "reset": + currentTab = $("#gOrganizeEditForm").tabs("option", "selected"); + form = $("#pane-"+currentTab+" form"); + $.ajax({ + data: serializeItemIds("#gMicroThumbPanel li.ui-selected"), + dataType: "html", + success: function (data, textStatus) { + $("#pane-"+currentTab + " form").replaceWith(data); + }, + type: "GET", + url: $(form).attr("action").replace("__FUNCTION__", "reset_" + $(form).attr("ref")) }); + break; + case "delete": + if (!confirm(CONFIRM_DELETE)) { + break; + } + default: + $.ajax({ + data: serializeItemIds("#gMicroThumbPanel li.ui-selected"), + dataType: "json", + success: operationCallback, + type: "POST", + url: get_organize_url("organize/startTask/" + operation, {item_id: item_id}) + }); + break; + } + } +}; + +// ************************************************************************** +// AJAX Callbacks +// MicroThumbContainer click +var getMicroThumbsCallback = function(json, textStatus) { + if (json.count > 0) { + $("#gMicroThumbGrid").append(json.data); + retrieveMicroThumbs(); + $(".gMicroThumbContainer").mouseup(onMicroThumbContainerMouseup); + $(".gMicroThumbContainer").mousemove(onMicroThumbContainerMousemove); + $(".gMicroThumbContainer").draggable(draggable); + } +}; + +var operationCallback = function (data, textStatus) { + var done = false; + if (!paused) { + createProgressDialog(data.runningMsg); + task = data.task; + task.pauseMsg = data.pauseMsg; + task.resumeMsg = data.resumeMsg; + done = data.task.done; + } + $(".gMicroThumbContainer").draggable("disable"); + paused = false; + while (!done && !paused) { + $.ajax({async: false, + success: function(data, textStatus) { + $(".gProgressBar").progressbar("value", data.task.percent_complete); + done = data.task.done; + if (data.task.post_process.reload) { + $.each(data.task.post_process.reload, function() { + var selector = "#gMicroThumb-" + this.id + " img"; + $(selector).attr("height", this.height); + $(selector).attr("width", this.width); + $(selector).attr("src", this.src); + $(selector).css("margin-top", this.marginTop); + }); + } + if (data.task.post_process.remove) { + $.each(data.task.post_process.remove, function() { + $("#thumb_" + this.id).remove(); + }); + } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + paused = true; + displayAjaxError(XMLHttpRequest.responseText); + }, + dataType: "json", + type: "POST", + url: get_organize_url("organize/runTask", {task_id: task.id}) }); - }; + } + if (!paused) { + $("#gOrganizeProgressDialog").dialog("destroy").remove(); + $.ajax({async: false, + success: function(data, textStatus) { + setDrawerButtonState(); + task = null; + $("#gMessage").empty().append("
        " + data.task.status + "
        "); + }, + dataType: "json", + type: "POST", + url: get_organize_url("organize/finishTask", {task_id: task.id}) + }); + } + $(".gMicroThumbContainer").draggable("enable"); +}; - $.fn.organize.defaults = { - autoOpen: false, - modal: true, - resizable: false, - minWidth: 600, - minHeight: 500, - position: "center", - close: function () { - $("#gOrganizeDialog").trigger("organize_close"); - $("#gOrganizeDialog").dialog("destroy").remove(); - }, - zIndex: 75 - }; +// ************************************************************************** + +/** + * Dynamically initialize the organize dialog when it is displayed + */ +function organize_dialog_init() { + var size = getViewportSize(); + heightMicroThumbPanel = size.height() - 100; + var width = size.width() - 100; + + // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 + $(".sf-menu li.sfHover ul").css("z-index", 70); + + $("#gDialog").dialog("option", "width", width); + $("#gDialog").dialog("option", "height", heightMicroThumbPanel); + + $("#gDialog").dialog("open"); + if ($("#gDialog h1").length) { + $("#gDialog").dialog('option', 'title', $("#gDialog h1:eq(0)").html()); + } else if ($("#gDialog fieldset legend").length) { + $("#gDialog").dialog('option', 'title', $("#gDialog fieldset legend:eq(0)").html()); + } + + $("#gDialog").bind("organize_close", function(target) { + $.gallery_reload(); + }); + + heightMicroThumbPanel -= 2 * parseFloat($("#gDialog").css("padding-top")); + heightMicroThumbPanel -= 2 * parseFloat($("#gDialog").css("padding-bottom")); + heightMicroThumbPanel -= $("#gMicroThumbPanel").position().top; + heightMicroThumbPanel -= $("#gDialog #ft").height(); + heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").height(); + heightMicroThumbPanel = Math.round(heightMicroThumbPanel); + + $("#gMicroThumbPanel").height(heightMicroThumbPanel); + $("#gOrganizeTreeContainer").height(heightMicroThumbPanel); + + $(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); + $(".gBranchText").droppable(treeDroppable); + $(".gBranchText").click(organizeOpenFolder); + retrieveMicroThumbs(item_id); + //showLoading("#gDialog"); - /** - * Dynamically initialize the organize dialog when it is displayed - */ - function _init(data) { + $("#gMicroThumbPanel").droppable(thumbDroppable); + $("#gMicroThumbPanel").selectable(selectable); + $("#gOrganizeEditDrawerHandle a").click(drawerHandleButtonsClick); +} - // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 - $(".sf-menu li.sfHover ul").css("z-index", 70); +function retrieveMicroThumbs() { + var offset = $("#gMicroThumbGrid li").length; + if (url == null) { + var grid_width = $("#gMicroThumbPanel").width(); + url = $("#gMicroThumbPanel").attr("ref"); + url = url.replace("__WIDTH__", grid_width); + url = url.replace("__HEIGHT__", heightMicroThumbPanel); + } + var url_data = url.replace("__OFFSET__", offset); + url_data = url_data.replace("__ITEM_ID__", item_id); + $.getJSON(url_data, getMicroThumbsCallback); +} - $("#gOrganizeDialog").html(data); - $("#gOrganizeDialog").dialog("open"); +function organizeToggleChildren(event) { + var id = $(this).attr("ref"); + var span_children = $("#gOrganizeChildren-" + id); + if ($(this).hasClass("ui-icon-plus")) { + $(this).removeClass("ui-icon-plus"); + $(this).addClass("ui-icon-minus"); + $("#gOrganizeChildren-" + id).removeClass("gBranchCollapsed"); + } else { + $(this).removeClass("ui-icon-minus"); + $(this).addClass("ui-icon-plus"); + $("#gOrganizeChildren-" + id).addClass("gBranchCollapsed"); + } + event.preventDefault(); +} - var heightMicroThumbPanel = $("#gOrganizeDialog").innerHeight(); - heightMicroThumbPanel -= 2 * parseFloat($("#gOrganizeDialog").css("padding-bottom")); - heightMicroThumbPanel -= $("#gMessage").outerHeight(); - heightMicroThumbPanel = Math.floor(heightMicroThumbPanel); - $("#gOrganizeTreeContainer").height(heightMicroThumbPanel); +function organizeOpenFolder(event) { + var selected = $(".gBranchSelected"); + if ($(selected).attr("id") != $(this).attr("id")) { + $(selected).removeClass("gBranchSelected"); + $(this).addClass("gBranchSelected"); + item_id = $(this).attr("ref"); + $("#gMicroThumbGrid").empty(); + retrieveMicroThumbs(); + } + event.preventDefault(); +} - heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").outerHeight(); - $("#gMicroThumbPanel").height(heightMicroThumbPanel); +function get_organize_url(uri, parms) { + var url = rearrangeUrl; + url = url.replace("__URI__", uri); + url = url.replace("__ITEM_ID__", !parms.item_id ? "" : parms.item_id); + url += (parms.item_id && parms.task_id) ? "/" : ""; + url = url.replace("__TASK_ID__", !parms.task_id ? "" : parms.task_id); + return url; +} - if ($("#gOrganizeDialog h1").length) { - $("#gOrganizeDialog").dialog('option', 'title', $("#gOrganizeDialog h1:eq(0)").html()); - } else if ($("#gOrganizeDialog fieldset legend").length) { - $("#gOrganizeDialog").dialog('option', 'title', $("#gOrganizeDialog fieldset legend:eq(0)").html()); +/** + * Set the enabled/disabled state of the buttons. The album cover is only enabled if + * there is only 1 image selected + */ +function setDrawerButtonState() { + $("#gOrganizeFormThumbStack").empty(); + $("#gOrganizeEditForm").empty(); + var selectedCount = $("#gMicroThumbGrid li.ui-selected").length; + if (selectedCount) { + $("#gOrganizeEditHandleButtonsLeft a").removeAttr("disabled"); + $("#gOrganizeEditHandleButtonsLeft a").removeClass("ui-state-disabled"); + + if (selectedCount > 1) { + $("#gOrganizeEditHandleButtonsLeft a[ref='albumCover']").attr("disabled", true); + $("#gOrganizeEditHandleButtonsLeft a[ref='albumCover']").addClass("ui-state-disabled"); + } + setSelectedThumbs(); + } else { + if ($("#gOrganizeEditDrawerPanel::visible").length) { + $("#gOrganizeEditHandleButtonsLeft a[ref='close']").trigger("click"); } + $("#gOrganizeEditHandleButtonsLeft a").attr("disabled", true); + $("#gOrganizeEditHandleButtonsLeft a").addClass("ui-state-disabled"); + } +} - $("#gOrganizeDialog #gMicroThumbDone").click(_dialog_close); - $("#gOrganizeDialog").bind("organize_close", function(target) { - $.gallery_reload(); +function setSelectedThumbs() { + if (!$("#gOrganizeEditDrawerPanel::visible").length) { + return; + } + var position = $("#gOrganizeFormThumbStack").position(); + var beginLeft = position.left; + var beginTop = 50; + var zindex = 2000; + $("li.ui-selected").each(function(i) { + var clone = $(this).clone(); + $(clone).attr("id", "edit_clone_" + $(this).attr("ref")); + $("#gOrganizeFormThumbStack").append(clone); + $(clone).removeClass("ui-draggable"); + $(clone).removeClass("ui-selected"); + $(clone).css("margin-top", beginTop); + $(clone).css("left", beginLeft); + $(clone).css("z-index", zindex--); + + if (i < 9) { + beginTop -= 5; + beginLeft += 5; + } + }); +} + +function getEditForm() { + if ($("#gMicroThumbGrid li.ui-selected").length > 0) { + var postData = serializeItemIds("li.ui-selected"); + var url_data = get_organize_url("organize/editForm", {}) + postData; + $.get(url_data, function(data, textStatus) { + $("#gOrganizeEditForm").tabs("destroy"); + $("#gOrganizeEditForm").html(data); + if ($("#gOrganizeEditForm ul li").length) { + $("#gOrganizeEditForm").tabs(); + $("#gOrganizeEditHandleButtonsMiddle a").removeAttr("disabled"); + $("#gOrganizeEditHandleButtonsMiddle a").removeClass("ui-state-disabled"); + } else { + $("#gOrganizeEditHandleButtonsMiddle a").attr("disabled", true); + $("#gOrganizeEditHandleButtonsMiddle a").addClass("ui-state-disabled"); + } }); + } else { + $("#gOrganizeEditForm").tabs("destroy"); + $("#gOrganizeEditForm").empty(); + } +} - //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); - //$(".gBranchText").droppable(treeDroppable); - //$(".gBranchText").click(organizeOpenFolder); - //retrieveMicroThumbs(item_id); - //showLoading("#gOrganizeDialog"); +function serializeItemIds(selector) { + var postData = ""; + $(selector).each(function(i) { + postData += "&item[]=" + $(this).attr("ref"); + }); - //$("#gMicroThumbPanel").droppable(thumbDroppable); - //$("#gMicroThumbPanel").selectable(selectable); - //$("#gOrganizeEditDrawerHandle a").click(drawerHandleButtonsClick); + return postData; +} - $(window).bind("resize", _size_dialog); - }; +function submitCurrentForm(event) { + console.log("submitCurrentForm"); + return false; +} - /** - * Dynamically initialize the organize dialog when it is displayed - */ - function _size_dialog(event) { - var size = $.getViewportSize(); - var h = $("#gOrganizeDialog").dialog("option", "minHeight"); - var sh = size.height() - 100; - var height = Math.max(sh, h); - var w = $("#gOrganizeDialog").dialog("option", "minWidth"); - var sw = size.width() - 100; - var width = Math.max(w, sw); - - $("#gOrganizeDialog").parent().css("height", height); - $("#gOrganizeDialog").parent().css("width", width); - $("#gOrganizeDialog").parent().css("left", "50px"); - $("#gOrganizeDialog").parent().css("top", "50px"); - - var heightMicroThumbPanel = height - 50; - heightMicroThumbPanel -= 2 * parseFloat($("#gOrganizeDialog").css("padding-bottom")); - heightMicroThumbPanel -= $("#gMessage").outerHeight(); - heightMicroThumbPanel = Math.floor(heightMicroThumbPanel); - $("#gOrganizeTreeContainer").height(heightMicroThumbPanel); - - heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").outerHeight(); - $("#gMicroThumbPanel").height(heightMicroThumbPanel); - }; +function resetCurrentForm(event) { + console.log("resetCurrentForm"); + return false; +} - function _dialog_close(event) { - event.preventDefault(); - $("#gOrganizeDialog").dialog("close"); +function createProgressDialog(title) { + $("body").append("
        " + + "
        " + + "" + + "" + + "" + + "
        "); + $("#gOrganizeProgressDialog").dialog({ + autoOpen: true, + autoResize: false, + modal: true, + resizable: false, + title: title + }); + + $(".gProgressBar").progressbar(); + $("#gOrganizeTaskPause").click(function(event) { + paused = true; + $("#gOrganizeTaskPause").hide(); + $("#gOrganizeTaskResume").show(); + $("#gOrganizeTaskCancel").show(); + $("#gMessage").empty().append(task.pauseMsg); + }); + $("#gOrganizeTaskResume").click(function(event) { + $("#gOrganizeTaskPause").show(); + $("#gOrganizeTaskResume").hide(); + $("#gOrganizeTaskCancel").hide(); + $("#gMessage").empty().append(task.resumeMsg); + operationCallback(); + //startRearrangeCallback(); + }); + $("#gOrganizeTaskCancel").click(function(event) { + $("#gOrganizeTaskPause").show(); + $("#gOrganizeTaskResume").hide(); + $("#gOrganizeTaskCancel").hide(); + + $.ajax({async: false, + success: function(data, textStatus) { + task = null; + paused = false; + transitItems = []; + $("#gMessage").empty().append("
        " + data.task.status + "
        "); + $("#gOrganizeProgressDialog").dialog("destroy").remove(); + }, + dataType: "json", + type: "POST", + url: get_organize_url("organize/cancelTask", {task_id: task.id}) + }); + }); +} + +// ************************************************************************** +// Functions that should probably be in a gallery namespace +function getViewportSize() { + return { + width : function() { + return window.innerWidth + || document.documentElement && document.documentElement.clientWidth + || document.body.clientWidth; + }, + height : function() { + return window.innerHeight + || document.documentElement && document.documentElement.clientHeight + || document.body.clientHeight; + } }; +} -})(jQuery); +function displayAjaxError(error) { + $("body").append("
        " + error + "
        "); -$("document").ready(function() { - $("#gOrganizeLink").organize(); -}); + $("#gAjaxError").dialog({ + autoOpen: true, + autoResize: false, + modal: true, + resizable: true, + width: 610, + height: $("#gDialog").height() + }); +} diff --git a/modules/organize/js/organize_init.js b/modules/organize/js/organize_init.js new file mode 100644 index 00000000..ed036fdb --- /dev/null +++ b/modules/organize/js/organize_init.js @@ -0,0 +1,29 @@ +$("document").ready(function() { + $("#gOrganizeLink").click(function(event) { + event.preventDefault(); + var href = event.target.href; + + $("body").append('
        '); + + $("#gDialog").dialog({ + autoOpen: false, + autoResize: false, + modal: true, + resizable: false, + close: function () { + $("#gDialog").trigger("organize_close"); + $("#gDialog").dialog("destroy").remove(); + }, + zIndex: 75 + }); + + //showLoading("#gDialog"); + + $.get(href, function(data) { + $("#gDialog").html(data); + }); + return false; + }); +}); + + diff --git a/modules/organize/views/organize.html.php b/modules/organize/views/organize.html.php new file mode 100644 index 00000000..1686d255 --- /dev/null +++ b/modules/organize/views/organize.html.php @@ -0,0 +1,53 @@ + + + +
        + p::purify($item->title))) ?> +
        +
        +
        +
        +
        +

        +
        +
        +
        +
        +
        +
        +
        + +
        +
        "> +
          +
          +
          +
          +
          +
            +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          diff --git a/modules/organize/views/organize_album.html.php b/modules/organize/views/organize_album.html.php new file mode 100644 index 00000000..ae2d5d51 --- /dev/null +++ b/modules/organize/views/organize_album.html.php @@ -0,0 +1,17 @@ + +
            +
          • + "> + + +
            gBranchText"> + title) ?> +
            +
            "> + +
            +
          • +
          diff --git a/modules/organize/views/organize_button_pane.html.php b/modules/organize/views/organize_button_pane.html.php index 8eced107..c5839a44 100644 --- a/modules/organize/views/organize_button_pane.html.php +++ b/modules/organize/views/organize_button_pane.html.php @@ -1,5 +1,50 @@ + +
          - + + +
          diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php deleted file mode 100644 index cf3fd478..00000000 --- a/modules/organize/views/organize_dialog.html.php +++ /dev/null @@ -1,37 +0,0 @@ - -
          -

          p::purify($item->title))) ?>

          -
          -
          -
          -

          -
          -
          -
          -
          -
          -
          -
          -
            - -
          -
          -
          -
          "> -
            - -
          -
          -
          -
          -
          -
          - -
          -
          -
          -
          -
          -
          - diff --git a/modules/organize/views/organize_edit.html.php b/modules/organize/views/organize_edit.html.php new file mode 100644 index 00000000..1adf290f --- /dev/null +++ b/modules/organize/views/organize_edit.html.php @@ -0,0 +1,14 @@ + +
            + $pane): ?> +
          • + +
          + + 0): ?> + $pane): ?> +
          + + +
          + \ No newline at end of file diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index e6b7aec0..c80696ad 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,19 +1,12 @@ $child): ?> - - is_album()): ?> - - -
        • + +is_album()): ?> + + +
        • +
          thumb_img(array("class" => "gThumbnail"), $thumbsize, true) ?> -
        • +
          + -= 25): ?> - - \ No newline at end of file diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 28b45be0..d2cdd957 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,20 +1,4 @@ -
        • - "> - - -
          gBranchText"> - title) ?> -
          - -
          - -
            "> - -
          - -
        • + $child): ?> + -- cgit v1.2.3 From 9f396178cedc96abb282e72ff0e843e255c8225a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 09:24:27 -0700 Subject: Revert "Allow a theme to override the page refresh mechanism. Create a new" This reverts commit 1f014aae6c16bbda62d8f5937180f11ccb0eb1b1. --- lib/gallery.dialog.js | 4 +- lib/gallery.panel.js | 4 +- lib/gallery.reload.js | 16 ----- modules/gallery/js/quick.js | 4 +- modules/gallery/tests/xss_data.txt | 68 +++++++++++----------- .../views/admin_maintenance_show_log.html.php | 2 +- .../gallery/views/admin_maintenance_task.html.php | 2 +- modules/organize/js/organize.js | 2 +- .../views/server_add_tree_dialog.html.php | 2 +- modules/tag/js/tag.js | 2 +- themes/admin_default/views/admin.html.php | 2 - themes/default/views/page.html.php | 2 - 12 files changed, 44 insertions(+), 66 deletions(-) delete mode 100644 lib/gallery.reload.js (limited to 'modules/organize') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 0efcf120..74c2f20e 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -25,9 +25,9 @@ function ajaxify_dialog() { } if (data.result == "success") { if (data.location) { - $.gallery_location(data.location); + window.location = data.location; } else { - $.gallery_reload(); + window.location.reload(); } } } diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js index 26be11ad..022e4878 100644 --- a/lib/gallery.panel.js +++ b/lib/gallery.panel.js @@ -40,9 +40,9 @@ function togglePanel(element, on_success) { if (on_success) { on_success(); } else if (data.location) { - $.gallery_location(data.location); + window.location = data.location; } else { - $.gallery_reload(); + window.location.reload(); } } } diff --git a/lib/gallery.reload.js b/lib/gallery.reload.js deleted file mode 100644 index 2c8752a0..00000000 --- a/lib/gallery.reload.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -(function ($) { - $.gallery_reload = function() { - window.location.reload(); - }; -})(jQuery); - -// Vertically align a block element's content -(function ($) { - $.gallery_location = function(location) { - window.location = location; - }; -})(jQuery); diff --git a/modules/gallery/js/quick.js b/modules/gallery/js/quick.js index 4753808e..fda6470f 100644 --- a/modules/gallery/js/quick.js +++ b/modules/gallery/js/quick.js @@ -67,9 +67,9 @@ var quick_do = function(cont, pane, img) { img.css("margin-top", 0); } } else if (data.location) { - $.gallery_location(data.location); + window.location = data.location; } else if (data.reload) { - $.gallery_reload(); + window.location.reload(); } } }); diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 29d223b7..0e118ce7 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -496,25 +496,24 @@ themes/admin_default/views/admin.html.php 20 DIRTY $theme->s themes/admin_default/views/admin.html.php 21 DIRTY $theme->script("jquery.form.js") themes/admin_default/views/admin.html.php 22 DIRTY $theme->script("jquery-ui.js") themes/admin_default/views/admin.html.php 23 DIRTY $theme->script("gallery.common.js") -themes/admin_default/views/admin.html.php 25 DIRTY $theme->script("gallery.reload.js") -themes/admin_default/views/admin.html.php 30 DIRTY $theme->script("gallery.dialog.js") -themes/admin_default/views/admin.html.php 31 DIRTY $theme->script("superfish/js/superfish.js") -themes/admin_default/views/admin.html.php 32 DIRTY $theme->script("jquery.dropshadow.js") -themes/admin_default/views/admin.html.php 33 DIRTY $theme->script("ui.init.js") -themes/admin_default/views/admin.html.php 35 DIRTY $theme->admin_head() -themes/admin_default/views/admin.html.php 38 DIRTY $theme->body_attributes() -themes/admin_default/views/admin.html.php 39 DIRTY $theme->admin_page_top() -themes/admin_default/views/admin.html.php 45 DIRTY $theme->site_status() -themes/admin_default/views/admin.html.php 47 DIRTY $theme->admin_header_top() -themes/admin_default/views/admin.html.php 50 DIRTY $csrf -themes/admin_default/views/admin.html.php 56 DIRTY $theme->admin_menu() -themes/admin_default/views/admin.html.php 58 DIRTY $theme->admin_header_bottom() -themes/admin_default/views/admin.html.php 64 DIRTY $theme->messages() -themes/admin_default/views/admin.html.php 65 DIRTY $content -themes/admin_default/views/admin.html.php 71 DIRTY $sidebar -themes/admin_default/views/admin.html.php 76 DIRTY $theme->admin_footer() -themes/admin_default/views/admin.html.php 78 DIRTY $theme->admin_credits() -themes/admin_default/views/admin.html.php 82 DIRTY $theme->admin_page_bottom() +themes/admin_default/views/admin.html.php 28 DIRTY $theme->script("gallery.dialog.js") +themes/admin_default/views/admin.html.php 29 DIRTY $theme->script("superfish/js/superfish.js") +themes/admin_default/views/admin.html.php 30 DIRTY $theme->script("jquery.dropshadow.js") +themes/admin_default/views/admin.html.php 31 DIRTY $theme->script("ui.init.js") +themes/admin_default/views/admin.html.php 33 DIRTY $theme->admin_head() +themes/admin_default/views/admin.html.php 36 DIRTY $theme->body_attributes() +themes/admin_default/views/admin.html.php 37 DIRTY $theme->admin_page_top() +themes/admin_default/views/admin.html.php 43 DIRTY $theme->site_status() +themes/admin_default/views/admin.html.php 45 DIRTY $theme->admin_header_top() +themes/admin_default/views/admin.html.php 48 DIRTY $csrf +themes/admin_default/views/admin.html.php 54 DIRTY $theme->admin_menu() +themes/admin_default/views/admin.html.php 56 DIRTY $theme->admin_header_bottom() +themes/admin_default/views/admin.html.php 62 DIRTY $theme->messages() +themes/admin_default/views/admin.html.php 63 DIRTY $content +themes/admin_default/views/admin.html.php 69 DIRTY $sidebar +themes/admin_default/views/admin.html.php 74 DIRTY $theme->admin_footer() +themes/admin_default/views/admin.html.php 76 DIRTY $theme->admin_credits() +themes/admin_default/views/admin.html.php 80 DIRTY $theme->admin_page_bottom() themes/admin_default/views/block.html.php 2 DIRTY $id themes/admin_default/views/block.html.php 2 DIRTY $css_id themes/admin_default/views/block.html.php 5 DIRTY $id @@ -602,22 +601,21 @@ themes/default/views/page.html.php 48 DIRTY $theme->s themes/default/views/page.html.php 49 DIRTY $theme->script("jquery.form.js") themes/default/views/page.html.php 50 DIRTY $theme->script("jquery-ui.js") themes/default/views/page.html.php 51 DIRTY $theme->script("gallery.common.js") -themes/default/views/page.html.php 53 DIRTY $theme->script("gallery.reload.js") -themes/default/views/page.html.php 58 DIRTY $theme->script("gallery.dialog.js") -themes/default/views/page.html.php 59 DIRTY $theme->script("gallery.form.js") -themes/default/views/page.html.php 60 DIRTY $theme->script("superfish/js/superfish.js") -themes/default/views/page.html.php 61 DIRTY $theme->script("jquery.localscroll.js") -themes/default/views/page.html.php 62 DIRTY $theme->script("ui.init.js") -themes/default/views/page.html.php 66 DIRTY $theme->script("jquery.scrollTo.js") -themes/default/views/page.html.php 67 DIRTY $theme->script("gallery.show_full_size.js") -themes/default/views/page.html.php 69 DIRTY $theme->script("flowplayer.js") -themes/default/views/page.html.php 72 DIRTY $theme->head() -themes/default/views/page.html.php 75 DIRTY $theme->body_attributes() -themes/default/views/page.html.php 76 DIRTY $theme->page_top() -themes/default/views/page.html.php 78 DIRTY $theme->site_status() -themes/default/views/page.html.php 86 DIRTY $theme->messages() -themes/default/views/page.html.php 87 DIRTY $content -themes/default/views/page.html.php 101 DIRTY $theme->page_bottom() +themes/default/views/page.html.php 56 DIRTY $theme->script("gallery.dialog.js") +themes/default/views/page.html.php 57 DIRTY $theme->script("gallery.form.js") +themes/default/views/page.html.php 58 DIRTY $theme->script("superfish/js/superfish.js") +themes/default/views/page.html.php 59 DIRTY $theme->script("jquery.localscroll.js") +themes/default/views/page.html.php 60 DIRTY $theme->script("ui.init.js") +themes/default/views/page.html.php 64 DIRTY $theme->script("jquery.scrollTo.js") +themes/default/views/page.html.php 65 DIRTY $theme->script("gallery.show_full_size.js") +themes/default/views/page.html.php 67 DIRTY $theme->script("flowplayer.js") +themes/default/views/page.html.php 70 DIRTY $theme->head() +themes/default/views/page.html.php 73 DIRTY $theme->body_attributes() +themes/default/views/page.html.php 74 DIRTY $theme->page_top() +themes/default/views/page.html.php 76 DIRTY $theme->site_status() +themes/default/views/page.html.php 84 DIRTY $theme->messages() +themes/default/views/page.html.php 85 DIRTY $content +themes/default/views/page.html.php 99 DIRTY $theme->page_bottom() themes/default/views/pager.html.php 13 DIRTY $url themes/default/views/pager.html.php 20 DIRTY $previous_page themes/default/views/pager.html.php 20 DIRTY $url diff --git a/modules/gallery/views/admin_maintenance_show_log.html.php b/modules/gallery/views/admin_maintenance_show_log.html.php index ac593de7..9d850986 100644 --- a/modules/gallery/views/admin_maintenance_show_log.html.php +++ b/modules/gallery/views/admin_maintenance_show_log.html.php @@ -1,7 +1,7 @@
          diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 12d8a5b5..f10cbcc9 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -374,7 +374,7 @@ function organize_dialog_init() { } $("#gDialog").bind("organize_close", function(target) { - $.gallery_reload(); + document.location.reload(); }); heightMicroThumbPanel -= 2 * parseFloat($("#gDialog").css("padding-top")); diff --git a/modules/server_add/views/server_add_tree_dialog.html.php b/modules/server_add/views/server_add_tree_dialog.html.php index 8dfd2c38..21952849 100644 --- a/modules/server_add/views/server_add_tree_dialog.html.php +++ b/modules/server_add/views/server_add_tree_dialog.html.php @@ -34,7 +34,7 @@ - diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js index 564de393..765c2a35 100644 --- a/modules/tag/js/tag.js +++ b/modules/tag/js/tag.js @@ -59,7 +59,7 @@ function editInPlace(element) { closeEditInPlaceForms(); // close form $("#gTag-" + data.tag_id).text(data.new_tagname); // update tagname console.log(data); - $.gallery_reload(); + window.location.reload(); } } }); diff --git a/themes/admin_default/views/admin.html.php b/themes/admin_default/views/admin.html.php index 63fc45b5..d27f9260 100644 --- a/themes/admin_default/views/admin.html.php +++ b/themes/admin_default/views/admin.html.php @@ -21,8 +21,6 @@ script("jquery.form.js") ?> script("jquery-ui.js") ?> script("gallery.common.js") ?> - - script("gallery.reload.js") ?>
          diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index f10cbcc9..12d8a5b5 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -374,7 +374,7 @@ function organize_dialog_init() { } $("#gDialog").bind("organize_close", function(target) { - document.location.reload(); + $.gallery_reload(); }); heightMicroThumbPanel -= 2 * parseFloat($("#gDialog").css("padding-top")); diff --git a/modules/server_add/views/server_add_tree_dialog.html.php b/modules/server_add/views/server_add_tree_dialog.html.php index 21952849..8dfd2c38 100644 --- a/modules/server_add/views/server_add_tree_dialog.html.php +++ b/modules/server_add/views/server_add_tree_dialog.html.php @@ -34,7 +34,7 @@ - diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js index 765c2a35..564de393 100644 --- a/modules/tag/js/tag.js +++ b/modules/tag/js/tag.js @@ -59,7 +59,7 @@ function editInPlace(element) { closeEditInPlaceForms(); // close form $("#gTag-" + data.tag_id).text(data.new_tagname); // update tagname console.log(data); - window.location.reload(); + $.gallery_reload(); } } }); diff --git a/themes/admin_default/views/admin.html.php b/themes/admin_default/views/admin.html.php index d27f9260..63fc45b5 100644 --- a/themes/admin_default/views/admin.html.php +++ b/themes/admin_default/views/admin.html.php @@ -21,6 +21,8 @@ script("jquery.form.js") ?> script("jquery-ui.js") ?> script("gallery.common.js") ?> + + script("gallery.reload.js") ?> -
          - p::purify($item->title))) ?> -
          -
          -
          -
          -
          -

          -
          -
          -
          -
          -
          -
          -
          - -
          -
          "> -
            -
            -
            -
            -
            -
              -
            -
            -
            -
            -
            - -
            -
            -
            -
            -
            diff --git a/modules/organize/views/organize_album.html.php b/modules/organize/views/organize_album.html.php deleted file mode 100644 index ae2d5d51..00000000 --- a/modules/organize/views/organize_album.html.php +++ /dev/null @@ -1,17 +0,0 @@ - -
              -
            • - "> - - -
              gBranchText"> - title) ?> -
              -
              "> - -
              -
            • -
            diff --git a/modules/organize/views/organize_button_pane.html.php b/modules/organize/views/organize_button_pane.html.php index c5839a44..8eced107 100644 --- a/modules/organize/views/organize_button_pane.html.php +++ b/modules/organize/views/organize_button_pane.html.php @@ -1,50 +1,5 @@ - -
            - - - +
            diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php new file mode 100644 index 00000000..cf3fd478 --- /dev/null +++ b/modules/organize/views/organize_dialog.html.php @@ -0,0 +1,37 @@ + +
            +

            p::purify($item->title))) ?>

            +
            +
            +
            +

            +
            +
            +
            +
            +
            +
            +
            +
              + +
            +
            +
            +
            "> +
              + +
            +
            +
            +
            +
            +
            + +
            +
            +
            +
            +
            +
            + diff --git a/modules/organize/views/organize_edit.html.php b/modules/organize/views/organize_edit.html.php deleted file mode 100644 index 1adf290f..00000000 --- a/modules/organize/views/organize_edit.html.php +++ /dev/null @@ -1,14 +0,0 @@ - -
              - $pane): ?> -
            • - -
            - - 0): ?> - $pane): ?> -
            - - -
            - \ No newline at end of file diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index c80696ad..e6b7aec0 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,12 +1,19 @@ $child): ?> - -is_album()): ?> - - -
          • -
            + + is_album()): ?> + + +
          • thumb_img(array("class" => "gThumbnail"), $thumbsize, true) ?> -
          • - + += 25): ?> + + \ No newline at end of file diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index d2cdd957..28b45be0 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,4 +1,20 @@ - $child): ?> - +
          • + "> + + +
            gBranchText"> + title) ?> +
            + +
            + +
              "> + +
            + +
          • -- cgit v1.2.3 From 63f3efef37839ffba8cd75b9098d56cd03b06376 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 10:26:49 -0700 Subject: Revert "Revert "Enable the expand/collapse of branches by clicking on the plus/minus"" This reverts commit e37526f94df74a52a9cf36f0a5a5e641958ebbb3. --- modules/organize/controllers/organize.php | 59 ++++++++++++++++--------- modules/organize/css/organize.css | 8 ++++ modules/organize/js/organize.js | 28 +++++++++++- modules/organize/views/organize_dialog.html.php | 2 +- modules/organize/views/organize_tree.html.php | 10 +++-- 5 files changed, 80 insertions(+), 27 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index d7854c53..e10e33b5 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -50,6 +50,27 @@ class Organize_Controller extends Controller { print $v->__toString(); } + function children($item_id) { + $item = ORM::factory("item", $item_id); + access::required("view", $item); + access::required("edit", $item); + + $albums = $item->children(null, 0, "album", array("title" => "ASC")); + + $children = ""; + foreach ($albums as $album) { + $v = new View("organize_tree.html"); + $v->album = $album; + $v->selected = false; + $v->children = array(); + $v->album_icon = $album->children_count("album") ? "ui-icon-plus" : "gBranchEmpty"; + + $children .= $v->__toString(); + } + + print $children; + } + private function _get_micro_thumb_grid($item, $offset=0) { $v = new View("organize_thumb_grid.html"); $v->item_id = $item->id; @@ -60,34 +81,30 @@ class Organize_Controller extends Controller { return $v; } - private function _tree($item, $parent, $selected=false) { - access::required("view", $item); - access::required("edit", $item); - - $albums = ORM::factory("item") - ->where(array("parent_id" => $parent->id, "type" => "album")) - ->orderby(array("title" => "ASC")) - ->find_all(); + private function _tree($item, $parent, $depth=0) { + $albums = $parent->children(null, 0, "album", array("title" => "ASC")); $v = new View("organize_tree.html"); $v->album = $parent; - $v->selected = false; - $v->children = ""; - $v->album_icon = "ui-icon-plus"; - if (!$selected) { - $v->selected = $parent->id == $item->id; + if ($parent->id == $item->id) { + $v->selected = true; + $depth = 1; + } else { + $v->selected = false; + } + $v->children = array(); + $v->album_icon = "gBranchEmpty"; + if ($albums->count()) { + $v->album_icon = "ui-icon-plus"; - if ($albums->count() && ($parent->id == 1 || $v->selected) ) { + if ($depth <= 1) { $v->album_icon = "ui-icon-minus"; - } - - foreach ($albums as $album) { - $v->children .= $this->_tree($item, $album, $v->selected); + foreach ($albums as $album) { + $v->children[] = $this->_tree($item, $album, ++$depth); + } } } - return $v->__toString(); + return $v; } - - } diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 4568a707..7c2d9c5b 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -41,6 +41,14 @@ padding-left: 1.2em; } +.gBranchText:hover { + border: 1px dashed #999; +} + +.gBranchEmpty { + visibility: hidden; +} + .gBranchSelected { background-color: #cfdeff !important; border-bottom: 1px solid #999 !important; diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index e84afd03..74b02569 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -37,7 +37,6 @@ * Dynamically initialize the organize dialog when it is displayed */ function _init(data) { - // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 $(".sf-menu li.sfHover ul").css("z-index", 70); @@ -64,6 +63,8 @@ $.gallery_reload(); }); + $(".gBranchText span").click(_collapse_or_expanded_tree); + //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); //$(".gBranchText").droppable(treeDroppable); //$(".gBranchText").click(organizeOpenFolder); @@ -109,6 +110,31 @@ $("#gOrganizeDialog").dialog("close"); }; + /** + * Open or close a branch. If the children is a div placeholder, replace with
              + */ + function _collapse_or_expanded_tree(event) { + var id = $(event.currentTarget).attr("ref"); + if ($(event.currentTarget).hasClass("ui-icon-minus")) { + $(event.currentTarget).removeClass("ui-icon-minus"); + $(event.currentTarget).addClass("ui-icon-plus"); + $("#gOrganizeChildren-" + id).hide(); + } else { + if ($("#gOrganizeChildren-" + id).is("div")) { + $("#gOrganizeChildren-" + id).remove(); + $("#gOrganizeBranch-" + id).after("
                "); + var url = $("#gOrganizeAlbumTree").attr("ref").replace("__ITEM_ID__", id); + $.get(url, function(data) { + $("#gOrganizeChildren-" + id).html(data); + $(".gBranchText span").click(_collapse_or_expanded_tree); + });; + } + $("#gOrganizeChildren-" + id).show(); + $(event.currentTarget).removeClass("ui-icon-plus"); + $(event.currentTarget).addClass("ui-icon-minus"); + } + } + })(jQuery); $("document").ready(function() { diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index cf3fd478..1e6646e4 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -12,7 +12,7 @@
              -
                +
                  ">
              diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 28b45be0..d64410d8 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,11 +1,11 @@
            • - "> -
              gBranchText"> + + title) ?>
              @@ -13,7 +13,9 @@
                "> - + + +
            • -- cgit v1.2.3 From a92a46b0cda18a3ba794a67c07181a2ca405a2a6 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 11:04:42 -0700 Subject: Change to use the new children and children_count API --- modules/organize/controllers/organize.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index e10e33b5..cbaaca6e 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -55,7 +55,7 @@ class Organize_Controller extends Controller { access::required("view", $item); access::required("edit", $item); - $albums = $item->children(null, 0, "album", array("title" => "ASC")); + $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); $children = ""; foreach ($albums as $album) { @@ -63,7 +63,8 @@ class Organize_Controller extends Controller { $v->album = $album; $v->selected = false; $v->children = array(); - $v->album_icon = $album->children_count("album") ? "ui-icon-plus" : "gBranchEmpty"; + $v->album_icon = + $album->children_count(array("type" => "album")) ? "ui-icon-plus" : "gBranchEmpty"; $children .= $v->__toString(); } @@ -82,7 +83,7 @@ class Organize_Controller extends Controller { } private function _tree($item, $parent, $depth=0) { - $albums = $parent->children(null, 0, "album", array("title" => "ASC")); + $albums = $parent->children(null, 0, array("type" => "album"), array("title" => "ASC")); $v = new View("organize_tree.html"); $v->album = $parent; -- cgit v1.2.3 From 824a80b0d4b5c12f5bd6981cac08b406de637dd3 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 15:24:31 -0700 Subject: Change the content pane based on the selection in the album tree --- modules/organize/js/organize.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 74b02569..194a2a19 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -64,12 +64,10 @@ }); $(".gBranchText span").click(_collapse_or_expanded_tree); + $(".gBranchText").click(_setContents); //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); //$(".gBranchText").droppable(treeDroppable); - //$(".gBranchText").click(organizeOpenFolder); - //retrieveMicroThumbs(item_id); - //showLoading("#gOrganizeDialog"); //$("#gMicroThumbPanel").droppable(thumbDroppable); //$("#gMicroThumbPanel").selectable(selectable); @@ -114,6 +112,7 @@ * Open or close a branch. If the children is a div placeholder, replace with
                */ function _collapse_or_expanded_tree(event) { + event.stopPropagation(); var id = $(event.currentTarget).attr("ref"); if ($(event.currentTarget).hasClass("ui-icon-minus")) { $(event.currentTarget).removeClass("ui-icon-minus"); @@ -127,7 +126,8 @@ $.get(url, function(data) { $("#gOrganizeChildren-" + id).html(data); $(".gBranchText span").click(_collapse_or_expanded_tree); - });; + $(".gBranchText").click(_setContents); + }); } $("#gOrganizeChildren-" + id).show(); $(event.currentTarget).removeClass("ui-icon-plus"); @@ -135,6 +135,24 @@ } } + /** + * When the text of a selection is clicked, then show that albums contents + */ + function _setContents(event) { + event.preventDefault(); + if ($(event.currentTarget).hasClass("gBranchSelected")) { + return; + } + var id = $(event.currentTarget).attr("ref"); + $(".gBranchSelected").removeClass("gBranchSelected"); + $(event.currentTarget).addClass("gBranchSelected"); + var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); + $.get(url, function(data) { + $("#gMicroThumbGrid").html(data); + }); + + } + })(jQuery); $("document").ready(function() { -- cgit v1.2.3 From a03f8b1003093b385e9c839c1e5e2e4f80f0cd0b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 16:45:44 -0700 Subject: Fix up formatting of items in thumbgrid --- modules/organize/css/organize.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/organize') diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 7c2d9c5b..0a23a6bf 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -83,6 +83,7 @@ } #gMicroThumbGrid { + padding: .5em; } .gMicroThumbContainer { @@ -93,7 +94,7 @@ .gMicroThumb { display: block; float: left; -// font-size: .7em; + font-size: .8em; height: 9em; margin-bottom: 1em; margin-left: 1em; @@ -101,6 +102,10 @@ width: 9em; } +.gThumbnail { + padding: .5em; +} + #gMicroThumbPanel #gMicroThumbGrid .gAlbum { background-color: #e8e8e8; } -- cgit v1.2.3 From cab46cf0386061840498f3efe32c7030e07d2e04 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 5 Aug 2009 22:28:37 -0700 Subject: Remove the resize dialog on window resize functionality --- modules/organize/js/organize.js | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 194a2a19..12712ff1 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -65,6 +65,7 @@ $(".gBranchText span").click(_collapse_or_expanded_tree); $(".gBranchText").click(_setContents); + $(".gAlbum img.gThumbnail").live("dblclick", _openAlbum); //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); //$(".gBranchText").droppable(treeDroppable); @@ -73,34 +74,6 @@ //$("#gMicroThumbPanel").selectable(selectable); //$("#gOrganizeEditDrawerHandle a").click(drawerHandleButtonsClick); - $(window).bind("resize", _size_dialog); - }; - - /** - * Dynamically initialize the organize dialog when it is displayed - */ - function _size_dialog(event) { - var size = $.getViewportSize(); - var h = $("#gOrganizeDialog").dialog("option", "minHeight"); - var sh = size.height() - 100; - var height = Math.max(sh, h); - var w = $("#gOrganizeDialog").dialog("option", "minWidth"); - var sw = size.width() - 100; - var width = Math.max(w, sw); - - $("#gOrganizeDialog").parent().css("height", height); - $("#gOrganizeDialog").parent().css("width", width); - $("#gOrganizeDialog").parent().css("left", "50px"); - $("#gOrganizeDialog").parent().css("top", "50px"); - - var heightMicroThumbPanel = height - 50; - heightMicroThumbPanel -= 2 * parseFloat($("#gOrganizeDialog").css("padding-bottom")); - heightMicroThumbPanel -= $("#gMessage").outerHeight(); - heightMicroThumbPanel = Math.floor(heightMicroThumbPanel); - $("#gOrganizeTreeContainer").height(heightMicroThumbPanel); - - heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").outerHeight(); - $("#gMicroThumbPanel").height(heightMicroThumbPanel); }; function _dialog_close(event) { @@ -150,7 +123,19 @@ $.get(url, function(data) { $("#gMicroThumbGrid").html(data); }); + } + function _openAlbum(event) { + event.preventDefault(); + var id = $(event.target).parent().attr("ref"); + $(".gBranchSelected").removeClass("gBranchSelected"); + $("#gOrganizeBranch-" + id).addClass("gBranchSelected"); + var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); + // @todo load the branch elements if required. + $.get(url, function(data) { + $("#gMicroThumbGrid").html(data); + // $(".gAlbum img.gThumbnail").dblclick(_openAlbum); + }); } })(jQuery); -- cgit v1.2.3 From 8131e6fa380d52faa7c1dc9a59c2e83a4adb9134 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 6 Aug 2009 06:33:17 -0700 Subject: Tighten up the code by loading all the albums in the tree at once, removing the events to populate the button bar. --- modules/organize/controllers/organize.php | 67 +++++---------- modules/organize/helpers/organize.php | 94 ---------------------- modules/organize/js/organize.js | 47 +---------- .../organize/views/organize_button_pane.html.php | 5 -- modules/organize/views/organize_dialog.html.php | 9 ++- modules/organize/views/organize_tree.html.php | 17 ++-- 6 files changed, 35 insertions(+), 204 deletions(-) delete mode 100644 modules/organize/helpers/organize.php delete mode 100644 modules/organize/views/organize_button_pane.html.php (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index cbaaca6e..95d71e9c 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -23,21 +23,20 @@ class Organize_Controller extends Controller { function index($item_id) { $item = ORM::factory("item", $item_id); - $root = ($item->id == 1) ? $item : ORM::factory("item", 1); + $root = $item->id == 1 ? $item : ORM::factory("item", 1); access::required("view", $item); access::required("edit", $item); $v = new View("organize_dialog.html"); - $v->root = $root; - $v->item = $item; - $v->album_tree = $this->_tree($item, $root); - $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item); - $v->button_pane = new View("organize_button_pane.html"); - $buttons = (object)array("left" => array(), "middle" =>array(), "right" => array(), - "item" => $item); - module::event("organize_format_button_pane", $buttons); + $v->title = $item->title; + $parents = array(); + foreach ($item->parents() as $parent) { + $parents[$parent->id] = 1; + } + $parents[$item->id] = 1; - $v->button_pane->buttons = $buttons; + $v->album_tree = $this->_tree($root, $parents); + $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item); print $v; } @@ -50,28 +49,6 @@ class Organize_Controller extends Controller { print $v->__toString(); } - function children($item_id) { - $item = ORM::factory("item", $item_id); - access::required("view", $item); - access::required("edit", $item); - - $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); - - $children = ""; - foreach ($albums as $album) { - $v = new View("organize_tree.html"); - $v->album = $album; - $v->selected = false; - $v->children = array(); - $v->album_icon = - $album->children_count(array("type" => "album")) ? "ui-icon-plus" : "gBranchEmpty"; - - $children .= $v->__toString(); - } - - print $children; - } - private function _get_micro_thumb_grid($item, $offset=0) { $v = new View("organize_thumb_grid.html"); $v->item_id = $item->id; @@ -82,28 +59,20 @@ class Organize_Controller extends Controller { return $v; } - private function _tree($item, $parent, $depth=0) { - $albums = $parent->children(null, 0, array("type" => "album"), array("title" => "ASC")); - + private function _tree($item, $parents) { $v = new View("organize_tree.html"); - $v->album = $parent; - - if ($parent->id == $item->id) { - $v->selected = true; - $depth = 1; - } else { - $v->selected = false; - } + $v->album = $item; + $keys = array_keys($parents); + $v->selected = end($keys) == $item->id; $v->children = array(); $v->album_icon = "gBranchEmpty"; + + $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); if ($albums->count()) { - $v->album_icon = "ui-icon-plus"; + $v->album_icon = empty($parents[$item->id]) ? "ui-icon-plus" : "ui-icon-minus"; - if ($depth <= 1) { - $v->album_icon = "ui-icon-minus"; - foreach ($albums as $album) { - $v->children[] = $this->_tree($item, $album, ++$depth); - } + foreach ($albums as $album) { + $v->children[] = $this->_tree($album, $parents); } } return $v; diff --git a/modules/organize/helpers/organize.php b/modules/organize/helpers/organize.php deleted file mode 100644 index 25284771..00000000 --- a/modules/organize/helpers/organize.php +++ /dev/null @@ -1,94 +0,0 @@ - "gEditGeneral", "ref" => "general")); - // In this case we know there is only 1 item, but in general we should loop - // and create multiple hidden items. - $generalPane->hidden("item[]")->value($item->id); - $generalPane->input("title")->label(t("Title"))->value($item->title); - $generalPane->textarea("description")->label(t("Description"))->value($item->description); - $generalPane->input("dirname")->label(t("Path Name"))->value($item->name) - ->callback("item::validate_no_slashes") - ->error_messages("no_slashes", t("The directory name can't contain a \"/\"")) - ->callback("item::validate_no_trailing_period") - ->error_messages("no_trailing_period", t("The directory name can't end in \".\"")) - ->callback("item::validate_no_name_conflict") - ->error_messages("conflict", t("The path name is not unique")); - - return $generalPane; - } - - static function get_sort_edit_form($item) { - $sortPane = new Forge("organize/__FUNCTION__", "", "post", - array("id" => "gEditSort", "ref" => "sort")); - $sortPane->hidden("item[]")->value($item->id); - $sortPane->dropdown("column", array("id" => "gAlbumSortColumn")) - ->label(t("Sort by")) - ->options(array("weight" => t("Order Added"), - "captured" => t("Capture Date"), - "created" => t("Creation Date"), - "title" => t("Title"), - "updated" => t("Updated Date"), - "view_count" => t("Number of views"), - "rand_key" => t("Random"))) - ->selected($item->sort_column); - $sortPane->dropdown("direction", array("id" => "gAlbumSortDirection")) - ->label(t("Order")) - ->options(array("ASC" => t("Ascending"), - "DESC" => t("Descending"))) - ->selected($item->sort_order); - - return $sortPane; - } - - static function get_tag_form($itemids) { - $tagPane = new Forge("organize/__FUNCTION__", "", "post", - array("id" => "gEditTags", "ref" => "edit_tags")); - $tagPane->hidden("item")->value(implode("|", $itemids)); - $item_count = count($itemids); - $ids = implode(", ", $itemids); - - // Lame stopgap security check. This code is going to get rewritten anyway. - foreach ($itemids as $id) { - $item = ORM::factory("item", $id); - access::required("view", $item); - access::required("edit", $item); - } - - $tags = Database::instance()->query( - "SELECT t.name, COUNT(it.item_id) as count - FROM {items_tags} it, {tags} t - WHERE it.tag_id = t.id - AND it.item_id in($ids) - GROUP BY it.tag_id - ORDER BY t.name ASC"); - $taglist = array(); - foreach ($tags as $tag) { - $taglist[] = $tag->name . ($item_count > $tag->count ? "*" : ""); - } - $taglist = implode("; ", $taglist); - $tagPane->textarea("tags")->label(t("Tags"))->value($taglist); - - return $tagPane; - } - -} \ No newline at end of file diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 12712ff1..0a7576b0 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -12,7 +12,6 @@ $("body").append('
                '); $("#gOrganizeDialog").dialog(opts); - // Pass the approx height and width of the thumb grid to optimize thumb retrieval $.get(href, _init); return false; }); @@ -45,8 +44,7 @@ var heightMicroThumbPanel = $("#gOrganizeDialog").innerHeight(); heightMicroThumbPanel -= 2 * parseFloat($("#gOrganizeDialog").css("padding-bottom")); - heightMicroThumbPanel -= $("#gMessage").outerHeight(); - heightMicroThumbPanel = Math.floor(heightMicroThumbPanel); + heightMicroThumbPanel = Math.floor(heightMicroThumbPanel - 10 - $("#gMessage").outerHeight()); $("#gOrganizeTreeContainer").height(heightMicroThumbPanel); heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").outerHeight(); @@ -65,15 +63,6 @@ $(".gBranchText span").click(_collapse_or_expanded_tree); $(".gBranchText").click(_setContents); - $(".gAlbum img.gThumbnail").live("dblclick", _openAlbum); - - //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren); - //$(".gBranchText").droppable(treeDroppable); - - //$("#gMicroThumbPanel").droppable(thumbDroppable); - //$("#gMicroThumbPanel").selectable(selectable); - //$("#gOrganizeEditDrawerHandle a").click(drawerHandleButtonsClick); - }; function _dialog_close(event) { @@ -86,26 +75,12 @@ */ function _collapse_or_expanded_tree(event) { event.stopPropagation(); - var id = $(event.currentTarget).attr("ref"); if ($(event.currentTarget).hasClass("ui-icon-minus")) { - $(event.currentTarget).removeClass("ui-icon-minus"); - $(event.currentTarget).addClass("ui-icon-plus"); - $("#gOrganizeChildren-" + id).hide(); + $(event.currentTarget).removeClass("ui-icon-minus").addClass("ui-icon-plus"); } else { - if ($("#gOrganizeChildren-" + id).is("div")) { - $("#gOrganizeChildren-" + id).remove(); - $("#gOrganizeBranch-" + id).after("
                  "); - var url = $("#gOrganizeAlbumTree").attr("ref").replace("__ITEM_ID__", id); - $.get(url, function(data) { - $("#gOrganizeChildren-" + id).html(data); - $(".gBranchText span").click(_collapse_or_expanded_tree); - $(".gBranchText").click(_setContents); - }); - } - $("#gOrganizeChildren-" + id).show(); - $(event.currentTarget).removeClass("ui-icon-plus"); - $(event.currentTarget).addClass("ui-icon-minus"); + $(event.currentTarget).removeClass("ui-icon-plus").addClass("ui-icon-minus"); } + $("#gOrganizeChildren-" + $(event.currentTarget).attr("ref")).toggle(); } /** @@ -118,26 +93,12 @@ } var id = $(event.currentTarget).attr("ref"); $(".gBranchSelected").removeClass("gBranchSelected"); - $(event.currentTarget).addClass("gBranchSelected"); - var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); - $.get(url, function(data) { - $("#gMicroThumbGrid").html(data); - }); - } - - function _openAlbum(event) { - event.preventDefault(); - var id = $(event.target).parent().attr("ref"); - $(".gBranchSelected").removeClass("gBranchSelected"); $("#gOrganizeBranch-" + id).addClass("gBranchSelected"); var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); - // @todo load the branch elements if required. $.get(url, function(data) { $("#gMicroThumbGrid").html(data); - // $(".gAlbum img.gThumbnail").dblclick(_openAlbum); }); } - })(jQuery); $("document").ready(function() { diff --git a/modules/organize/views/organize_button_pane.html.php b/modules/organize/views/organize_button_pane.html.php deleted file mode 100644 index 8eced107..00000000 --- a/modules/organize/views/organize_button_pane.html.php +++ /dev/null @@ -1,5 +0,0 @@ - -
                  - -
                  diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 1e6646e4..4f10297e 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,6 +1,6 @@
                  -

                  p::purify($item->title))) ?>

                  +

                  p::purify($title))) ?>

                  @@ -12,7 +12,7 @@
                  -
                    "> +
                  @@ -27,7 +27,10 @@
                  - +
                  + +
                  diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index d64410d8..280bdc5f 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -8,15 +8,12 @@ title) ?>
                  - -
                  - -
                    "> - - - -
                  - +
                    "> +
                  •  
                  • + + + +
                  -- cgit v1.2.3 From 7bdf382e813515ce7ab6e14f0b8e3e0b7b6bd867 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 6 Aug 2009 07:02:41 -0700 Subject: Revert "Revert "Revert "Allow a theme to override the page refresh mechanism. Create a new""" This reverts commit 7b1cca168cb9b29fcccdcdce9e32efb190e4575e. Basically remove it and Bharat and I will fight it out in SF for a resolution :-) --- lib/gallery.dialog.js | 4 +- lib/gallery.panel.js | 4 +- lib/gallery.reload.js | 16 ----- modules/gallery/js/quick.js | 4 +- modules/gallery/tests/xss_data.txt | 68 +++++++++++----------- .../views/admin_maintenance_show_log.html.php | 2 +- .../gallery/views/admin_maintenance_task.html.php | 2 +- modules/organize/js/organize.js | 2 +- .../views/server_add_tree_dialog.html.php | 2 +- modules/tag/js/tag.js | 2 +- themes/admin_default/views/admin.html.php | 2 - themes/default/views/page.html.php | 2 - 12 files changed, 44 insertions(+), 66 deletions(-) delete mode 100644 lib/gallery.reload.js (limited to 'modules/organize') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 0efcf120..74c2f20e 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -25,9 +25,9 @@ function ajaxify_dialog() { } if (data.result == "success") { if (data.location) { - $.gallery_location(data.location); + window.location = data.location; } else { - $.gallery_reload(); + window.location.reload(); } } } diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js index 26be11ad..022e4878 100644 --- a/lib/gallery.panel.js +++ b/lib/gallery.panel.js @@ -40,9 +40,9 @@ function togglePanel(element, on_success) { if (on_success) { on_success(); } else if (data.location) { - $.gallery_location(data.location); + window.location = data.location; } else { - $.gallery_reload(); + window.location.reload(); } } } diff --git a/lib/gallery.reload.js b/lib/gallery.reload.js deleted file mode 100644 index 2c8752a0..00000000 --- a/lib/gallery.reload.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -(function ($) { - $.gallery_reload = function() { - window.location.reload(); - }; -})(jQuery); - -// Vertically align a block element's content -(function ($) { - $.gallery_location = function(location) { - window.location = location; - }; -})(jQuery); diff --git a/modules/gallery/js/quick.js b/modules/gallery/js/quick.js index 4753808e..fda6470f 100644 --- a/modules/gallery/js/quick.js +++ b/modules/gallery/js/quick.js @@ -67,9 +67,9 @@ var quick_do = function(cont, pane, img) { img.css("margin-top", 0); } } else if (data.location) { - $.gallery_location(data.location); + window.location = data.location; } else if (data.reload) { - $.gallery_reload(); + window.location.reload(); } } }); diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 29d223b7..0e118ce7 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -496,25 +496,24 @@ themes/admin_default/views/admin.html.php 20 DIRTY $theme->s themes/admin_default/views/admin.html.php 21 DIRTY $theme->script("jquery.form.js") themes/admin_default/views/admin.html.php 22 DIRTY $theme->script("jquery-ui.js") themes/admin_default/views/admin.html.php 23 DIRTY $theme->script("gallery.common.js") -themes/admin_default/views/admin.html.php 25 DIRTY $theme->script("gallery.reload.js") -themes/admin_default/views/admin.html.php 30 DIRTY $theme->script("gallery.dialog.js") -themes/admin_default/views/admin.html.php 31 DIRTY $theme->script("superfish/js/superfish.js") -themes/admin_default/views/admin.html.php 32 DIRTY $theme->script("jquery.dropshadow.js") -themes/admin_default/views/admin.html.php 33 DIRTY $theme->script("ui.init.js") -themes/admin_default/views/admin.html.php 35 DIRTY $theme->admin_head() -themes/admin_default/views/admin.html.php 38 DIRTY $theme->body_attributes() -themes/admin_default/views/admin.html.php 39 DIRTY $theme->admin_page_top() -themes/admin_default/views/admin.html.php 45 DIRTY $theme->site_status() -themes/admin_default/views/admin.html.php 47 DIRTY $theme->admin_header_top() -themes/admin_default/views/admin.html.php 50 DIRTY $csrf -themes/admin_default/views/admin.html.php 56 DIRTY $theme->admin_menu() -themes/admin_default/views/admin.html.php 58 DIRTY $theme->admin_header_bottom() -themes/admin_default/views/admin.html.php 64 DIRTY $theme->messages() -themes/admin_default/views/admin.html.php 65 DIRTY $content -themes/admin_default/views/admin.html.php 71 DIRTY $sidebar -themes/admin_default/views/admin.html.php 76 DIRTY $theme->admin_footer() -themes/admin_default/views/admin.html.php 78 DIRTY $theme->admin_credits() -themes/admin_default/views/admin.html.php 82 DIRTY $theme->admin_page_bottom() +themes/admin_default/views/admin.html.php 28 DIRTY $theme->script("gallery.dialog.js") +themes/admin_default/views/admin.html.php 29 DIRTY $theme->script("superfish/js/superfish.js") +themes/admin_default/views/admin.html.php 30 DIRTY $theme->script("jquery.dropshadow.js") +themes/admin_default/views/admin.html.php 31 DIRTY $theme->script("ui.init.js") +themes/admin_default/views/admin.html.php 33 DIRTY $theme->admin_head() +themes/admin_default/views/admin.html.php 36 DIRTY $theme->body_attributes() +themes/admin_default/views/admin.html.php 37 DIRTY $theme->admin_page_top() +themes/admin_default/views/admin.html.php 43 DIRTY $theme->site_status() +themes/admin_default/views/admin.html.php 45 DIRTY $theme->admin_header_top() +themes/admin_default/views/admin.html.php 48 DIRTY $csrf +themes/admin_default/views/admin.html.php 54 DIRTY $theme->admin_menu() +themes/admin_default/views/admin.html.php 56 DIRTY $theme->admin_header_bottom() +themes/admin_default/views/admin.html.php 62 DIRTY $theme->messages() +themes/admin_default/views/admin.html.php 63 DIRTY $content +themes/admin_default/views/admin.html.php 69 DIRTY $sidebar +themes/admin_default/views/admin.html.php 74 DIRTY $theme->admin_footer() +themes/admin_default/views/admin.html.php 76 DIRTY $theme->admin_credits() +themes/admin_default/views/admin.html.php 80 DIRTY $theme->admin_page_bottom() themes/admin_default/views/block.html.php 2 DIRTY $id themes/admin_default/views/block.html.php 2 DIRTY $css_id themes/admin_default/views/block.html.php 5 DIRTY $id @@ -602,22 +601,21 @@ themes/default/views/page.html.php 48 DIRTY $theme->s themes/default/views/page.html.php 49 DIRTY $theme->script("jquery.form.js") themes/default/views/page.html.php 50 DIRTY $theme->script("jquery-ui.js") themes/default/views/page.html.php 51 DIRTY $theme->script("gallery.common.js") -themes/default/views/page.html.php 53 DIRTY $theme->script("gallery.reload.js") -themes/default/views/page.html.php 58 DIRTY $theme->script("gallery.dialog.js") -themes/default/views/page.html.php 59 DIRTY $theme->script("gallery.form.js") -themes/default/views/page.html.php 60 DIRTY $theme->script("superfish/js/superfish.js") -themes/default/views/page.html.php 61 DIRTY $theme->script("jquery.localscroll.js") -themes/default/views/page.html.php 62 DIRTY $theme->script("ui.init.js") -themes/default/views/page.html.php 66 DIRTY $theme->script("jquery.scrollTo.js") -themes/default/views/page.html.php 67 DIRTY $theme->script("gallery.show_full_size.js") -themes/default/views/page.html.php 69 DIRTY $theme->script("flowplayer.js") -themes/default/views/page.html.php 72 DIRTY $theme->head() -themes/default/views/page.html.php 75 DIRTY $theme->body_attributes() -themes/default/views/page.html.php 76 DIRTY $theme->page_top() -themes/default/views/page.html.php 78 DIRTY $theme->site_status() -themes/default/views/page.html.php 86 DIRTY $theme->messages() -themes/default/views/page.html.php 87 DIRTY $content -themes/default/views/page.html.php 101 DIRTY $theme->page_bottom() +themes/default/views/page.html.php 56 DIRTY $theme->script("gallery.dialog.js") +themes/default/views/page.html.php 57 DIRTY $theme->script("gallery.form.js") +themes/default/views/page.html.php 58 DIRTY $theme->script("superfish/js/superfish.js") +themes/default/views/page.html.php 59 DIRTY $theme->script("jquery.localscroll.js") +themes/default/views/page.html.php 60 DIRTY $theme->script("ui.init.js") +themes/default/views/page.html.php 64 DIRTY $theme->script("jquery.scrollTo.js") +themes/default/views/page.html.php 65 DIRTY $theme->script("gallery.show_full_size.js") +themes/default/views/page.html.php 67 DIRTY $theme->script("flowplayer.js") +themes/default/views/page.html.php 70 DIRTY $theme->head() +themes/default/views/page.html.php 73 DIRTY $theme->body_attributes() +themes/default/views/page.html.php 74 DIRTY $theme->page_top() +themes/default/views/page.html.php 76 DIRTY $theme->site_status() +themes/default/views/page.html.php 84 DIRTY $theme->messages() +themes/default/views/page.html.php 85 DIRTY $content +themes/default/views/page.html.php 99 DIRTY $theme->page_bottom() themes/default/views/pager.html.php 13 DIRTY $url themes/default/views/pager.html.php 20 DIRTY $previous_page themes/default/views/pager.html.php 20 DIRTY $url diff --git a/modules/gallery/views/admin_maintenance_show_log.html.php b/modules/gallery/views/admin_maintenance_show_log.html.php index ac593de7..9d850986 100644 --- a/modules/gallery/views/admin_maintenance_show_log.html.php +++ b/modules/gallery/views/admin_maintenance_show_log.html.php @@ -1,7 +1,7 @@
                  diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 0a7576b0..89549954 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -58,7 +58,7 @@ $("#gOrganizeDialog #gMicroThumbDone").click(_dialog_close); $("#gOrganizeDialog").bind("organize_close", function(target) { - $.gallery_reload(); + document.location.reload(); }); $(".gBranchText span").click(_collapse_or_expanded_tree); diff --git a/modules/server_add/views/server_add_tree_dialog.html.php b/modules/server_add/views/server_add_tree_dialog.html.php index 8dfd2c38..21952849 100644 --- a/modules/server_add/views/server_add_tree_dialog.html.php +++ b/modules/server_add/views/server_add_tree_dialog.html.php @@ -34,7 +34,7 @@ - diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js index 564de393..765c2a35 100644 --- a/modules/tag/js/tag.js +++ b/modules/tag/js/tag.js @@ -59,7 +59,7 @@ function editInPlace(element) { closeEditInPlaceForms(); // close form $("#gTag-" + data.tag_id).text(data.new_tagname); // update tagname console.log(data); - $.gallery_reload(); + window.location.reload(); } } }); diff --git a/themes/admin_default/views/admin.html.php b/themes/admin_default/views/admin.html.php index 63fc45b5..d27f9260 100644 --- a/themes/admin_default/views/admin.html.php +++ b/themes/admin_default/views/admin.html.php @@ -21,8 +21,6 @@ script("jquery.form.js") ?> script("jquery-ui.js") ?> script("gallery.common.js") ?> - - script("gallery.reload.js") ?> \ No newline at end of file -- cgit v1.2.3 From 6e4023a7207b721694403f38d6afb7a507468498 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 6 Aug 2009 16:16:11 -0700 Subject: Fix indentation. --- modules/organize/js/organize.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index e4d4a9a2..4c45b007 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -12,7 +12,7 @@ $("#gDialog #gMicroThumbDone").click(function(event) { $("#gDialog").dialog("close"); - window.location.reload(); + window.location.reload(); }); $(".gBranchText span").click($.organize.collapse_or_expand_tree); -- cgit v1.2.3 From d3f46436999b7326e88986daa5a99516430dbf15 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 6 Aug 2009 21:02:22 -0700 Subject: * Rename setContents -> show_album to be consistent style wise (no camel caps) and more explicit about what it's doing. * use toggleClass() to simplify the +/- css management. --- modules/organize/js/organize.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 4c45b007..d2006c27 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -16,26 +16,22 @@ }); $(".gBranchText span").click($.organize.collapse_or_expand_tree); - $(".gBranchText").click($.organize.setContents); + $(".gBranchText").click($.organize.show_album); }, /** - * Open or close a branch. If the children is a div placeholder, replace with
                    + * Open or close a branch. */ - collapse_or_expand_tree: function (event) { + collapse_or_expand_tree: function(event) { event.stopPropagation(); - if ($(event.currentTarget).hasClass("ui-icon-minus")) { - $(event.currentTarget).removeClass("ui-icon-minus").addClass("ui-icon-plus"); - } else { - $(event.currentTarget).removeClass("ui-icon-plus").addClass("ui-icon-minus"); - } + $(event.currentTarget).toggleClass("ui-icon-minus").toggleClass("ui-icon-plus"); $("#gOrganizeChildren-" + $(event.currentTarget).attr("ref")).toggle(); }, /** * When the text of a selection is clicked, then show that albums contents */ - setContents: function(event) { + show_album: function(event) { event.preventDefault(); if ($(event.currentTarget).hasClass("gBranchSelected")) { return; -- cgit v1.2.3 From a245c57400398d2b4b1c2aea94f590a9c0a7d8a8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 6 Aug 2009 21:36:17 -0700 Subject: Further streamline the code. Organize_Controller: * Remove unnecessary constants * Rename index() to dialog() * Simplify _get_micro_thumb_grid organize.js: * Move sizing code in here from organize_dialog.html.php organize_dialog.html.php: * Move CSS and JS links in here so that we only load them when we need them. * Move sizing code into organize.js organize_thumb_grid.html.php: * Move pagination logic in here, since it's view centric * Collapse the css class determination code and inline it --- modules/organize/controllers/organize.php | 22 +++++---------- modules/organize/helpers/organize_event.php | 2 +- modules/organize/helpers/organize_theme.php | 27 ------------------- modules/organize/js/organize.js | 6 +++++ modules/organize/views/organize_dialog.html.php | 9 +++---- .../organize/views/organize_thumb_grid.html.php | 31 +++++++++++----------- modules/organize/views/organize_tree.html.php | 2 -- 7 files changed, 33 insertions(+), 66 deletions(-) delete mode 100644 modules/organize/helpers/organize_theme.php (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 95d71e9c..3a81ef4f 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -18,10 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Organize_Controller extends Controller { - private static $_MICRO_THUMB_SIZE = 90; - private static $_MICRO_THUMB_PADDING = 10; - - function index($item_id) { + function dialog($item_id) { $item = ORM::factory("item", $item_id); $root = $item->id == 1 ? $item : ORM::factory("item", 1); access::required("view", $item); @@ -36,26 +33,21 @@ class Organize_Controller extends Controller { $parents[$item->id] = 1; $v->album_tree = $this->_tree($root, $parents); - $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item); + $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item, 0); print $v; } - function content($item_id, $offset=0) { + function content($item_id, $offset) { $item = ORM::factory("item", $item_id); access::required("view", $item); access::required("edit", $item); - - $v = $this->_get_micro_thumb_grid($item, $offset); - print $v->__toString(); + print $this->_get_micro_thumb_grid($item, $offset); } - private function _get_micro_thumb_grid($item, $offset=0) { + private function _get_micro_thumb_grid($item, $offset) { $v = new View("organize_thumb_grid.html"); - $v->item_id = $item->id; - $v->children = $item->children(25, $offset); - $v->thumbsize = self::$_MICRO_THUMB_SIZE; - $v->offset = $offset + 25; - + $v->item = $item; + $v->offset = $offset; return $v; } diff --git a/modules/organize/helpers/organize_event.php b/modules/organize/helpers/organize_event.php index 887d9c2d..7d6b3e24 100644 --- a/modules/organize/helpers/organize_event.php +++ b/modules/organize/helpers/organize_event.php @@ -27,7 +27,7 @@ class organize_event_Core { ->id("organize") ->label(t("Organize Album")) ->css_id("gOrganizeLink") - ->url(url::site("organize/index/{$item->id}"))); + ->url(url::site("organize/dialog/{$item->id}"))); } } } diff --git a/modules/organize/helpers/organize_theme.php b/modules/organize/helpers/organize_theme.php deleted file mode 100644 index 0fd117c3..00000000 --- a/modules/organize/helpers/organize_theme.php +++ /dev/null @@ -1,27 +0,0 @@ -item()) && access::can("edit", $theme->item())) { - $theme->script("organize.js"); - $theme->css("organize.css"); - } - } -} diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index d2006c27..6b4a5934 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -4,6 +4,12 @@ * Dynamically initialize the organize dialog when it is displayed */ init: function(data) { + // Resize with 50 pixels padding all around + var size = $.getViewportSize(); + $("#gDialog").dialog("option", "height", size.height() - 100) + .dialog("option", "width", size.width() - 100) + .dialog("option", "position", "center"); + // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) $(".sf-menu li.sfHover ul").css("z-index", 70); diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 11ce0a37..6001e038 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,4 +1,5 @@ +" />

                    p::purify($title))) ?>

                    @@ -38,13 +39,9 @@
                    + \ No newline at end of file + diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index e6b7aec0..0d54c5c8 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,19 +1,20 @@ - $child): ?> - - is_album()): ?> - - -
                  • - thumb_img(array("class" => "gThumbnail"), $thumbsize, true) ?> -
                  • +children(25, $offset) as $child): ?> +
                  • " + ref="id ?>"> + thumb_img(array("class" => "gThumbnail"), 90, true) ?> +
                  • -= 25): ?> + +children_count() > $offset): ?> - \ No newline at end of file + diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 280bdc5f..99b0dc1a 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,6 +1,5 @@
                  • -
                    gBranchText">
                  - -- cgit v1.2.3 From 7b0ea229b8591c3fba5eb3cb853aa2ac3efd2d97 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 7 Aug 2009 17:07:04 -0700 Subject: Make the organize dialog open properly in IE8, Chrome and FF. For some reason (probably a timing thing) the height of the contents was not being set correctly in FF. So we just hard code an estimate of the size of the Draw handle, and message areas. --- lib/gallery.dialog.js | 8 ++++++-- modules/organize/js/organize.js | 16 +++++++--------- modules/organize/views/organize_dialog.html.php | 4 +--- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'modules/organize') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 51ebb21a..e3597eab 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -59,10 +59,14 @@ var dialogHeight = $("#gDialog").height(); var cssWidth = new String($("#gDialog form").css("width")); var childWidth = cssWidth.replace(/[^0-9]/g,""); + var size = $.gallery_get_viewport_size(); if ($("#gDialog iframe").length) { - dialogWidth = $(window).width() - 100; + dialogWidth = size.width() - 100; // Set the iframe width and height - $("#gDialog iframe").width("100%").height($(window).height() - 100); + $("#gDialog iframe").width("100%").height(size.height() - 100); + } else if ($("#gDialog form").length == 0) { + dialogWidth = size.width() - 100; + $("#gDialog").dialog("option", "height", size.height() - 100); } else if (childWidth == "" || childWidth > 300) { dialogWidth = 500; } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 6b4a5934..853e3eef 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -4,21 +4,19 @@ * Dynamically initialize the organize dialog when it is displayed */ init: function(data) { - // Resize with 50 pixels padding all around - var size = $.getViewportSize(); - $("#gDialog").dialog("option", "height", size.height() - 100) - .dialog("option", "width", size.width() - 100) - .dialog("option", "position", "center"); - // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) $(".sf-menu li.sfHover ul").css("z-index", 70); - var height = $("#gOrganizeDetail").innerHeight(); - $("#gMicroThumbPanel").height(height - $("#gOrganizeEditDrawerHandle").outerHeight()); + $("#gDialog").bind("dialogopen", function(event, ui) { + $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 90); + }); + + $("#gDialog").bind("dialogclose", function(event, ui) { + window.location.reload(); + }); $("#gDialog #gMicroThumbDone").click(function(event) { $("#gDialog").dialog("close"); - window.location.reload(); }); $(".gBranchText span").click($.organize.collapse_or_expand_tree); diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 6001e038..0daa328d 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -41,7 +41,5 @@ -- cgit v1.2.3 From 685b1ddf88c8dd7c055c1fb2571060ad1e4f4530 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 7 Aug 2009 21:40:35 -0700 Subject: Enhance how the organize dialog degrades if the browser window is not optimal --- modules/organize/css/organize.css | 2 +- modules/organize/js/organize.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/organize') diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 56ecc309..d33dac0d 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -7,7 +7,6 @@ #gOrganize { overflow: hidden; - height: 100%; } #gOrganize #bd { @@ -25,6 +24,7 @@ #gOrganize .yui-gf #gMessage { margin-bottom: .4em; width: 75%; + white-space: nowrap; } #gOrganizeDetail { diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 853e3eef..03d81a98 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -8,6 +8,7 @@ $(".sf-menu li.sfHover ul").css("z-index", 70); $("#gDialog").bind("dialogopen", function(event, ui) { + $("#gOrganize").height($("#gDialog").innerHeight() - 20); $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 90); }); -- cgit v1.2.3 From 1c5b04a2c5d58838dbea413359c9b114f7077ca8 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 8 Aug 2009 16:26:34 -0700 Subject: Fix the problem where the login page and edit permission pages were supersized based on ly last commit. --- lib/gallery.dialog.js | 2 +- modules/organize/views/organize_dialog.html.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/organize') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 6c2993fd..ace588f6 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -61,7 +61,7 @@ dialogWidth = size.width() - 100; // Set the iframe width and height $("#gDialog iframe").width("100%").height(size.height() - 100); - } else if ($("#gDialog form").length == 0) { + } else if ($("#gDialog .gDialogPanel").length) { dialogWidth = size.width() - 100; $("#gDialog").dialog("option", "height", size.height() - 100); } else if (childWidth == "" || childWidth > 300) { diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 0daa328d..b946d82b 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,6 +1,6 @@ " /> -
                  +

                  p::purify($title))) ?>

                  -- cgit v1.2.3 From 39d0098038b828c3cf5d63caa06f1b6d57904f32 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 9 Aug 2009 09:00:10 -0700 Subject: Enable microthumbnail selection --- modules/organize/css/organize.css | 11 ++++++----- modules/organize/js/organize.js | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index d33dac0d..a4b5fdbd 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -95,11 +95,6 @@ padding: .5em; } -.gMicroThumbContainer { -// padding: 0 .5em; -// opacity: .4; -} - .gMicroThumb { display: block; float: left; @@ -107,10 +102,16 @@ height: 9em; margin-bottom: 1em; margin-left: 1em; + opacity: .5; text-align: center; width: 9em; } +.gMicroThumb.ui-selected { + opacity: 1; +} + + .gThumbnail { padding: .5em; } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 03d81a98..05693200 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -5,8 +5,8 @@ */ init: function(data) { // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) - $(".sf-menu li.sfHover ul").css("z-index", 70); - + $(".sf-menu li.sfHover ul").css("z-index", 68); + $("#gDialog").dialog("option", "zIndex", 70); $("#gDialog").bind("dialogopen", function(event, ui) { $("#gOrganize").height($("#gDialog").innerHeight() - 20); $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 90); @@ -22,6 +22,8 @@ $(".gBranchText span").click($.organize.collapse_or_expand_tree); $(".gBranchText").click($.organize.show_album); + + $("#gMicroThumbGrid").selectable({filter: ".gMicroThumb"}); }, /** -- cgit v1.2.3 From 3823f65dfb4114caf9bd9cfbf730638927f6c970 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 12 Aug 2009 21:55:25 -0700 Subject: Implement the first part of drag functionality. Having trouble getting visual feedback of the drop position between thumbnails, so this commit provides a checkpoint for trying various options --- modules/organize/controllers/organize.php | 9 +-- modules/organize/css/organize.css | 9 ++- modules/organize/helpers/organize_theme.php | 28 +++++++++ modules/organize/js/organize.js | 73 +++++++++++++++++++++- modules/organize/views/organize_dialog.html.php | 4 +- .../organize/views/organize_thumb_grid.html.php | 2 +- modules/organize/views/organize_tree.html.php | 4 +- 7 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 modules/organize/helpers/organize_theme.php (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 3a81ef4f..6f83f940 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -60,13 +60,14 @@ class Organize_Controller extends Controller { $v->album_icon = "gBranchEmpty"; $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); - if ($albums->count()) { - $v->album_icon = empty($parents[$item->id]) ? "ui-icon-plus" : "ui-icon-minus"; - - foreach ($albums as $album) { + foreach ($albums as $album) { + if (access::can("view", $album)) { $v->children[] = $this->_tree($album, $parents); } } + if (count($v->children)) { + $v->album_icon = empty($parents[$item->id]) ? "ui-icon-plus" : "ui-icon-minus"; + } return $v; } } diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index a4b5fdbd..1cc7c92c 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -1,3 +1,4 @@ + /******************************************************************* * Dialog wide stylings */ @@ -92,7 +93,7 @@ } #gMicroThumbGrid { - padding: .5em; + padding: 1em; } .gMicroThumb { @@ -107,10 +108,14 @@ width: 9em; } -.gMicroThumb.ui-selected { +.gMicroThumb.ui-state-selected { opacity: 1; } +.ui-selectable-lasso { + z-index: 2000 !important; + border: 1px dashed #13A; +} .gThumbnail { padding: .5em; diff --git a/modules/organize/helpers/organize_theme.php b/modules/organize/helpers/organize_theme.php new file mode 100644 index 00000000..de812261 --- /dev/null +++ b/modules/organize/helpers/organize_theme.php @@ -0,0 +1,28 @@ +item(); + if ($item && access::can("edit", $item) && $item->is_album()) { + $theme->script("organize.js"); + $theme->css("organize.css"); + } + } +} diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 05693200..c9408673 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -1,15 +1,83 @@ (function($) { $.organize = { + micro_thumb_draggable: { + distance: 10, + cursorAt: { left: -10, top: -10}, + appendTo: "#gOrganizeContentPane", + helper: function(event, ui) { + var selected = $("li.ui-state-selected img"), + set = $('
                  ').css({zIndex: 2000, width: 80, height: Math.ceil(selected.length / 5) * 16 }), + offset = $(this).offset(), + click = { left: event.pageX - offset.left, top: event.pageY - offset.top }; + + selected.each(function(i) { + var row = parseInt(i / 5); + var j = i - (row * 5); + + var o = $(this).offset(); + + var copy = $(this).clone() + .css({ + width: $(this).width(), height: $(this).height(), display: "block", + margin: 0, position: 'absolute', outline: '5px solid #fff', + left: o.left - event.pageX, top: o.top - event.pageY + }) + .appendTo(set) + .animate({width: 10, height: 10, outlineWidth: 1, margin: 1, left: (20 * j), top: (row * 20)}, 500); + }); + return set; + }, + start: function(event, ui) { + $("#gMicroThumbPanel").prepend("
                  "); + + $("#gMicroThumbPanel li.ui-state-selected").hide(); + }, + drag: function(event, ui) { + var container = $("#gMicroThumbPanel").get(0); + var scrollTop = container.scrollTop; + var height = $(container).height(); + if (event.pageY > height + scrollTop) { + container.scrollTop += height; + } else if (event.pageY < scrollTop) { + container.scrollTop -= height; + } + }, + stop: function(event, ui) { + $("li.ui-state-selected").show(); + } + }, + + droppable: { + accept: "*", + tolerance: "pointer", + greedy: true, + drop: function(event, ui) { + // @todo do a ajax call to send the rearrange request to the zerver + // organize/move/target_id/ + // post parameters + // before=id|after=id + // source=[id1, id2, ...] + // before or after not supplied then append to end + // return: json { + // result: success | msg, + // tree: null | new tree, + // content: new thumbgrid + // } + } + }, + /** * Dynamically initialize the organize dialog when it is displayed */ init: function(data) { + var self = this; // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475 (target 1.8?) $(".sf-menu li.sfHover ul").css("z-index", 68); $("#gDialog").dialog("option", "zIndex", 70); $("#gDialog").bind("dialogopen", function(event, ui) { $("#gOrganize").height($("#gDialog").innerHeight() - 20); $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 90); + $("#gOrganizeAlbumTree").height($("#gDialog").innerHeight() - 59); }); $("#gDialog").bind("dialogclose", function(event, ui) { @@ -23,7 +91,10 @@ $(".gBranchText span").click($.organize.collapse_or_expand_tree); $(".gBranchText").click($.organize.show_album); - $("#gMicroThumbGrid").selectable({filter: ".gMicroThumb"}); + $("#gMicroThumbPanel").selectable({filter: "li"}); + $("#gMicroThumbPanel img").draggable($.organize.micro_thumb_draggable); + $(".gOrganizeBranch").droppable($.organize.droppable); + $("#gMicroThumbPanel").droppable($.organize.droppable); }, /** diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index b946d82b..f8d6d792 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,5 +1,4 @@ -" />

                  p::purify($title))) ?>

                  @@ -11,7 +10,7 @@
                  -
                  +
                    @@ -39,7 +38,6 @@
                  - diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index 0d54c5c8..b6e3aa11 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -3,7 +3,7 @@
                • " ref="id ?>"> - thumb_img(array("class" => "gThumbnail"), 90, true) ?> + thumb_img(array("class" => "gThumbnail", "ref" => $child->id), 90, true) ?>
                • diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 99b0dc1a..d2ef287a 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,11 +1,11 @@
                • gBranchText"> + class=""> - title) ?> + title) ?>
                    "> -- cgit v1.2.3 From 5a84df9ac501b57cb5b472dc57590eef5e165dc3 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 13 Aug 2009 10:56:50 -0700 Subject: Vertical scrolling of the thumb grid seems to work better now. Wasn't able to get the draggable autoscrolling working, so this is a poor replacemment. --- modules/organize/js/organize.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index c9408673..aadc713a 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -3,7 +3,7 @@ micro_thumb_draggable: { distance: 10, cursorAt: { left: -10, top: -10}, - appendTo: "#gOrganizeContentPane", + //appendTo: "#gOrganizeContentPane", helper: function(event, ui) { var selected = $("li.ui-state-selected img"), set = $('
                    ').css({zIndex: 2000, width: 80, height: Math.ceil(selected.length / 5) * 16 }), @@ -28,21 +28,19 @@ return set; }, start: function(event, ui) { - $("#gMicroThumbPanel").prepend("
                    "); - $("#gMicroThumbPanel li.ui-state-selected").hide(); }, drag: function(event, ui) { - var container = $("#gMicroThumbPanel").get(0); - var scrollTop = container.scrollTop; - var height = $(container).height(); - if (event.pageY > height + scrollTop) { - container.scrollTop += height; - } else if (event.pageY < scrollTop) { - container.scrollTop -= height; + var top = $("#gMicroThumbPanel").offset().top; + var height = $("#gMicroThumbPanel").height(); + if (ui.offset.top > height + top - 20) { + $("#gMicroThumbPanel").get(0).scrollTop += 100; + } else if (ui.offset.top < top + 20) { + $("#gMicroThumbPanel").get(0).scrollTop = Math.max(0, $("#gMicroThumbPanel").get(0).scrollTop - 100); } }, stop: function(event, ui) { + // @todo delete this method when drop is implemented $("li.ui-state-selected").show(); } }, @@ -63,6 +61,7 @@ // tree: null | new tree, // content: new thumbgrid // } + // do forget to reset all the stuff in init when updating the content } }, @@ -92,7 +91,7 @@ $(".gBranchText").click($.organize.show_album); $("#gMicroThumbPanel").selectable({filter: "li"}); - $("#gMicroThumbPanel img").draggable($.organize.micro_thumb_draggable); + $("#gMicroThumbPanel li").draggable($.organize.micro_thumb_draggable); $(".gOrganizeBranch").droppable($.organize.droppable); $("#gMicroThumbPanel").droppable($.organize.droppable); }, -- cgit v1.2.3 From d758266fabff6c9fe4de22fce57bf00962150ee2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 13 Aug 2009 18:58:40 -0700 Subject: Add a visual indicator of the insertion point --- modules/organize/css/organize.css | 16 ++++++---- modules/organize/js/organize.js | 34 ++++++++++++++++------ .../organize/views/organize_thumb_grid.html.php | 5 +++- 3 files changed, 39 insertions(+), 16 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 1cc7c92c..d717bcae 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -96,19 +96,23 @@ padding: 1em; } +.gMicroThumbGridCell { + float: left; + font-size: 0.8em; + padding: .5em !important; + opacity: .5; + border-left: 1px hidden #13A; + border-right: 1px hidden #13A; +} + .gMicroThumb { display: block; - float: left; - font-size: .8em; height: 9em; - margin-bottom: 1em; - margin-left: 1em; - opacity: .5; text-align: center; width: 9em; } -.gMicroThumb.ui-state-selected { +.gMicroThumbGridCell.ui-state-selected { opacity: 1; } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index aadc713a..a1b59676 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -3,10 +3,10 @@ micro_thumb_draggable: { distance: 10, cursorAt: { left: -10, top: -10}, - //appendTo: "#gOrganizeContentPane", + appendTo: "#gMicroThumbPanel", helper: function(event, ui) { - var selected = $("li.ui-state-selected img"), - set = $('
                    ').css({zIndex: 2000, width: 80, height: Math.ceil(selected.length / 5) * 16 }), + var selected = $(".ui-draggable.ui-state-selected img"), + set = $('
                    ').css({zIndex: 2000, width: 80, height: Math.ceil(selected.length / 5) * 16 }), offset = $(this).offset(), click = { left: event.pageX - offset.left, top: event.pageY - offset.top }; @@ -28,7 +28,7 @@ return set; }, start: function(event, ui) { - $("#gMicroThumbPanel li.ui-state-selected").hide(); + $("#gMicroThumbPanel .ui-state-selected").hide(); }, drag: function(event, ui) { var top = $("#gMicroThumbPanel").offset().top; @@ -39,9 +39,10 @@ $("#gMicroThumbPanel").get(0).scrollTop = Math.max(0, $("#gMicroThumbPanel").get(0).scrollTop - 100); } }, + // @todo delete this method when drop is implemented stop: function(event, ui) { - // @todo delete this method when drop is implemented - $("li.ui-state-selected").show(); + $(".ui-state-selected").show(); + $(".gMicroThumbGridCell").css("borderStyle", "none"); } }, @@ -50,7 +51,7 @@ tolerance: "pointer", greedy: true, drop: function(event, ui) { - // @todo do a ajax call to send the rearrange request to the zerver + // @todo do a ajax call to send the rearrange request to the server // organize/move/target_id/ // post parameters // before=id|after=id @@ -90,10 +91,24 @@ $(".gBranchText span").click($.organize.collapse_or_expand_tree); $(".gBranchText").click($.organize.show_album); - $("#gMicroThumbPanel").selectable({filter: "li"}); - $("#gMicroThumbPanel li").draggable($.organize.micro_thumb_draggable); + $("#gMicroThumbPanel").selectable({filter: ".gMicroThumbGridCell"}); $(".gOrganizeBranch").droppable($.organize.droppable); $("#gMicroThumbPanel").droppable($.organize.droppable); + + $.organize.set_handlers(); + }, + + set_handlers: function() { + $(".gMicroThumbGridCell").draggable($.organize.micro_thumb_draggable); + $(".gMicroThumbGridCell").mousemove(function(event) { + if ($(".gDragHelper").length) { + $(".gMicroThumbGridCell").css("borderStyle", "none"); + console.log("pageX:" + event.pageX + ", offset.left:" + $(this).offset().left + ", width:" + $(this).width()); + var side = event.pageX < $(this).offset().left + $(this).width() / 2 ? + "hidden hidden hidden solid" : "hidden solid hidden hidden"; + $(this).css("borderStyle", side); + } + }); }, /** @@ -119,6 +134,7 @@ var url = $("#gMicroThumbPanel").attr("ref").replace("__ITEM_ID__", id).replace("__OFFSET__", 0); $.get(url, function(data) { $("#gMicroThumbGrid").html(data); + $.organize.set_handlers(); }); } }; diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index b6e3aa11..b41c54e8 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,9 +1,11 @@ children(25, $offset) as $child): ?> -
                  • +
                    " ref="id ?>"> thumb_img(array("class" => "gThumbnail", "ref" => $child->id), 90, true) ?> +
                  • @@ -13,6 +15,7 @@ $.get("id/" . ($offset + 25)) ?>", function(data) { $("#gMicroThumbGrid").append(data); + $.organize.set_handlers(); } ); }, 50); -- cgit v1.2.3 From eeae2dc56c822a2fa32278bfe0f52bc43f665ec2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 13 Aug 2009 21:31:20 -0700 Subject: Added javascript portion of the drop functionality. At this point you can drag selected images and drop them on the micro thumb grid in a different position or onto a branch in the gallery tree. No ajax call is made, it just writes the generated url and post data to the console, so it only works in ff right now. --- modules/organize/js/organize.js | 90 +++++++++++++++------- modules/organize/views/organize_dialog.html.php | 3 + .../organize/views/organize_thumb_grid.html.php | 5 +- 3 files changed, 68 insertions(+), 30 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index a1b59676..07c07286 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -46,23 +46,68 @@ } }, - droppable: { + content_droppable: { accept: "*", tolerance: "pointer", greedy: true, drop: function(event, ui) { - // @todo do a ajax call to send the rearrange request to the server - // organize/move/target_id/ - // post parameters - // before=id|after=id - // source=[id1, id2, ...] - // before or after not supplied then append to end - // return: json { - // result: success | msg, - // tree: null | new tree, - // content: new thumbgrid - // } - // do forget to reset all the stuff in init when updating the content + $.organize.do_drop({ + parent_id: $(".gBranchSelected").attr("ref"), + target_id: $(".currentDropTarget").attr("ref"), + position: $(".currentDropTarget").css("borderLeftStyle") == "solid" ? "before" : "after", + source: $(ui.helper).children("img") + }); + } + }, + + branch_droppable: { + accept: "*", + tolerance: "pointer", + greedy: true, + drop: function(event, ui) { + $.organize.do_drop({ + parent_id: $(event.target).attr("ref"), + target_id: -1, + position: "after", + source: $(ui.helper).children("img") + }); + } + }, + + do_drop:function(drop_parms) { + var source_ids = ""; + $(drop_parms.source).each(function(i) { + source_ids += (source_ids.length ? "&" : "") + "source_id[" + i + "]=" + $(this).attr("ref"); + }); + var url = drop_url.replace("__PARENT_ID__", drop_parms.parent_id) + .replace("__POSITION__", drop_parms.position) + .replace("__TARGET_ID__", drop_parms.target_id); + + console.group("do_drop"); + console.log("Generated url: " + url); + console.log("Post data(ids to move): " + source_ids); + console.groupEnd(); + // @todo do a ajax call to send the rearrange request to the server + // organize/move/parent_id/before|after/-1|target_id + // post parameters + // source=[id1, id2, ...] + // before or after not supplied then append to end + // return: json { + // result: success | msg, + // tree: null | new tree, + // content: new thumbgrid + // } + // do forget to reset all the stuff in init when updating the content + }, + + mouse_move_handler: function(event) { + if ($(".gDragHelper").length) { + $(".gMicroThumbGridCell").css("borderStyle", "hidden"); + $(".currentDropTarget").removeClass("currentDropTarget"); + var borderStyle = event.pageX < $(this).offset().left + $(this).width() / 2 ? + "borderLeftStyle" : "borderRightStyle"; + $(this).css(borderStyle, "solid"); + $(this).addClass("currentDropTarget"); } }, @@ -88,27 +133,18 @@ $("#gDialog").dialog("close"); }); - $(".gBranchText span").click($.organize.collapse_or_expand_tree); - $(".gBranchText").click($.organize.show_album); - $("#gMicroThumbPanel").selectable({filter: ".gMicroThumbGridCell"}); - $(".gOrganizeBranch").droppable($.organize.droppable); - $("#gMicroThumbPanel").droppable($.organize.droppable); + $("#gMicroThumbPanel").droppable($.organize.content_droppable); $.organize.set_handlers(); }, set_handlers: function() { $(".gMicroThumbGridCell").draggable($.organize.micro_thumb_draggable); - $(".gMicroThumbGridCell").mousemove(function(event) { - if ($(".gDragHelper").length) { - $(".gMicroThumbGridCell").css("borderStyle", "none"); - console.log("pageX:" + event.pageX + ", offset.left:" + $(this).offset().left + ", width:" + $(this).width()); - var side = event.pageX < $(this).offset().left + $(this).width() / 2 ? - "hidden hidden hidden solid" : "hidden solid hidden hidden"; - $(this).css("borderStyle", side); - } - }); + $(".gMicroThumbGridCell").mousemove($.organize.mouse_move_handler); + $(".gOrganizeBranch").droppable($.organize.branch_droppable); + $(".gBranchText span").click($.organize.collapse_or_expand_tree); + $(".gBranchText").click($.organize.show_album); }, /** diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index f8d6d792..982eba9e 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,4 +1,7 @@ +

                    p::purify($title))) ?>

                    diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index b41c54e8..671e0ce4 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,9 +1,8 @@ children(25, $offset) as $child): ?> -
                  • +
                  • " - ref="id ?>"> + class="gMicroThumb is_album() ? "gAlbum" : "gPhoto" ?>"> thumb_img(array("class" => "gThumbnail", "ref" => $child->id), 90, true) ?>
                  • -- cgit v1.2.3 From 76f320ab3d6b1f67055dd913eb5811d0d113682a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 16 Aug 2009 12:36:14 -0700 Subject: In this patch, drag now works to the album tree, but the progress bar is not showing. As well fixed a problem where selectable single clink no longer worked when the album was reloaded. --- modules/gallery/controllers/combined.php | 9 +- modules/organize/controllers/organize.php | 121 +++++++++++++++++++-- modules/organize/js/organize.js | 138 ++++++++++++++---------- modules/organize/views/organize_dialog.html.php | 7 +- 4 files changed, 208 insertions(+), 67 deletions(-) (limited to 'modules/organize') diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index 9a790fdf..c1f42bfe 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -42,22 +42,23 @@ class Combined_Controller extends Controller { private function _emit($type, $key) { $input = Input::instance(); + // We don't need to save the session for this request + Session::abort_save(); + // Our data is immutable, so if they already have a copy then it needs no updating. if ($input->server("HTTP_IF_MODIFIED_SINCE")) { header('HTTP/1.0 304 Not Modified'); header("Expires: Tue, 19 Jan 2038 00:00:00 GMT"); header("Cache-Control: max-age=2678400"); header('Pragma: public'); - return; + Kohana::close_buffers(false); + return ""; } if (empty($key)) { Kohana::show_404(); } - // We don't need to save the session for this request - Session::abort_save(); - $cache = Cache::instance(); $use_gzip = function_exists("gzencode") && stripos($input->server("HTTP_ACCEPT_ENCODING"), "gzip") !== false && diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 6f83f940..1c4a3a69 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -32,8 +32,8 @@ class Organize_Controller extends Controller { } $parents[$item->id] = 1; - $v->album_tree = $this->_tree($root, $parents); - $v->micro_thumb_grid = $this->_get_micro_thumb_grid($item, 0); + $v->album_tree = self::_tree($root, $parents); + $v->micro_thumb_grid = self::_get_micro_thumb_grid($item, 0); print $v; } @@ -41,17 +41,77 @@ class Organize_Controller extends Controller { $item = ORM::factory("item", $item_id); access::required("view", $item); access::required("edit", $item); - print $this->_get_micro_thumb_grid($item, $offset); + print self::_get_micro_thumb_grid($item, $offset); } - private function _get_micro_thumb_grid($item, $offset) { + function move($target_id) { + access::verify_csrf(); + + $task_def = Task_Definition::factory() + ->callback("Organize_Controller::move_task_handler") + ->description(t("Move images")) + ->name(t("Move Images")); + $task = task::create($task_def, array("target_id" => $target_id, + "source_ids" => $this->input->post("source_ids"))); + + print json_encode( + array("result" => "started", + "status" => $task->status, + "url" => url::site("organize/run/$task->id?csrf=" . access::csrf_token()))); + } + + function rearrange($target_id, $before) { + access::verify_csrf(); + $target = ORM::factory("item", $target_id); + $parent = $target->parent(); + access::required("view", $parent); + access::required("edit", $parent); + + $task_def = Task_Definition::factory() + ->callback("Organize_Controller::rearrange_task_handler") + ->description(t("Rearrange Image")) + ->name(t("Rearrange Images")); + $task = task::create($task_def, array("target_id" => $target_id, "before" => $before, + "current" => 0, + "source_ids" => $this->input->post("source_ids"))); + + print json_encode( + array("result" => "started", + "status" => $task->status, + "url" => url::site("organize/run/$task->id?csrf=" . access::csrf_token()))); + } + + private static function _get_micro_thumb_grid($item, $offset) { $v = new View("organize_thumb_grid.html"); $v->item = $item; $v->offset = $offset; return $v; } - private function _tree($item, $parents) { + /** + * Run the task + */ + function run($task_id) { + access::verify_csrf(); + + $task = ORM::factory("task", $task_id); + if (!$task->loaded || $task->owner_id != user::active()->id) { + access::forbidden(); + } + + $task = task::run($task_id); + $results = array("done" => $task->done, "status" => $task->status, + "percent_complete" => $task->percent_complete); + foreach (array("tree", "content") as $data) { + $value = $task->get($data, false); + if ($value !== false) { + $results[$data] = $value; + } + } + print json_encode($results); + } + + private static function _tree($item, $parents) { $v = new View("organize_tree.html"); $v->album = $item; $keys = array_keys($parents); @@ -62,7 +122,7 @@ class Organize_Controller extends Controller { $albums = $item->children(null, 0, array("type" => "album"), array("title" => "ASC")); foreach ($albums as $album) { if (access::can("view", $album)) { - $v->children[] = $this->_tree($album, $parents); + $v->children[] = self::_tree($album, $parents); } } if (count($v->children)) { @@ -70,4 +130,53 @@ class Organize_Controller extends Controller { } return $v; } + + static function move_task_handler($task) { + $start = microtime(true); + if ($task->percent_complete == 0) { + batch::start(); + } + + $target = ORM::factory("item", $task->get("target_id")); + $source_ids = $task->get("source_ids", array()); + $idx = $task->get("current", 0); + $count = 0; + for (; $idx < count($source_ids) && microtime(true) - $start < 0.5; $idx++) { + item::move(ORM::factory("item", $source_ids[$idx]), $target); + $count++; + } + $task->set("current", $idx); + $task->percent_complete = ceil($idx / count($source_ids) * 100); + $task->status = t2("Moved one file", "Moved %count files", $count); + if ($task->percent_complete == 100) { + batch::stop(); + $task->done = true; + $task->state = "success"; + $parents = array(); + foreach ($target->parents() as $parent) { + $parents[$parent->id] = 1; + } + $parents[$target->id] = 1; + // @TODO do we want to set a flag and then generate them in the run method so we don't + // potentially store large data items in the task? + $task->set("tree", self::_tree(ORM::factory("item", 1), $parents)->__toString()); + $task->set("content", self::_get_micro_thumb_grid($target, 0)->__toString()); + } + } + + static function rearrange_task_handler($task) { + // @todo need to + // 1) reset the weights based on the current sort order + // 2) when they are all copied, change the sort order of the parent to "weight" + $task->percent_complete = 100; + //$start = microtime(true); + //$mode = $task->get("mode", "init"); + //$start = microtime(true); + // if (microtime(true) - $start > 0.5) { + // break; + $task->done = true; + $task->state = "success"; + $target = ORM::factory("item", $task->get("target_id")); + $task->set("content", self::_get_micro_thumb_grid($target, 0)->__toString()); + } } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 07c07286..2d7c99fc 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -1,32 +1,37 @@ (function($) { $.organize = { micro_thumb_draggable: { + handle: ".ui-state-selected", distance: 10, cursorAt: { left: -10, top: -10}, appendTo: "#gMicroThumbPanel", helper: function(event, ui) { - var selected = $(".ui-draggable.ui-state-selected img"), - set = $('
                    ').css({zIndex: 2000, width: 80, height: Math.ceil(selected.length / 5) * 16 }), - offset = $(this).offset(), - click = { left: event.pageX - offset.left, top: event.pageY - offset.top }; - - selected.each(function(i) { - var row = parseInt(i / 5); - var j = i - (row * 5); - - var o = $(this).offset(); - - var copy = $(this).clone() - .css({ - width: $(this).width(), height: $(this).height(), display: "block", - margin: 0, position: 'absolute', outline: '5px solid #fff', - left: o.left - event.pageX, top: o.top - event.pageY - }) - .appendTo(set) - .animate({width: 10, height: 10, outlineWidth: 1, margin: 1, left: (20 * j), top: (row * 20)}, 500); - }); - return set; + var selected = $(".ui-draggable.ui-state-selected img"); + if (selected.length) { + var set = $('
                    ').css({zIndex: 2000, width: 80, height: Math.ceil(selected.length / 5) * 16 }), + offset = $(this).offset(), + click = { left: event.pageX - offset.left, top: event.pageY - offset.top }; + + selected.each(function(i) { + var row = parseInt(i / 5); + var j = i - (row * 5); + + var o = $(this).offset(); + + var copy = $(this).clone() + .css({ + width: $(this).width(), height: $(this).height(), display: "block", + margin: 0, position: 'absolute', outline: '5px solid #fff', + left: o.left - event.pageX, top: o.top - event.pageY + }) + .appendTo(set) + .animate({width: 10, height: 10, outlineWidth: 1, margin: 1, left: (20 * j), top: (row * 20)}, 500); + }); + return set; + } + return null; }, + start: function(event, ui) { $("#gMicroThumbPanel .ui-state-selected").hide(); }, @@ -52,9 +57,8 @@ greedy: true, drop: function(event, ui) { $.organize.do_drop({ - parent_id: $(".gBranchSelected").attr("ref"), - target_id: $(".currentDropTarget").attr("ref"), - position: $(".currentDropTarget").css("borderLeftStyle") == "solid" ? "before" : "after", + url: rearrange_url.replace("__TARGET_ID__", $(".currentDropTarget").attr("ref")) + .replace("__BEFORE__", $(".currentDropTarget").css("borderLeftStyle") == "solid"), source: $(ui.helper).children("img") }); } @@ -66,40 +70,61 @@ greedy: true, drop: function(event, ui) { $.organize.do_drop({ - parent_id: $(event.target).attr("ref"), - target_id: -1, - position: "after", + url: move_url.replace("__TARGET_ID__", $(event.target).attr("ref")), source: $(ui.helper).children("img") }); } }, - do_drop:function(drop_parms) { - var source_ids = ""; - $(drop_parms.source).each(function(i) { - source_ids += (source_ids.length ? "&" : "") + "source_id[" + i + "]=" + $(this).attr("ref"); + do_drop:function(options) { + var source_ids = []; + $(options.source).each(function(i) { + source_ids.push($(this).attr("ref")); }); - var url = drop_url.replace("__PARENT_ID__", drop_parms.parent_id) - .replace("__POSITION__", drop_parms.position) - .replace("__TARGET_ID__", drop_parms.target_id); - - console.group("do_drop"); - console.log("Generated url: " + url); - console.log("Post data(ids to move): " + source_ids); - console.groupEnd(); - // @todo do a ajax call to send the rearrange request to the server - // organize/move/parent_id/before|after/-1|target_id - // post parameters - // source=[id1, id2, ...] - // before or after not supplied then append to end - // return: json { - // result: success | msg, - // tree: null | new tree, - // content: new thumbgrid - // } - // do forget to reset all the stuff in init when updating the content + + if (source_ids.length) { + $("#gOrganize .gProgressBar").progressbar().progressbar("value", 0); + $("#gOrganizeProgress").slideDown("fast", function() { + $.ajax({ + url: options.url, + type: "POST", + async: false, + data: { "source_ids[]": source_ids }, + dataType: "json", + success: function(data, textStatus) { + $("#gStatus").html(data.status); + $("#gOrganize .gProgressBar").progressbar("value", data.percent_complete); + setTimeout(function() { $.organize._run_task(data.url); }, 0); + } + }); + }); + } }, + _run_task: function(url) { + $.ajax({ + url: url, + async: false, + dataType: "json", + success: function(data, textStatus) { + $("#gStatus").html(data.status); + $("#gOrganize .gProgressBar").progressbar("value", data.percent_complete); + if (data.done) { + $("#gProgress").slideUp(); + // Don't forget to refresh the content pane and tree + if (data.tree) { + $("#gOrganizeAlbumTree").html(data.tree); + } + if (data.content) { + $("#gMicroThumbGrid").html(data.content); + } + $.organize.set_handlers(); + } else { + setTimeout(function() { $.organize._run_task(url); }, 0); + } + } + }); + }, mouse_move_handler: function(event) { if ($(".gDragHelper").length) { $(".gMicroThumbGridCell").css("borderStyle", "hidden"); @@ -121,8 +146,8 @@ $("#gDialog").dialog("option", "zIndex", 70); $("#gDialog").bind("dialogopen", function(event, ui) { $("#gOrganize").height($("#gDialog").innerHeight() - 20); - $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 90); - $("#gOrganizeAlbumTree").height($("#gDialog").innerHeight() - 59); + $("#gMicroThumbPanel").height($("#gDialog").innerHeight() - 120); + $("#gOrganizeAlbumTree").height($("#gDialog").innerHeight() - 89); }); $("#gDialog").bind("dialogclose", function(event, ui) { @@ -133,18 +158,18 @@ $("#gDialog").dialog("close"); }); - $("#gMicroThumbPanel").selectable({filter: ".gMicroThumbGridCell"}); - $("#gMicroThumbPanel").droppable($.organize.content_droppable); - $.organize.set_handlers(); }, set_handlers: function() { + $("#gMicroThumbPanel").selectable({filter: ".gMicroThumbGridCell"}); + $("#gMicroThumbPanel").droppable($.organize.content_droppable); + $(".gMicroThumbGridCell").draggable($.organize.micro_thumb_draggable); $(".gMicroThumbGridCell").mousemove($.organize.mouse_move_handler); $(".gOrganizeBranch").droppable($.organize.branch_droppable); - $(".gBranchText span").click($.organize.collapse_or_expand_tree); $(".gBranchText").click($.organize.show_album); + $(".gOrganizeBranch .ui-icon").click($.organize.collapse_or_expand_tree); }, /** @@ -164,6 +189,7 @@ if ($(event.currentTarget).hasClass("gBranchSelected")) { return; } + $("#gMicroThumbPanel").selectable("destroy"); var id = $(event.currentTarget).attr("ref"); $(".gBranchSelected").removeClass("gBranchSelected"); $("#gOrganizeBranch-" + id).addClass("gBranchSelected"); diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index 982eba9e..46f9ad9b 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -1,6 +1,7 @@

                    p::purify($title))) ?>

                    @@ -39,6 +40,10 @@
                    +
                • -

                  p::purify($title))) ?>

                  +

                  p::purify($album->title))) ?>

                  @@ -27,15 +28,14 @@
                -
                -
                -
                -
                -
                - -
                -
                +
                + +
                + + "gOrganizeSortColumn"), album::get_sort_order_options(), $album->sort_column) ?> + "gOrganizeSortDir"), array("ASC" => "Ascending", "DESC" => "Descending"), $album->sort_order) ?> +
                diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php index 5adb487a..31dc9af5 100644 --- a/modules/organize/views/organize_thumb_grid.html.php +++ b/modules/organize/views/organize_thumb_grid.html.php @@ -1,5 +1,5 @@ -children(25, $offset) as $child): ?> +children(25, $offset) as $child): ?>
              • "> @@ -8,10 +8,10 @@
              • -children_count() > $offset): ?> +children_count() > $offset): ?>
                -

                p::purify($album->title))) ?>

                +

                SafeString::purify($album->title))) ?>

                diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 36f900ac..387d5977 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -5,7 +5,7 @@ - title) ?> + title) ?>
                  @@ -17,7 +17,7 @@ " ref="id ?>"> - title) ?> + title) ?> id == $album->id): ?> @@ -29,7 +29,7 @@ - title) ?> + title) ?> -- cgit v1.2.3 From 483d8df91b443a20a614eb5864cabb2a66ac72d2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 29 Aug 2009 16:33:22 -0700 Subject: Change the organize tree to expand/collapse. It doesn't properly open up to the album that you're viewing, and if you move a photo to a different album it'll reload the entire album tree. --- modules/organize/controllers/organize.php | 18 +++++----- modules/organize/js/organize.js | 26 ++++++++++++++ modules/organize/views/organize_dialog.html.php | 1 + modules/organize/views/organize_tree.html.php | 46 +++++++------------------ 4 files changed, 47 insertions(+), 44 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 2b966657..3cbcfb28 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -25,7 +25,7 @@ class Organize_Controller extends Controller { $v = new View("organize_dialog.html"); $v->album = $album; - $v->album_tree = self::_tree($album); + $v->album_tree = self::_tree(ORM::factory("item", 1)); $v->micro_thumb_grid = self::_get_micro_thumb_grid($album, 0); print $v; } @@ -50,7 +50,7 @@ class Organize_Controller extends Controller { } print json_encode( - array("tree" => self::_tree($album)->__toString(), + array("tree" => self::_tree(ORM::factory("item", 1))->__toString(), "grid" => self::_get_micro_thumb_grid($album, 0)->__toString())); } @@ -132,17 +132,15 @@ class Organize_Controller extends Controller { return $v; } + public function tree($album_id) { + $album = ORM::factory("item", $album_id); + access::required("view", $album); + print self::_tree($album); + } + private static function _tree($album) { $v = new View("organize_tree.html"); - $v->parents = $album->parents(); $v->album = $album; - - if ($album->id == 1) { - $v->peers = array($album); - } else { - $v->peers = $album->parent()->children(null, 0, array("type" => "album")); - } - return $v; } } diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 04e14a2f..3dbd0c89 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -159,8 +159,34 @@ $(".gMicroThumbGridCell").mousemove($.organize.mouse_move_handler); $(".gOrganizeAlbum").droppable($.organize.branch_droppable); $(".gAlbumText").click($.organize.show_album); + $("#gOrganizeAlbumTree .ui-icon-plus,#gOrganizeAlbumTree .ui-icon-minus").click($.organize.toggle_branch); }, + toggle_branch: function(event) { + event.preventDefault(); + var target = $(event.currentTarget); + var branch = $(target).parent(); + var id = $(event.currentTarget).parent().attr("ref"); + + if ($(target).hasClass("ui-icon-plus")) { + // Expanding + if (!branch.find("ul").length) { + $.get(tree_url.replace("__ALBUM_ID__", id), { }, + function(data) { + branch.replaceWith(data); + $.organize.set_handlers(); + } + ); + } else { + branch.find("ul:eq(0)").slideDown(); + } + } else { + // Contracting + branch.find("ul:eq(0)").slideUp(); + } + $(target).toggleClass("ui-icon-plus"); + $(target).toggleClass("ui-icon-minus"); + }, /** * When the text of a selection is clicked, then show that albums contents diff --git a/modules/organize/views/organize_dialog.html.php b/modules/organize/views/organize_dialog.html.php index b03c066c..d4196460 100644 --- a/modules/organize/views/organize_dialog.html.php +++ b/modules/organize/views/organize_dialog.html.php @@ -3,6 +3,7 @@ var move_url = ""; var rearrange_url = ""; var sort_order_url = ""; + var tree_url = "";

                  p::purify($album->title))) ?>

                  diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 36f900ac..4677234c 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,44 +1,22 @@ - -
                • " - ref="id ?>"> +
                • " + ref="id ?>"> - - title) ?> + + title) ?> -
                    - - - -
                  • " - ref="id ?>"> - "> +
                      + children(null, 0, array("type" => "album")) as $child): ?> +
                    • " + ref="id ?>"> + - " - ref="id ?>"> - title) ?> + + title) ?> - - id == $album->id): ?> -
                        - children(null, 0, array("type" => "album")) as $child): ?> -
                      • " - ref="id ?>"> - - - - title) ?> - -
                      • - -
                      -
                    • - -
                  • - + -- cgit v1.2.3 From b9bd1681a3b1496c0f1bbe5e6254ab4fd0c9fe30 Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Sat, 29 Aug 2009 22:54:20 -0700 Subject: Update all code to use helper method html::clean(), html::purify(), ... instead of SafeString directly. --- modules/comment/controllers/comments.php | 8 ++++---- modules/comment/helpers/comment_rss.php | 8 ++++---- modules/comment/views/admin_block_recent_comments.html.php | 6 +++--- modules/comment/views/admin_comments.html.php | 10 +++++----- modules/comment/views/comment.html.php | 6 +++--- modules/comment/views/comment.mrss.php | 12 ++++++------ modules/comment/views/comments.html.php | 6 +++--- modules/digibug/controllers/digibug.php | 2 +- modules/exif/views/exif_dialog.html.php | 4 ++-- modules/g2_import/helpers/g2_import.php | 2 +- modules/gallery/controllers/admin_advanced_settings.php | 2 +- modules/gallery/controllers/quick.php | 10 +++++----- modules/gallery/helpers/MY_html.php | 4 ++-- modules/gallery/helpers/gallery_rss.php | 4 ++-- modules/gallery/helpers/gallery_task.php | 4 ++-- modules/gallery/tests/Html_Helper_Test.php | 4 ++-- modules/gallery/tests/Xss_Security_Test.php | 4 ++-- modules/gallery/views/admin_advanced_settings.html.php | 6 +++--- modules/gallery/views/admin_block_log_entries.html.php | 2 +- modules/gallery/views/admin_block_photo_stream.html.php | 4 ++-- modules/gallery/views/admin_languages.html.php | 4 ++-- modules/gallery/views/admin_maintenance.html.php | 4 ++-- modules/gallery/views/admin_maintenance_show_log.html.php | 2 +- modules/gallery/views/move_tree.html.php | 8 ++++---- modules/gallery/views/permissions_browse.html.php | 4 ++-- modules/gallery/views/permissions_form.html.php | 2 +- modules/gallery/views/simple_uploader.html.php | 14 +++++++------- modules/info/views/info_block.html.php | 10 +++++----- modules/notification/views/comment_published.html.php | 12 ++++++------ modules/notification/views/item_added.html.php | 8 ++++---- modules/notification/views/item_deleted.html.php | 6 +++--- modules/notification/views/item_updated.html.php | 12 ++++++------ modules/organize/views/organize_dialog.html.php | 2 +- modules/organize/views/organize_tree.html.php | 6 +++--- modules/rss/views/feed.mrss.php | 14 +++++++------- modules/rss/views/rss_block.html.php | 2 +- modules/search/views/search.html.php | 6 +++--- modules/server_add/views/admin_server_add.html.php | 2 +- modules/server_add/views/server_add_tree.html.php | 4 ++-- modules/server_add/views/server_add_tree_dialog.html.php | 6 +++--- modules/tag/controllers/admin_tags.php | 2 +- modules/tag/views/admin_tags.html.php | 6 +++--- modules/tag/views/tag_cloud.html.php | 2 +- modules/user/controllers/logout.php | 2 +- modules/user/views/admin_users.html.php | 8 ++++---- modules/user/views/admin_users_group.html.php | 4 ++-- modules/user/views/login.html.php | 2 +- themes/default/views/album.html.php | 6 +++--- themes/default/views/dynamic.html.php | 4 ++-- themes/default/views/header.html.php | 4 ++-- themes/default/views/movie.html.php | 4 ++-- themes/default/views/photo.html.php | 6 +++--- 52 files changed, 143 insertions(+), 143 deletions(-) (limited to 'modules/organize') diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index 87633f4c..82b12893 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -39,9 +39,9 @@ class Comments_Controller extends REST_Controller { foreach ($comments as $comment) { $data[] = array( "id" => $comment->id, - "author_name" => SafeString::of($comment->author_name()), + "author_name" => html::clean($comment->author_name()), "created" => $comment->created, - "text" => nl2br(SafeString::purify($comment->text))); + "text" => nl2br(html::purify($comment->text))); } print json_encode($data); break; @@ -126,9 +126,9 @@ class Comments_Controller extends REST_Controller { array("result" => "success", "data" => array( "id" => $comment->id, - "author_name" => SafeString::of($comment->author_name()), + "author_name" => html::clean($comment->author_name()), "created" => $comment->created, - "text" => nl2br(SafeString::purify($comment->text))))); + "text" => nl2br(html::purify($comment->text))))); } else { $view = new Theme_View("comment.html", "fragment"); $view->comment = $comment; diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index 4151dcd0..b539887b 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -23,7 +23,7 @@ class comment_rss_Core { $feeds["comment/newest"] = t("All new comments"); if ($item) { $feeds["comment/item/$item->id"] = - t("Comments on %title", array("title" => SafeString::purify($item->title))); + t("Comments on %title", array("title" => html::purify($item->title))); } return $feeds; } @@ -49,13 +49,13 @@ class comment_rss_Core { $item = $comment->item(); $feed->children[] = new ArrayObject( array("pub_date" => date("D, d M Y H:i:s T", $comment->created), - "text" => nl2br(SafeString::purify($comment->text)), + "text" => nl2br(html::purify($comment->text)), "thumb_url" => $item->thumb_url(), "thumb_height" => $item->thumb_height, "thumb_width" => $item->thumb_width, "item_uri" => url::abs_site("{$item->type}s/$item->id"), - "title" => SafeString::purify($item->title), - "author" => SafeString::of($comment->author_name())), + "title" => html::purify($item->title), + "author" => html::clean($comment->author_name())), ArrayObject::ARRAY_AS_PROPS); } diff --git a/modules/comment/views/admin_block_recent_comments.html.php b/modules/comment/views/admin_block_recent_comments.html.php index 2c7a5cf1..dc3975e0 100644 --- a/modules/comment/views/admin_block_recent_comments.html.php +++ b/modules/comment/views/admin_block_recent_comments.html.php @@ -4,13 +4,13 @@
                  • "> " class="gAvatar" - alt="author_name()) ?>" + alt="author_name()) ?>" width="32" height="32" /> created) ?> %author_name said %comment_text', - array("author_name" => SafeString::of($comment->author_name()), - "comment_text" => text::limit_words(nl2br(SafeString::purify($comment->text)), 50))); ?> + array("author_name" => html::clean($comment->author_name()), + "comment_text" => text::limit_words(nl2br(html::purify($comment->text)), 50))); ?>
                  diff --git a/modules/comment/views/admin_comments.html.php b/modules/comment/views/admin_comments.html.php index 8b0b4c29..801ce2b3 100644 --- a/modules/comment/views/admin_comments.html.php +++ b/modules/comment/views/admin_comments.html.php @@ -108,12 +108,12 @@ " class="gAvatar" - alt="author_name()) ?>" + alt="author_name()) ?>" width="40" height="40" /> -

                  author_name()) ?>

                  +

                  author_name()) ?>

                • created) ?>

                  - text)) ?> + text)) ?>
                    diff --git a/modules/comment/views/comment.html.php b/modules/comment/views/comment.html.php index 31bb7f4d..1d0786cb 100644 --- a/modules/comment/views/comment.html.php +++ b/modules/comment/views/comment.html.php @@ -4,15 +4,15 @@ " class="gAvatar" - alt="author_name()) ?>" + alt="author_name()) ?>" width="40" height="40" /> gallery::date_time($comment->created), - "author_name" => SafeString::of($comment->author_name()))) ?> + "author_name" => html::clean($comment->author_name()))) ?>

                    - text)) ?> + text)) ?>
                    diff --git a/modules/comment/views/comment.mrss.php b/modules/comment/views/comment.mrss.php index ae7762d9..c2a4b538 100644 --- a/modules/comment/views/comment.mrss.php +++ b/modules/comment/views/comment.mrss.php @@ -6,9 +6,9 @@ xmlns:fh="http://purl.org/syndication/history/1.0"> Gallery 3 - <?= SafeString::of($feed->title) ?> + <?= html::clean($feed->title) ?> uri ?> - description) ?> + description) ?> en-us @@ -22,14 +22,14 @@ children as $child): ?> - <?= SafeString::purify($child->title) ?> - item_uri) ?> - author) ?> + <?= html::purify($child->title) ?> + item_uri) ?> + author) ?> item_uri ?> pub_date ?> text)) ?>

                    +

                    text)) ?>

                    diff --git a/modules/comment/views/comments.html.php b/modules/comment/views/comments.html.php index 9eac0502..1e45c946 100644 --- a/modules/comment/views/comments.html.php +++ b/modules/comment/views/comments.html.php @@ -18,16 +18,16 @@ " class="gAvatar" - alt="author_name()) ?>" + alt="author_name()) ?>" width="40" height="40" /> %name said', array("date" => date("Y-M-d H:i:s", $comment->created), - "name" => SafeString::of($comment->author_name()))); ?> + "name" => html::clean($comment->author_name()))); ?>

                    - text)) ?> + text)) ?>
                    diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 509a8b70..0939704b 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -50,7 +50,7 @@ class Digibug_Controller extends Controller { "image_width_1" => $item->width, "thumb_height_1" => $item->thumb_height, "thumb_width_1" => $item->thumb_width, - "title_1" => SafeString::purify($item->title)); + "title_1" => html::purify($item->title)); print $v; } diff --git a/modules/exif/views/exif_dialog.html.php b/modules/exif/views/exif_dialog.html.php index a981ca09..11d1e212 100644 --- a/modules/exif/views/exif_dialog.html.php +++ b/modules/exif/views/exif_dialog.html.php @@ -14,14 +14,14 @@ - + - + diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index a01ca1db..7e5c6f75 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -590,7 +590,7 @@ class g2_import_Core { self::map($g2_comment->getId(), $comment->id); return t("Imported comment '%comment' for item with id: %id", array("id" => $comment->item_id, - "comment" => text::limit_words(nl2br(SafeString::purify($comment->text)), 50))); + "comment" => text::limit_words(nl2br(html::purify($comment->text)), 50))); } /** diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index d727b654..43c77340 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -46,7 +46,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller { module::set_var($module_name, $var_name, Input::instance()->post("value")); message::success( t("Saved value for %var (%module_name)", - array("var" => SafeString::of($var_name), "module_name" => $module_name))); + array("var" => html::clean($var_name), "module_name" => $module_name))); print json_encode(array("result" => "success")); } diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 8fddb563..20731f9c 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -75,7 +75,7 @@ class Quick_Controller extends Controller { access::required("view", $item->parent()); access::required("edit", $item->parent()); - $msg = t("Made %title this album's cover", array("title" => SafeString::purify($item->title))); + $msg = t("Made %title this album's cover", array("title" => html::purify($item->title))); item::make_album_cover($item); message::success($msg); @@ -91,10 +91,10 @@ class Quick_Controller extends Controller { if ($item->is_album()) { print t( "Delete the album %title? All photos and movies in the album will also be deleted.", - array("title" => SafeString::purify($item->title))); + array("title" => html::purify($item->title))); } else { print t("Are you sure you want to delete %title?", - array("title" => SafeString::purify($item->title))); + array("title" => html::purify($item->title))); } $form = item::get_delete_form($item); @@ -108,9 +108,9 @@ class Quick_Controller extends Controller { access::required("edit", $item); if ($item->is_album()) { - $msg = t("Deleted album %title", array("title" => SafeString::purify($item->title))); + $msg = t("Deleted album %title", array("title" => html::purify($item->title))); } else { - $msg = t("Deleted photo %title", array("title" => SafeString::purify($item->title))); + $msg = t("Deleted photo %title", array("title" => html::purify($item->title))); } $parent = $item->parent(); diff --git a/modules/gallery/helpers/MY_html.php b/modules/gallery/helpers/MY_html.php index eb388811..75114898 100644 --- a/modules/gallery/helpers/MY_html.php +++ b/modules/gallery/helpers/MY_html.php @@ -65,11 +65,11 @@ class html extends html_Core { * * Example:
                        *   
                     
                    -

                    SafeString::purify($album->title))) ?>

                    +

                    html::purify($album->title))) ?>

                    diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 387d5977..5b676889 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -5,7 +5,7 @@ - title) ?> + title) ?>
                      @@ -17,7 +17,7 @@ " ref="id ?>"> - title) ?> + title) ?> id == $album->id): ?> @@ -29,7 +29,7 @@ - title) ?> + title) ?> diff --git a/modules/rss/views/feed.mrss.php b/modules/rss/views/feed.mrss.php index 7298b7f4..731703c7 100644 --- a/modules/rss/views/feed.mrss.php +++ b/modules/rss/views/feed.mrss.php @@ -6,9 +6,9 @@ xmlns:fh="http://purl.org/syndication/history/1.0"> gallery3 - <?= SafeString::of($feed->title) ?> + <?= html::clean($feed->title) ?> uri ?> - description) ?> + description) ?> en-us @@ -22,25 +22,25 @@ children as $child): ?> - <?= SafeString::of($child->title) ?> + <?= html::clean($child->title) ?> type}s/{$child->id}") ?> type}s/{$child->id}") ?> created); ?> description) ?> + description) ?>

                      type == "photo" || $child->type == "album"): ?>
                      type}s/{$child->id}") ?>">
                      - description) ?> + description) ?>

                      ]]>
                      diff --git a/modules/rss/views/rss_block.html.php b/modules/rss/views/rss_block.html.php index cd8db89d..737731b6 100644 --- a/modules/rss/views/rss_block.html.php +++ b/modules/rss/views/rss_block.html.php @@ -5,7 +5,7 @@ - + diff --git a/modules/search/views/search.html.php b/modules/search/views/search.html.php index e5c7b4a6..7963948d 100644 --- a/modules/search/views/search.html.php +++ b/modules/search/views/search.html.php @@ -8,7 +8,7 @@
                      • - +
                      • for_html_attr() ?>" /> @@ -31,10 +31,10 @@ id") ?>"> thumb_img() ?>

                        - title) ?> + title) ?>

                        - description)) ?> + description)) ?>
                      • diff --git a/modules/server_add/views/admin_server_add.html.php b/modules/server_add/views/admin_server_add.html.php index c4439bda..b48a19da 100644 --- a/modules/server_add/views/admin_server_add.html.php +++ b/modules/server_add/views/admin_server_add.html.php @@ -16,7 +16,7 @@ class="gRemoveDir ui-icon ui-icon-trash"> X - +
                      diff --git a/modules/server_add/views/server_add_tree.html.php b/modules/server_add/views/server_add_tree.html.php index 2f65a590..dbae42c5 100644 --- a/modules/server_add/views/server_add_tree.html.php +++ b/modules/server_add/views/server_add_tree.html.php @@ -10,7 +10,7 @@
                    • - +
                        @@ -24,7 +24,7 @@ file=" '\\"')) ?>" > - + diff --git a/modules/server_add/views/server_add_tree_dialog.html.php b/modules/server_add/views/server_add_tree_dialog.html.php index 912e69b6..8eb6e4df 100644 --- a/modules/server_add/views/server_add_tree_dialog.html.php +++ b/modules/server_add/views/server_add_tree_dialog.html.php @@ -5,17 +5,17 @@
                        -

                        SafeString::purify($item->title))) ?>

                        +

                        html::purify($item->title))) ?>

                          parents() as $parent): ?>
                        • - title) ?> + title) ?>
                        • - title) ?> + title) ?>
                        diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index f1b4ca3a..8b8dde21 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -106,7 +106,7 @@ class Admin_Tags_Controller extends Admin_Controller { array("result" => "success", "location" => url::site("admin/tags"), "tag_id" => $tag->id, - "new_tagname" => SafeString::of($tag->name))); + "new_tagname" => html::clean($tag->name))); } else { print json_encode( array("result" => "error", diff --git a/modules/tag/views/admin_tags.html.php b/modules/tag/views/admin_tags.html.php index 30dd0728..3d805c5e 100644 --- a/modules/tag/views/admin_tags.html.php +++ b/modules/tag/views/admin_tags.html.php @@ -32,7 +32,7 @@ name, 0, 1)) ?> - +
                          $tags_per_column): /* new column */ ?> @@ -42,12 +42,12 @@
                        - + diff --git a/modules/user/controllers/logout.php b/modules/user/controllers/logout.php index 4b141a1c..fc3ced56 100644 --- a/modules/user/controllers/logout.php +++ b/modules/user/controllers/logout.php @@ -24,7 +24,7 @@ class Logout_Controller extends Controller { $user = user::active(); user::logout(); log::info("user", t("User %name logged out", array("name" => $user->name)), - html::anchor("user/$user->id", SafeString::of($user->name))); + html::anchor("user/$user->id", html::clean($user->name))); if ($continue_url = $this->input->get("continue")) { $item = url::get_item_from_uri($continue_url); if (access::can("view", $item)) { diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index 36c4f4fd..9455f9d9 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -68,16 +68,16 @@ " title="" - alt="name) ?>" + alt="name) ?>" width="20" height="20" /> - name) ?> + name) ?> - full_name) ?> + full_name) ?> - email) ?> + email) ?> last_login == 0) ? "" : gallery::date($user->last_login) ?> diff --git a/modules/user/views/admin_users_group.html.php b/modules/user/views/admin_users_group.html.php index f89a4392..8418ebc9 100644 --- a/modules/user/views/admin_users_group.html.php +++ b/modules/user/views/admin_users_group.html.php @@ -1,6 +1,6 @@

                        - name) ?> + name) ?> special): ?> id") ?>" title=" $group->name)) ?>" @@ -17,7 +17,7 @@

                          @@ -16,7 +16,7 @@ width="thumb_width ?>" height="thumb_height ?>" /> -

                          title) ?>

                          +

                          title) ?>

                          thumb_bottom($child) ?> diff --git a/themes/default/views/movie.html.php b/themes/default/views/movie.html.php index 237743b7..910814dd 100644 --- a/themes/default/views/movie.html.php +++ b/themes/default/views/movie.html.php @@ -28,8 +28,8 @@ movie_img(array("class" => "gMovie", "id" => "gMovieId-{$item->id}")) ?>
                          -

                          title) ?>

                          -
                          description)) ?>
                          +

                          title) ?>

                          +
                          description)) ?>
                          photo_bottom() ?> diff --git a/themes/default/views/photo.html.php b/themes/default/views/photo.html.php index 5b5cb12b..c601c4cc 100644 --- a/themes/default/views/photo.html.php +++ b/themes/default/views/photo.html.php @@ -5,7 +5,7 @@ -- cgit v1.2.3 From 9fbdcf3efd37e2c6bf67b197b8c93f8790a79cbe Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 5 Sep 2009 13:39:30 -0700 Subject: Change the module installer so that you don't need to provide your own install() function if all you're going to do is to set the version of the module from module.info into the database. This means that for some simple modules, you don't need an install.php file at all. --- modules/akismet/helpers/akismet_installer.php | 4 ---- modules/gallery/helpers/module.php | 9 ++++++++ .../image_block/helpers/image_block_installer.php | 24 ---------------------- modules/info/helpers/info_installer.php | 24 ---------------------- modules/organize/helpers/organize_installer.php | 24 ---------------------- modules/recaptcha/helpers/recaptcha_installer.php | 4 ---- modules/rss/helpers/rss_installer.php | 24 ---------------------- modules/slideshow/helpers/slideshow_installer.php | 4 ---- 8 files changed, 9 insertions(+), 108 deletions(-) delete mode 100644 modules/image_block/helpers/image_block_installer.php delete mode 100644 modules/info/helpers/info_installer.php delete mode 100644 modules/organize/helpers/organize_installer.php delete mode 100644 modules/rss/helpers/rss_installer.php (limited to 'modules/organize') diff --git a/modules/akismet/helpers/akismet_installer.php b/modules/akismet/helpers/akismet_installer.php index 5d8c0e07..b891fc7b 100644 --- a/modules/akismet/helpers/akismet_installer.php +++ b/modules/akismet/helpers/akismet_installer.php @@ -18,10 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class akismet_installer { - static function install() { - module::set_version("akismet", 1); - } - static function activate() { akismet::check_config(); } diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 03d538a9..a3088c38 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -119,6 +119,8 @@ class module_Core { $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "install")) { call_user_func_array(array($installer_class, "install"), array()); + } else { + module::set_version($module_name, 1); } module::load_modules(); @@ -145,6 +147,13 @@ class module_Core { $installer_class = "{$module_name}_installer"; if (method_exists($installer_class, "upgrade")) { call_user_func_array(array($installer_class, "upgrade"), array($version_before)); + } else { + $available = module::available(); + if (isset($available->$module_name->code_version)) { + module::set_version($module_name, $available->$module_name->code_version); + } else { + throw new Exception("@todo UNKNOWN_MODULE"); + } } module::load_modules(); diff --git a/modules/image_block/helpers/image_block_installer.php b/modules/image_block/helpers/image_block_installer.php deleted file mode 100644 index 7ea6a229..00000000 --- a/modules/image_block/helpers/image_block_installer.php +++ /dev/null @@ -1,24 +0,0 @@ - Date: Thu, 10 Sep 2009 06:17:21 -0700 Subject: Changed the check in organize_Controller::move_to: 1) check that target and source are not the same. 2) check that the source is not already a child of the target (use to be a descendant) Fixes #741. --- modules/organize/controllers/organize.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 27299e85..0611c334 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -47,7 +47,7 @@ class Organize_Controller extends Controller { $album = ORM::factory("item", $album_id); foreach ($this->input->post("source_ids") as $source_id) { $source = ORM::factory("item", $source_id); - if (!$album->is_descendant($source)) { + if ($album->id != $source->parent_id && $album->id != $source->id) { item::move($source, $album); } } -- cgit v1.2.3 From bea89be268f242a381e77f94f44b8bdbf3f90ff9 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 10 Sep 2009 07:59:29 -0700 Subject: If the current drop target is not defined, in that we have moved out of the range of the current li elements, then assume the drop is occurring at the end of the list items. Fixes #742 --- modules/organize/js/organize.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index d4449b38..0aeb4f7c 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -56,11 +56,18 @@ tolerance: "pointer", greedy: true, drop: function(event, ui) { - var before_or_after = $(".currentDropTarget").css("borderLeftStyle") == "solid" ? "before" : "after"; + var before_or_after = null; + var target_id = null; + if ($(".currentDropTarget").length) { + before_or_after = $(".currentDropTarget").css("borderLeftStyle") == "solid" ? "before" : "after"; + target_id = $(".currentDropTarget").attr("ref"); + } else { + before_or_after = "after"; + target_id = $("#gOrganizeMicroThumbGrid li:last").attr("ref"); + } $.organize.do_drop({ url: rearrange_url - .replace("__TARGET_ID__", $(".currentDropTarget").attr("ref")) - .replace("__ALBUM_ID__", $(".currentDropTarget").attr("ref")) + .replace("__TARGET_ID__", target_id) .replace("__BEFORE__", before_or_after), source: $(ui.helper).children("img") }); @@ -119,8 +126,8 @@ $(".currentDropTarget").removeClass("currentDropTarget"); var borderStyle = event.pageX < $(this).offset().left + $(this).width() / 2 ? "borderLeftStyle" : "borderRightStyle"; - $(this).css(borderStyle, "solid"); - $(this).addClass("currentDropTarget"); + $(this).addClass("currentDropTarget") + .css(borderStyle, "solid"); } }, @@ -159,6 +166,7 @@ .droppable($.organize.content_droppable); $(".gOrganizeMicroThumbGridCell") .draggable($.organize.micro_thumb_draggable) + .mouseleave($.organize.mouse_leave_handler) .mousemove($.organize.mouse_move_handler); $(".gOrganizeAlbum").droppable($.organize.branch_droppable); $(".gOrganizeAlbumText").click($.organize.show_album); -- cgit v1.2.3 From 2bbe162339075d385431029c713c48c9f6b92639 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 10 Sep 2009 10:09:09 -0700 Subject: A better fix for #741... the original problem was that the source and album variables were reversed --- modules/organize/controllers/organize.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 0611c334..99563327 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -47,7 +47,7 @@ class Organize_Controller extends Controller { $album = ORM::factory("item", $album_id); foreach ($this->input->post("source_ids") as $source_id) { $source = ORM::factory("item", $source_id); - if ($album->id != $source->parent_id && $album->id != $source->id) { + if (!$source->is_descendant($album)) { item::move($source, $album); } } -- cgit v1.2.3 From b550a060450923b5c02d531d33785b5c9eb0d3e9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 10 Sep 2009 10:08:29 -0700 Subject: Rename $album to $target in move_to() --- modules/organize/controllers/organize.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 99563327..1fec6c9b 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -41,14 +41,14 @@ class Organize_Controller extends Controller { "sort_order" => $album->sort_order)); } - function move_to($album_id) { + function move_to($target_album_id) { access::verify_csrf(); - $album = ORM::factory("item", $album_id); + $target_album = ORM::factory("item", $target_album_id); foreach ($this->input->post("source_ids") as $source_id) { $source = ORM::factory("item", $source_id); - if (!$source->is_descendant($album)) { - item::move($source, $album); + if (!$source->is_descendant($target_album_)) { + item::move($source, $target_album); } } -- cgit v1.2.3 From 752c85711659eb7f83e6556665175266db8f24f5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 10 Sep 2009 10:28:43 -0700 Subject: Rename ORM_MPTT::is_descendant() to ORM_MPTT::contains() to make the API a little clearer. Write a test for it, too. --- modules/gallery/libraries/ORM_MPTT.php | 4 ++-- modules/gallery/tests/ORM_MPTT_Test.php | 13 +++++++++++++ modules/gallery/views/move_tree.html.php | 4 ++-- modules/organize/controllers/organize.php | 2 +- modules/organize/views/organize_tree.html.php | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) (limited to 'modules/organize') diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 9b3e1f2b..83d2445c 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -110,7 +110,7 @@ class ORM_MPTT_Core extends ORM { * @param ORM $target * @return boolean */ - function is_descendant($target) { + function contains($target) { return ($this->left_ptr <= $target->left_ptr && $this->right_ptr >= $target->right_ptr); } @@ -212,7 +212,7 @@ class ORM_MPTT_Core extends ORM { * @return ORM_MTPP */ function move_to($target) { - if ($this->is_descendant($target)) { + if ($this->contains($target)) { throw new Exception("@todo INVALID_TARGET can't move item inside itself"); } diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index f77f1f34..a749542b 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -97,6 +97,19 @@ class ORM_MPTT_Test extends Unit_Test_Case { $album1_2->children()->select_list()); } + public function cant_move_parent_into_own_subtree_test() { + $album1 = album::create(item::root(), "move_to_test", "move_to_test"); + $album2 = album::create($album1, "move_to_test", "move_to_test"); + $album3 = album::create($album2, "move_to_test", "move_to_test"); + + try { + $album1->move_to($album3); + $self->assert_true(false, "We should be unable to move an item inside its own hierarchy"); + } catch (Exception $e) { + // pass + } + } + public function parent_test() { $root = ORM::factory("item", 1); $album = self::create_item_and_add_to_parent($root); diff --git a/modules/gallery/views/move_tree.html.php b/modules/gallery/views/move_tree.html.php index 623f80ee..e629e1bb 100644 --- a/modules/gallery/views/move_tree.html.php +++ b/modules/gallery/views/move_tree.html.php @@ -1,6 +1,6 @@ thumb_img(array(), 25); ?> -is_descendant($parent)): ?> +contains($parent)): ?> title) ?> title) ?> @@ -9,7 +9,7 @@
                        • thumb_img(array(), 25); ?> - is_descendant($child)): ?> + contains($child)): ?> title) ?> title) ?> diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 1fec6c9b..4639777c 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -47,7 +47,7 @@ class Organize_Controller extends Controller { $target_album = ORM::factory("item", $target_album_id); foreach ($this->input->post("source_ids") as $source_id) { $source = ORM::factory("item", $source_id); - if (!$source->is_descendant($target_album_)) { + if (!$source->contains($target_album)) { item::move($source, $target_album); } } diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index c0c23f94..e5d91c04 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -9,7 +9,7 @@
                            children(null, 0, array("type" => "album")) as $child): ?> - is_descendant($selected)): ?> + contains($selected)): ?> $selected, "album" => $child)); ?>
                          • " -- cgit v1.2.3 From 25ea6085b78423ee651dc21b639c5f10f59dcaf0 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 10 Sep 2009 21:26:07 -0700 Subject: Reset the margins when the mouse is over a thumbnail when dragging. When the border is displayed then adjust the margin to account for the border. Just hidding the border causes things to move. --- modules/organize/js/organize.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 0aeb4f7c..c30f89e0 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -122,12 +122,12 @@ mouse_move_handler: function(event) { if ($(".gDragHelper").length) { - $(".gOrganizeMicroThumbGridCell").css("borderStyle", "hidden"); + $(".gOrganizeMicroThumbGridCell").css({borderStyle: "hidden", margin: "4px"}); $(".currentDropTarget").removeClass("currentDropTarget"); var borderStyle = event.pageX < $(this).offset().left + $(this).width() / 2 ? - "borderLeftStyle" : "borderRightStyle"; + {borderLeftStyle: "solid", marginLeft: "2px"} : {borderRightStyle: "solid", marginRight: "2px"}; $(this).addClass("currentDropTarget") - .css(borderStyle, "solid"); + .css(borderStyle); } }, -- cgit v1.2.3 From 1d40c77c4c05a85fbf6bbb96820fb98cbaa989eb Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 12 Sep 2009 08:53:24 -0700 Subject: Update the organize module to use the release version of jquery Selectable. Unfortunately this does not have the functionality to select additional thumbnails using the ctrl or alt-keys, it is preferable to forking the Selectable component. This functionality should arrive with ui.jquery 1.8.x --- modules/organize/css/organize.css | 5 +++-- modules/organize/js/organize.js | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'modules/organize') diff --git a/modules/organize/css/organize.css b/modules/organize/css/organize.css index 15b5538d..b1cef33c 100644 --- a/modules/organize/css/organize.css +++ b/modules/organize/css/organize.css @@ -102,12 +102,13 @@ width: 9em; } -.gOrganizeMicroThumbGridCell.ui-state-selected { +.gOrganizeMicroThumbGridCell.ui-selecting, +.gOrganizeMicroThumbGridCell.ui-selected { margin: 2px; border: 2px solid #13A; } -.ui-selectable-lasso { +.ui-selectable-helper { z-index: 2000 !important; border: 1px dashed #00F; opacity: 0.25; diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index c30f89e0..7d204708 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -1,12 +1,12 @@ (function($) { $.organize = { micro_thumb_draggable: { - handle: ".ui-state-selected", + handle: ".ui-selected", distance: 10, cursorAt: { left: -10, top: -10}, appendTo: "#gOrganizeMicroThumbPanel", helper: function(event, ui) { - var selected = $(".ui-draggable.ui-state-selected img"); + var selected = $(".ui-draggable.ui-selected img"); if (selected.length) { var set = $('
                            ') .css({ @@ -37,7 +37,7 @@ }, start: function(event, ui) { - $("#gOrganizeMicroThumbPanel .ui-state-selected").hide(); + $("#gOrganizeMicroThumbPanel .ui-selected").hide(); }, drag: function(event, ui) { @@ -80,7 +80,7 @@ greedy: true, drop: function(event, ui) { if ($(event.target).hasClass("gViewOnly")) { - $(".ui-state-selected").show(); + $(".ui-selected").show(); $(".gOrganizeMicroThumbGridCell").css("borderStyle", "none"); } else { $.organize.do_drop({ -- cgit v1.2.3