Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
Added delete dashboard functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofvanroy committed Apr 15, 2010
1 parent 8fe51c7 commit 45f7424
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 13 deletions.
2 changes: 1 addition & 1 deletion nice_dash.blocks.inc
Expand Up @@ -14,7 +14,7 @@ function nice_dash_dashboard_block(){
}
}

$links['create']['href'] = 'admin/dashboard/create-dashboard';
$links['create']['href'] = 'admin/dashboard/create';
$links['create']['title'] = t('Create new dashboard');

$links['configure']['href'] = 'admin/dashboard/configure';
Expand Down
24 changes: 22 additions & 2 deletions nice_dash.module
Expand Up @@ -39,7 +39,7 @@ function nice_dash_menu() {
'file' => 'nice_dash.pages.inc'
);

$items['admin/dashboard/configure/create-dashboard'] = array(
$items['admin/dashboard/configure/create'] = array(
'title' => 'Create new dashboard',
'page callback' => 'drupal_get_form',
'page arguments' => array('nice_dash_dashboard_settings_form'),
Expand All @@ -48,6 +48,16 @@ function nice_dash_menu() {
'file' => 'nice_dash.pages.inc'
);

$items['admin/dashboard/configure/delete/%'] = array(
'title' => 'Create new dashboard',
'page callback' => 'drupal_get_form',
'page arguments' => array('nice_dash_dashboard_delete_form',4),
'access arguments' => array('administer nice dashboard'),
'type' => MENU_CALLBACK,
'file' => 'nice_dash.pages.inc'
);


// Implement all the dashboard menu calls
$dashboards = nice_dash_dashboards();

Expand Down Expand Up @@ -242,4 +252,14 @@ function nice_dash_dashboards(){
}

return $rows;
}
}

/**
* Delete dashboard
*/
function nice_dash_remove_dashboard($did){
db_query("DELETE FROM {nice_dash_dashboards} WHERE did = %d", $did);
db_query("DELETE FROM {nice_dash_widgets} WHERE did = %d", $did);
// Clear them from the menu
module_invoke('menu','rebuild');
}
58 changes: 48 additions & 10 deletions nice_dash.pages.inc
Expand Up @@ -33,17 +33,24 @@ function nice_dash_dashboard_page($did = NULL) {
}

function nice_dash_dashboard_overview_page(){
$result = db_query("SELECT did, name FROM nice_dash_dashboards ORDER BY weight ASC");
$headers = array(t('Name'), t('Actions'));
$rows = array();

while($row = db_fetch_array($result)){
$rows[] = array(
l($row['name'], 'admin/dashboard'),
l(t('Edit'), 'admin/dashboard/configure/'.$row['did'].'/edit').' | '.t('Delete'));
}

return theme('table', $headers, $rows);
$dashboards = nice_dash_dashboards();

if(count($dashboards) > 0){
$headers = array(t('Name'), t('Actions'));
$rows = array();
foreach($dashboards as $dashboard){
$rows[] = array(
l($dashboard['name'], 'admin/dashboard'),
l(t('Edit'), 'admin/dashboard/configure/'.$dashboard['did'].'/edit').' | '.l(t('Delete'), 'admin/dashboard/configure/delete/'.$dashboard['did']));

}
return theme('table', $headers, $rows);
}
else {
drupal_set_message(t('You have to create a dashboard first. You can create your first dashboard on the <a href="@create-page">dashboard create page</a>.',array('@create-page' => url("admin/dashboard/configure/create"))), 'warning');
return '';
}
}


Expand Down Expand Up @@ -157,4 +164,35 @@ function nice_dash_dashboard_settings_form_submit(&$form, &$form_state) {
}

module_invoke('menu','rebuild');
}

/**
* Confirm delete form for dashboards
*/
function nice_dash_dashboard_delete_form($form_state, $did) {
$form = array();
$form['did'] = array('#value' => $did, '#type' => 'value');
$dashboard = nice_dash_dashboard_values($did);

if(empty($dashboard)){
drupal_set_message(t('The dashboard you want to delete does not exist. Go back to the <a href="@overview-page">dashboard overview page</a>.', array('@overview-page' => url("admin/dashboard/configure"))),'warning');
return $form;
}

return confirm_form(
$form,
t('Are your sure you want to delete the dashboard %name', array('%name' => $dashboard['name'])),
'admin/dashboard/configure',
t('This action cannot be undone.'),
t('Delete')
);
}

/**
* Submit for confirm delete form for dashboards
*/
function nice_dash_dashboard_delete_form_submit($form, &$form_state) {
nice_dash_remove_dashboard($form_state['values']['did']);
drupal_set_message(t('The dashboard has been removed'));
drupal_goto('admin/dashboard/configure');
}

0 comments on commit 45f7424

Please sign in to comment.