Skip to content

Commit

Permalink
Add item delete support to the organize module. Fixes #1588.
Browse files Browse the repository at this point in the history
  • Loading branch information
beckettmw committed Jan 9, 2011
1 parent d0df489 commit b78a131
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
15 changes: 15 additions & 0 deletions modules/organize/controllers/organize.php
Expand Up @@ -159,6 +159,21 @@ function rearrange() {
json::reply(null);
}

function delete() {
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)) {
$item->delete();
}
}

json::reply(null);
}

private function _get_tree($item, $selected) {
$tree = array();
$children = $item->viewable()
Expand Down
53 changes: 50 additions & 3 deletions modules/organize/views/organize_frame.html.php
Expand Up @@ -11,6 +11,13 @@
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = "<?= url::file("modules/organize/vendor/ext/images/default/s.gif") ?>";
Ext.Ajax.timeout = 1000000; // something really large
// I18N for dialog boxes.
Ext.Msg.buttonText = {
ok: <?= t("OK")->for_js() ?>,
cancel: <?= t("Cancel")->for_js() ?>,
yes: <?= t("Yes")->for_js() ?>,
no: <?= t("No")->for_js() ?>
};

Ext.onReady(function() {
/*
Expand Down Expand Up @@ -94,6 +101,29 @@
});
}

var delete_items = function() {
var nodes = thumb_data_view.getSelectedNodes();
item_ids = [];
for (var i = 0; i != nodes.length; i++) {
var node = Ext.fly(nodes[i]);
item_ids.push(node.getAttribute("rel"));
}
start_busy(<?= t("Deleting...")->for_js() ?>);
Ext.Ajax.request({
url: '<?= url::site("organize/delete") ?>',
method: "post",
success: function() {
stop_busy();
reload_album_data();
},
failure: show_generic_error,
params: {
item_ids: item_ids.join(","),
csrf: '<?= access::csrf_token() ?>'
}
});
};

/*
* ********************************************************************************
* JsonStore, DataView and Panel for viewing albums
Expand Down Expand Up @@ -222,7 +252,7 @@

/*
* ********************************************************************************
* Toolbar with sort column, sort order and a close button.
* Toolbar with sort column, sort order, delete and close buttons.
* ********************************************************************************
*/

Expand Down Expand Up @@ -296,10 +326,27 @@
sort_column_combobox,
sort_order_combobox
]
},
{
}, {
xtype: "spacer",
flex: 10
}, {
xtype: "button",
flex: 2,
text: <?= t("Delete")->for_js() ?>,
listeners: {
"click": function() {
Ext.Msg.show({
title: <?= t("Are you sure you want to delete the selected items?")->for_js() ?>,
buttons: Ext.Msg.YESNO,
fn: function(buttonId) {
if (buttonId == "yes") {
delete_items();
}
}
});
return true;
}
}
}, {
xtype: "button",
flex: 2,
Expand Down

0 comments on commit b78a131

Please sign in to comment.