diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-01-12 08:26:38 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-12 08:26:38 +0000 |
commit | bc421a615ab89cf5416af12173471235cdf5d297 (patch) | |
tree | a4318a7c649423e2a4a23327ba8aa1fa183397eb /core/controllers | |
parent | ce6d7b8d3799cf5996a7c4fd512bf4efb85d1c5b (diff) |
Implement deleting dashboard blocks.
* Refactor blocks so that they have a separate id vs css_id. This way
we can have a unique identifier for each visual block.
* Store blocks with a random id as their unique identifier
* Add Admin_Dashboard::remove_block() and modify
themes/admin_default/views/block.html.php to call it when you click the
remove box.
Diffstat (limited to 'core/controllers')
-rw-r--r-- | core/controllers/admin_dashboard.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/core/controllers/admin_dashboard.php b/core/controllers/admin_dashboard.php index bd0910a7..1a845e04 100644 --- a/core/controllers/admin_dashboard.php +++ b/core/controllers/admin_dashboard.php @@ -22,6 +22,7 @@ class Admin_Dashboard_Controller extends Admin_Controller { $blocks = unserialize(module::get_var("core", "dashboard_blocks")); $block_adder = new Block(); + $block_adder->id = "core:block_adder"; $block_adder->title = t("Dashboard Content"); $block_adder->content = $this->get_add_block_form(); @@ -54,11 +55,35 @@ class Admin_Dashboard_Controller extends Admin_Controller { url::redirect("admin/dashboard"); } + public function remove_block($id) { + access::verify_csrf(); + $blocks = unserialize(module::get_var("core", "dashboard_blocks")); + + if (array_key_exists($id, $blocks["sidebar"])) { + $deleted = $blocks["sidebar"][$id]; + unset($blocks["sidebar"][$id]); + } else if (array_key_exists($id, $blocks["main"])) { + $deleted = $blocks["main"][$id]; + unset($blocks["main"][$id]); + } + + if (!empty($deleted)) { + module::set_var("core", "dashboard_blocks", serialize($blocks)); + $available = $this->get_block_list(); + $title = $available[join(":", $deleted)]; + message::success(t("Removed <b>{{title}}</b> block", array("title" => $title))); + } + + url::redirect("admin"); + } + private function get_blocks($blocks) { $result = ""; - foreach ($blocks as $desc) { + foreach ($blocks as $id => $desc) { if (method_exists("$desc[0]_dashboard", "get_block")) { - $result .= call_user_func(array("$desc[0]_dashboard", "get_block"), $desc[1]); + $block = call_user_func(array("$desc[0]_dashboard", "get_block"), $desc[1]); + $block->id = $id; + $result .= $block; } } return $result; |