Commit dd5ded83 authored by Dries's avatar Dries
Browse files

- Patch #544360 by Gábor Hojtsy, ksenzee, David_Rothstein, seutje, JacobSingh,...

- Patch #544360 by Gábor Hojtsy, ksenzee, David_Rothstein, seutje, JacobSingh, paul.lovvik, EclipseGc et al: Dashboard module 1.0. Wo-hoot!
parent bc9a742f
......@@ -1438,6 +1438,14 @@ function install_finished(&$install_state) {
$output .= '<p>' . st('For more information on configuring Drupal, refer to the <a href="@help">help section</a>.', array('@help' => url('admin/help'))) . '</p>';
}
// Rebuild the module and theme data, in case any newly-installed modules
// need to modify it via hook_system_info_alter(). We need to clear the
// theme static cache first, to make sure that the theme data is actually
// rebuilt.
drupal_static_reset('_system_get_theme_data');
system_get_module_data();
system_get_theme_data();
// Rebuild menu and registry to get content type links registered by the
// profile, and possibly any other menu items created through the tasks.
menu_rebuild();
......
......@@ -243,20 +243,34 @@ function block_page_build(&$page) {
* The requested region.
*/
function block_get_blocks_by_region($region) {
$weight = 0;
$build = array();
if ($list = block_list($region)) {
foreach ($list as $key => $block) {
$build[$key] = $block->content;
unset($block->content);
$build[$key] += array(
'#block' => $block,
'#weight' => ++$weight,
);
$build[$key]['#theme_wrappers'][] ='block';
}
$build['#sorted'] = TRUE;
$build = _block_get_renderable_array($list);
}
return $build;
}
/**
* Get an array of blocks suitable for drupal_render().
*
* @param $list
* A list of blocks such as that returned by block_list().
* @return
* A renderable array.
*/
function _block_get_renderable_array($list = array()) {
$weight = 0;
$build = array();
foreach ($list as $key => $block) {
$build[$key] = $block->content;
unset($block->content);
$build[$key] += array(
'#block' => $block,
'#weight' => ++$weight,
);
$build[$key]['#theme_wrappers'][] ='block';
}
$build['#sorted'] = TRUE;
return $build;
}
......
/* $Id$ */
#dashboard div.dashboard-region {
float: left;
min-height: 1px;
}
#dashboard div#dashboard_main {
width: 65%;
}
#dashboard div#dashboard_sidebar {
width: 35%;
}
#dashboard div.block {
margin-bottom: 20px;
}
#dashboard .dashboard-region .block {
clear: both;
}
#dashboard div.block h2 {
background-color:#e2e1dc;
padding: 3px 5px;
}
#dashboard div.block div.content {
padding: 10px 5px 5px 5px;
}
#dashboard div.block div.content ul.menu {
margin-left:20px;
}
#dashboard #disabled-blocks .block, #dashboard .block-placeholder {
background: #e2e1dc;
padding: 6px 4px;
margin: 3px 3px 3px 0;
float: left;
-moz-border-radius: 4px;
}
#dashboard .ui-sortable {
border: 3px dashed #ccc;
padding: 10px;
}
#dashboard .canvas-content {
background-color: #4d4d4d;
padding: 10px;
color: #fff;
}
#dashboard .canvas-content a {
color: #fff;
text-decoration: underline;
}
#dashboard #disabled-blocks .ui-sortable {
padding: 0;
background-color: #4d4d4d;
border: 0;
}
#dashboard .canvas-content input {
float: right;
margin: 0 0 0 10px;
}
#dashboard .region {
margin: 5px;
}
#dashboard #disabled-blocks .section {
margin: 0 7em 0 0;
height: 100px;
overflow: auto;
}
#dashboard #disabled-blocks {
padding: 5px 0;
}
#dashboard div.dragging {
width: 30%;
}
#dashboard #disabled-blocks h2 {
display: inline;
font-weight: normal;
white-space: nowrap;
color: #000;
}
#dashboard #disabled-blocks .block .content, #dashboard .ui-sortable-helper .content {
display: none;
}
#dashboard .ui-sortable .block {
cursor: move;
}
#dashboard .dashboard-region .block-placeholder {
margin: 0 0 20px 0;
padding: 0;
display: block;
height: 1.6em;
width: 100%;
}
#dashboard #disabled-blocks .block-placeholder {
width: 30px;
height: 1.6em;
}
; $Id$
name = Dashboard
description = A module that provides a dashboard interface for organizing and tracking various information within your site.
core = 7.x
package = Core
version = VERSION
files[] = dashboard.module
dependencies[] = block
// $Id$
(function ($) {
/**
* Implementation of Drupal.behaviors for dashboard.
*/
Drupal.behaviors.dashboard = {
attach: function () {
$('#dashboard').prepend('<div class="customize"><ul class="action-links"><a href="#">' + Drupal.t('Customize') + '</a></ul><div class="canvas"></div></div>');
$('#dashboard .customize .action-links a').click(Drupal.behaviors.dashboard.enterCustomizeMode);
if ($('#dashboard .region .block').length == 0) {
Drupal.settings.dashboard.launchCustomize = true;
}
Drupal.behaviors.dashboard.addPlaceholders();
if (Drupal.settings.dashboard.launchCustomize) {
Drupal.behaviors.dashboard.enterCustomizeMode();
}
},
addPlaceholders: function() {
$('#dashboard .dashboard-region .region').each(function () {
var empty_text = "";
if ($('.block', this).length == 0) {
// We need a placeholder.
if ($('#dashboard').hasClass('customize_mode')) {
empty_text = Drupal.settings.dashboard.emptyRegionTextActive;
} else {
empty_text = Drupal.settings.dashboard.emptyRegionTextInactive;
}
if ($('.placeholder', this).length == 0) {
$(this).append('<div class="placeholder"></div>');
}
$('.placeholder', this).html(empty_text);
}
else {
$('.placeholder', this).remove();
}
});
},
/**
* Enter "customize" mode by displaying disabled blocks.
*/
enterCustomizeMode: function () {
$('#dashboard').addClass('customize_mode');
Drupal.behaviors.dashboard.addPlaceholders();
$('#dashboard .customize .action-links').hide();
$('div.customize .canvas').load(Drupal.settings.dashboard.drawer, Drupal.behaviors.dashboard.setupDrawer);
},
/**
* Exit "customize" mode by simply forcing a page refresh.
*/
exitCustomizeMode: function () {
$('#dashboard').removeClass('customize_mode');
Drupal.behaviors.dashboard.addPlaceholders();
location.href = Drupal.settings.dashboard.dashboard;
},
/**
* Helper for enterCustomizeMode; sets up drag-and-drop and close button.
*/
setupDrawer: function () {
$('div.customize .canvas-content').prepend('<input type="button" class="form-submit" value="' + Drupal.t('Done') + '"></input>');
$('div.customize .canvas-content input').click(Drupal.behaviors.dashboard.exitCustomizeMode);
// Initialize drag-and-drop.
var regions = $('#dashboard div.region');
regions.sortable({
connectWith: regions,
cursor: 'move',
cursorAt: {top:0},
dropOnEmpty: true,
items: '>div.block, div.disabled-block',
opacity: 0.8,
helper: 'block-dragging',
placeholder: 'block-placeholder clearfix',
start: Drupal.behaviors.dashboard.start,
update: Drupal.behaviors.dashboard.update
});
},
/**
* While dragging, make the block appear as a disabled block
*
* This function is called on the jQuery UI Sortable "start" event.
*
* @param event
* The event that triggered this callback.
* @param ui
* An object containing information about the item that is being dragged.
*/
start: function (event, ui) {
var item = $(ui.item);
// If the block is already in disabled state, don't do anything.
if (!item.hasClass('disabled-block')) {
item.css({height: 'auto'});
}
},
/**
* Send block order to the server, and expand previously disabled blocks.
*
* This function is called on the jQuery UI Sortable "update" event.
*
* @param event
* The event that triggered this callback.
* @param ui
* An object containing information about the item that was just dropped.
*/
update: function (event, ui) {
var item = $(ui.item);
// If the user dragged a disabled block, load the block contents.
if (item.hasClass('disabled-block')) {
var module, delta, itemClass;
itemClass = item.attr('class');
// Determine the block module and delta.
module = itemClass.match(/\bmodule-(\S+)\b/)[1];
delta = itemClass.match(/\bdelta-(\S+)\b/)[1];
// Load the newly enabled block's content.
$.get(Drupal.settings.dashboard.blockContent + '/' + module + '/' + delta, {},
function (block) {
var blockContent = "";
if (block) {
blockContent = $("div.content", $(block));
}
if (!blockContent) {
blockContent = $('<div class="content">' + Drupal.settings.dashboard.emptyBlockText + '</div>');
}
$("div.content", item).after(blockContent).remove();
},
'html'
);
// Remove the "disabled-block" class, so we don't reload its content the
// next time it's dragged.
item.removeClass("disabled-block");
}
Drupal.behaviors.dashboard.addPlaceholders();
// Let the server know what the new block order is.
$.post(Drupal.settings.dashboard.updatePath, {
'form_token': Drupal.settings.dashboard.formToken,
'regions': Drupal.behaviors.dashboard.getOrder
}
);
},
/**
* Return the current order of the blocks in each of the sortable regions,
* in query string format.
*/
getOrder: function () {
var order = [];
$('#dashboard div.region').each(function () {
var region = $(this).parent().attr('id').replace(/-/g, '_');
var blocks = $(this).sortable('toArray');
var i;
for (i = 0; i < blocks.length; i++) {
order.push(region + '[]=' + blocks[i]);
}
});
order = order.join('&');
return order;
}
};
})(jQuery);
<?php
// $Id$
/**
* Implement hook_menu().
*/
function dashboard_menu() {
$items['admin/dashboard'] = array(
'title' => 'Dashboard',
'page callback' => 'dashboard_admin',
'access arguments' => array('access dashboard'),
// Make this appear first, so for example, in admin menus, it shows up on
// the top corner of the window as a convinient "home link".
'weight' => -100,
);
$items['admin/dashboard/customize'] = array(
'title' => 'Dashboard',
'page callback' => 'dashboard_admin',
'page arguments' => array(TRUE),
'access arguments' => array('access dashboard'),
'type' => MENU_CALLBACK,
);
$items['admin/dashboard/drawer'] = array(
'page callback' => 'dashboard_show_disabled',
'access arguments' => array('administer blocks'),
'type' => MENU_CALLBACK,
);
$items['admin/dashboard/block-content/%/%'] = array(
'page callback' => 'dashboard_show_block_content',
'page arguments' => array(3, 4),
'access arguments' => array('administer blocks'),
'type' => MENU_CALLBACK,
);
$items['admin/dashboard/update'] = array(
'page callback' => 'dashboard_update',
'access arguments' => array('administer blocks'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implement hook_block_info_alter().
*
* Skip rendering dashboard blocks when not on the dashboard page itself. This
* prevents expensive dashboard blocks from causing performance issues on pages
* where they will never be displayed.
*/
function dashboard_block_info_alter(&$blocks) {
if (!dashboard_is_visible()) {
foreach ($blocks as $key => $block) {
if (in_array($block->region, dashboard_regions())) {
unset($blocks[$key]);
}
}
}
}
/**
* Implement hook_page_alter().
*
* Display dashboard blocks in the main content region.
*/
function dashboard_page_alter(&$page) {
global $theme_key;
if (dashboard_is_visible()) {
$block_info = array();
// Create a wrapper for the dashboard itself, then insert each dashboard
// region into it.
$page['content']['dashboard'] = array('#theme_wrappers' => array('dashboard'));
foreach (dashboard_regions() as $region) {
// Insert regions even when they are empty, so that they will be
// displayed when the dashboard is being configured.
$page['content']['dashboard'][$region] = !empty($page[$region]) ? $page[$region] : array();
$page['content']['dashboard'][$region]['#dashboard_region'] = $region;
// Allow each dashboard region to be themed differently, or fall back on
// the generic theme wrapper function for dashboard regions.
$page['content']['dashboard'][$region]['#theme_wrappers'][] = array($region, 'dashboard_region');
unset($page[$region]);
$blocks_found = array();
foreach ($page['content']['dashboard'][$region] as $item) {
if (isset($item['#theme_wrappers']) && is_array($item['#theme_wrappers']) && in_array('block', $item['#theme_wrappers'])) {
// If this item is a block, ensure it has a subject.
if (empty($item['#block']->subject)) {
// Locally cache info data for the object for all blocks, in case
// we find a block similarly missing title from the same module.
if (!isset($block_info[$item['#block']->module])) {
$block_info[$item['#block']->module] = module_invoke($item['#block']->module, 'block_info');
}
$item['#block']->subject = $block_info[$item['#block']->module][$item['#block']->delta]['info'];
}
$blocks_found[$item['#block']->module . '_' . $item['#block']->delta] = TRUE;
}
}
// Find blocks which were not yet displayed on the page (were empty), and
// add placeholder items in their place for rendering.
$block_list = db_select('block')
->condition('theme', $theme_key)
->condition('status', 1)
->condition('region', $region)
->fields('block')
->execute();
foreach ($block_list as $block) {
if (!isset($blocks_found[$block->module . '_' . $block->delta])) {
$block->enabled = $block->page_match = TRUE;
$block->content = array('#markup' => '<div class="dashboard-block-empty">(empty)</div>');
if (!isset($block_info[$block->module])) {
$block_info[$block->module] = module_invoke($block->module, 'block_info');
}
$block->subject = t('@title', array('@title' => $block_info[$block->module][$block->delta]['info']));
$block_render = array($block->module . '_' . $block->delta => $block);
$build = _block_get_renderable_array($block_render);
$page['content']['dashboard'][$block->region][] = $build;
}
}
}
}
}
/**
* Implement hook_permission().
*/
function dashboard_permission() {
return array(
'access dashboard' => array(
'title' => t('View the administrative dashboard'),
'description' => t('Access the site-wide dashboard. Modifying the dashboard requires the "Administer blocks" permission.'),
),
);
}
/**
* Implement hook_system_info_alter().
*
* Add regions to each theme to store the dashboard blocks.
*/
function dashboard_system_info_alter(&$info, $file, $type) {
if ($type == 'theme') {
$info['regions'] += dashboard_region_descriptions();
if (module_exists('overlay')) {
$info['overlay_regions'] = !empty($info['overlay_regions']) ? array_merge($info['overlay_regions'], dashboard_regions()) : dashboard_regions();
}
}
}
/**
* Implement hook_theme().
*/
function dashboard_theme() {
return array(
'dashboard' => array(
'arguments' => array('element' => NULL),
),
'dashboard_region' => array(
'arguments' => array('element' => NULL),
),
'dashboard_disabled_blocks' => array(
'arguments' => array('blocks' => NULL),
),
'dashboard_disabled_block' => array(
'arguments' => array('block' => NULL),
),
);
}
/**
* Dashboard page callback.
*
* @param $launch_customize
* Whether to launch in customization mode right away. TRUE or FALSE.
*/
function dashboard_admin($launch_customize = FALSE) {
$output = '';
if (user_access('administer blocks')) {
$output .= '<div class="customize-dashboard js-hide">' . t('To customize the dashboard page, move blocks to the dashboard regions on !block-admin, or enable JavaScript on this page to use the drag-and-drop interface.', array('!block-admin' => l('the block administration page', 'admin/structure/block'))) . '</div>';
drupal_add_js(drupal_get_path('module', 'dashboard') . '/dashboard.js');
$settings = array(
'dashboard' => array(
'drawer' => url('admin/dashboard/drawer'),
'blockContent' => url('admin/dashboard/block-content'),
'updatePath' => url('admin/dashboard/update'),
'formToken' => drupal_get_token('dashboard-update'),
'launchCustomize' => $launch_customize,
'dashboard' => url('admin/dashboard'),
'emptyBlockText' => _dashboard_get_default_string('dashboard_empty_block_text'),
'emptyRegionTextInactive' => _dashboard_get_default_string('dashboard_empty_region_text_inactive'),
'emptyRegionTextActive' => _dashboard_get_default_string('dashboard_empty_region_text_active'),
),
);
drupal_add_js($settings, array('type' => 'setting'));
drupal_add_library('system', 'ui.sortable');
}
// We do not return any main page content, because the content of the page
// will be populated via the dashboard regions in dashboard_page_alter().
return $output;
}
/**
* Returns TRUE if the user is currently viewing the dashboard.
*/
function dashboard_is_visible() {
$menu_item = menu_get_item();
return isset($menu_item['page_callback']) && $menu_item['page_callback'] == 'dashboard_admin';
}
/**
* Return an array of dashboard region descriptions, keyed by region name.
*/
function dashboard_region_descriptions() {
$default_regions = array(
'dashboard_main' => 'Dashboard main',
'dashboard_sidebar' => 'Dashboard sidebar',
);
return variable_get('dashboard_region_descriptions', $default_regions);
}
/**
* Return an array of dashboard region names.
*/
function dashboard_regions() {
return array_keys(dashboard_region_descriptions());
}
/**
* AJAX callback to show disabled blocks in the dashboard customization mode.
*/
function dashboard_show_disabled() {
global $theme_key;
// Blocks are not necessarily initialized at this point.
$blocks = _block_rehash();
// Limit the list to disabled blocks for the current theme.
foreach ($blocks as $key => $block) {
if ($block['theme'] != $theme_key || (!empty($block['status']) && !empty($block['region']))) {
unset($blocks[$key]);
}
}
// Theme the output and end the page request.
print theme('dashboard_disabled_blocks', array('blocks' => $blocks));
exit();
}