From d45a73777935c86fc5131955831833d7465b5e9d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Jan 2013 01:22:01 -0500 Subject: Update copyright to 2013. Fixes #1953. --- modules/organize/controllers/organize.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/organize/controllers') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index b0c13e7d..f090b8a9 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -1,7 +1,7 @@ Date: Wed, 23 Jan 2013 21:59:02 +0200 Subject: #1952 Add bulk tagging to the Organize module. Allow a user to highlight one or more items (images, videos, or albums), and enter a tag (or tags, comma delimited) and apply it to all of the selected items. The code is based on the batchtag module. If the tags module is not enabled, no changes to the Organize UI will be shown. --- modules/organize/controllers/organize.php | 22 +++++++++ modules/organize/views/organize_frame.html.php | 68 +++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) (limited to 'modules/organize/controllers') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index b0c13e7d..b0158278 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -182,6 +182,28 @@ class Organize_Controller extends Controller { json::reply(null); } + function tag() { + access::verify_csrf(); + $input = Input::instance(); + + foreach (explode(",", $input->post("item_ids")) as $item_id) { + $item = ORM::factory("item", $item_id); + if (access::can("edit", $item)) { + // Assuming the user can view/edit the current item, loop + // through each tag that was submitted and apply it to + // the current item. + foreach (explode(",", $input->post("tag_names")) as $tag_name) { + $tag_name = trim($tag_name); + if ($tag_name) { + tag::add($item, $tag_name); + } + } + } + } + + json::reply(null); + } + private function _get_tree($item, $selected) { $tree = array(); $children = $item->viewable() diff --git a/modules/organize/views/organize_frame.html.php b/modules/organize/views/organize_frame.html.php index 51d49104..c33b7607 100644 --- a/modules/organize/views/organize_frame.html.php +++ b/modules/organize/views/organize_frame.html.php @@ -104,9 +104,33 @@ }); } + var tag_selected_items = function(tag) { + var nodes = thumb_data_view.getSelectedNodes(); + var item_ids = []; + for (var i = 0; i != nodes.length; i++) { + var node = Ext.fly(nodes[i]); + item_ids.push(get_id_from_node(node)); + } + start_busy(for_js() ?>); + Ext.Ajax.request({ + url: '', + method: "post", + success: function() { + stop_busy(); + reload_album_data(); + }, + failure: show_generic_error, + params: { + item_ids: item_ids.join(","), + tag_names: tag, + csrf: '' + } + }); + }; + var delete_selected_items = function() { var nodes = thumb_data_view.getSelectedNodes(); - item_ids = []; + var item_ids = []; for (var i = 0; i != nodes.length; i++) { var node = Ext.fly(nodes[i]); item_ids.push(get_id_from_node(node)); @@ -254,6 +278,7 @@ }); }, "selectionchange": function(v, selections) { + tag_button.setDisabled(!selections.length || !current_album_editable || !tag_textfield.getValue()); delete_button.setDisabled(!selections.length || !current_album_editable); } }, @@ -330,6 +355,31 @@ displayField: "value" }); + var tag_textfield = new Ext.form.TextField({ + flex: 4, + enableKeyEvents: true, + listeners: { + "keyup": function(v, e) { + var nodes = thumb_data_view.getSelectedNodes(); + tag_button.setDisabled(!nodes.length || !current_album_editable || !tag_textfield.getValue()); + } + } + }); + + var tag_button = new Ext.Button({ + flex: 2, + text: for_js() ?>, + cls: "x-btn-text-icon", + id: "tag-button", + disabled: true, + listeners: { + "click": function() { + tag_selected_items(tag_textfield.getValue()); + return true; + } + } + }); + var delete_button = new Ext.Button({ flex: 2, text: for_js() ?>, @@ -375,10 +425,24 @@ sort_column_combobox, sort_order_combobox ] - }, { + }, + + { + xtype: "spacer", + flex: 3 + }, + tag_textfield, + tag_button, + { + xtype: "spacer", + flex: 1 + }, + + { xtype: "spacer", flex: 10 }, + delete_button, { xtype: "button", -- cgit v1.2.3 From aa8fffcd8fc7d16f4bd84a9f8f7ead206d9ce45a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 23 Jan 2013 21:33:19 -0500 Subject: Extract reweighting logic out of Organize_Controller into item::reweight_all_children as an API and write a test for it. Work in progress on #1914. --- modules/gallery/helpers/item.php | 12 ++++++++++++ modules/gallery/tests/Item_Helper_Test.php | 15 +++++++++++++++ modules/organize/controllers/organize.php | 8 +------- 3 files changed, 28 insertions(+), 7 deletions(-) (limited to 'modules/organize/controllers') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 20a865d1..b2c4cadf 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -437,4 +437,16 @@ class item_Core { } return call_user_func_array($callback, $args); } + + /** + * Reset all child weights of a given album to a monotonically increasing sequence based on the + * current sort order of the album. + */ + static function resequence_child_weights($album) { + $weight = 0; + foreach ($album->children() as $child) { + $child->weight = ++$weight; + $child->save(); + } + } } \ No newline at end of file diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index 0c08d1af..63081884 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -235,4 +235,19 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case { $level3b->id, item::find_by_relative_url("{$level1->slug}/{$level2b->slug}/{$level3b->slug}")->id); } + + public function resequence_child_weights_test() { + $album = test::random_album(); + $photo1 = test::random_photo($album); + $photo2 = test::random_photo($album); + $this->assert_true($photo2->weight > $photo1->weight); + + $album->reload(); + $album->sort_order = "DESC"; + $album->save(); + item::resequence_child_weights($album); + + $this->assert_equal(2, $photo1->reload()->weight); + $this->assert_equal(1, $photo2->reload()->weight); + } } diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 97280489..37920020 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -128,13 +128,7 @@ class Organize_Controller extends Controller { access::required("edit", $album); if ($album->sort_column != "weight") { - // Force all the weights into the current order before changing the order to manual - $weight = 0; - foreach ($album->children() as $child) { - $child->weight = ++$weight; - $child->save(); - } - + item::resequence_child_weights($album); $album->sort_column = "weight"; $album->sort_order = "ASC"; $album->save(); -- cgit v1.2.3 From 727a595447ebd331db199f34620d7e037415b582 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 24 Jan 2013 18:13:26 -0500 Subject: Add back a comment that I accidentally removed in the last commit. --- modules/organize/controllers/organize.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/organize/controllers') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 37920020..9e5bce84 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -128,6 +128,8 @@ class Organize_Controller extends Controller { access::required("edit", $album); if ($album->sort_column != "weight") { + // Force all the weights into the current order before changing the order to manual + // @todo: consider making this a trigger in the Item_Model. item::resequence_child_weights($album); $album->sort_column = "weight"; $album->sort_order = "ASC"; -- cgit v1.2.3 From 21a43410141579e4347e2255ae3ab1da9d27ae11 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 25 Jan 2013 15:49:04 -0500 Subject: Fix an assignment-instead-of-comparison bug. I wish PHP had a better warning system for this stuff. In this case it's innocuous because the UI only allows you to rearrange stuff inside a single album, so the assignment doesn't do anything. Fixes #1914. --- modules/organize/controllers/organize.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/organize/controllers') diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 9e5bce84..ba73ae75 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -154,7 +154,7 @@ class Organize_Controller extends Controller { // Move all the source items to the right spots. for ($i = 0; $i < count($source_ids); $i++) { $source = ORM::factory("item", $source_ids[$i]); - if ($source->parent_id = $album->id) { + if ($source->parent_id == $album->id) { $source->weight = $base_weight + $i; $source->save(); } -- cgit v1.2.3