From: Coleman Watts Date: Thu, 4 Aug 2016 02:40:46 +0000 (-0400) Subject: CRM-17663 - Dashboard cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ce2cc43ec96c60c163b504db691d83b2de0669a0;p=civicrm-core.git CRM-17663 - Dashboard cleanup --- diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index c98b4e78c6..8a4675845c 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -569,32 +569,23 @@ LIMIT {$offset}, {$rowCount} * Function used for CiviCRM dashboard operations. */ public static function dashboard() { - $operation = CRM_Utils_Type::escape($_REQUEST['op'], 'String'); - - switch ($operation) { - case 'get_widgets_by_column': - // This would normally be coming from either the database (this user's settings) or a default/initial dashboard configuration. - // get contact id of logged in user - - $dashlets = CRM_Core_BAO_Dashboard::getContactDashlets(); - break; - + switch ($_REQUEST['op']) { case 'get_widget': $dashletID = CRM_Utils_Type::escape($_GET['id'], 'Positive'); - $dashlets = CRM_Core_BAO_Dashboard::getDashletInfo($dashletID); + CRM_Utils_JSON::output($dashlets); break; case 'save_columns': CRM_Core_BAO_Dashboard::saveDashletChanges($_REQUEST['columns']); - CRM_Utils_System::civiExit(); + break; + case 'delete_dashlet': $dashletID = CRM_Utils_Type::escape($_REQUEST['dashlet_id'], 'Positive'); CRM_Core_BAO_Dashboard::deleteDashlet($dashletID); - CRM_Utils_System::civiExit(); } - CRM_Utils_JSON::output($dashlets); + CRM_Utils_System::civiExit(); } /** diff --git a/CRM/Core/BAO/Dashboard.php b/CRM/Core/BAO/Dashboard.php index 51caf40144..3d74b07cfb 100644 --- a/CRM/Core/BAO/Dashboard.php +++ b/CRM/Core/BAO/Dashboard.php @@ -360,9 +360,8 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { * @throws RuntimeException */ public static function saveDashletChanges($columns, $contactID = NULL) { - $session = CRM_Core_Session::singleton(); if (!$contactID) { - $contactID = $session->get('userID'); + $contactID = CRM_Core_Session::getLoggedInContactID(); } if (empty($contactID)) { diff --git a/js/jquery/jquery.dashboard.js b/js/jquery/jquery.dashboard.js index 34cfec6109..c97dc32996 100644 --- a/js/jquery/jquery.dashboard.js +++ b/js/jquery/jquery.dashboard.js @@ -35,13 +35,8 @@ * Sortable * Draggable * UI Core - * - * NOTE: This file is viewed as "legacy" and shouldn't be used to - * develop new functionality. Its lint problems are grandfathered - * (although if someone wants to cleanup+test, please feel welcome). */ -/* jshint ignore:start */ -(function($) { // Create closure. +(function($) { // Constructor for dashboard object. $.fn.dashboard = function(options) { // Public properties of dashboard. @@ -57,7 +52,7 @@ */ // Saves the order of widgets for all columns including the widget.minimized status to options.ajaxCallbacks.saveColumns. - dashboard.saveColumns = function() { + dashboard.saveColumns = function(showStatus) { // Update the display status of the empty placeholders. for (var c in dashboard.columns) { var col = dashboard.columns[c]; @@ -99,9 +94,12 @@ // The ajaxCallback settings overwrite any duplicate properties. $.extend(params, opts.ajaxCallbacks.saveColumns.data); - $.post(opts.ajaxCallbacks.saveColumns.url, params, function(response, status) { + var post = $.post(opts.ajaxCallbacks.saveColumns.url, params, function(response, status) { invokeCallback(opts.callbacks.saveColumns, dashboard); }); + if (showStatus !== false) { + CRM.status({}, post); + } }; // Puts the dashboard into full screen mode, saving element for when the user exits full-screen mode. @@ -434,13 +432,16 @@ // Removes the widget from the dashboard, and saves columns. widget.remove = function() { - if ( confirm( 'Are you sure you want to remove "' + widget.title + '"?') ) { - invokeCallback(opts.widgetCallbacks.remove, widget); - widget.element.fadeOut(opts.animationSpeed, function() { - $(this).remove(); - dashboard.saveColumns(); - }); - } + invokeCallback(opts.widgetCallbacks.remove, widget); + widget.element.fadeOut(opts.animationSpeed, function() { + $(this).remove(); + }); + dashboard.saveColumns(false); + CRM.alert( + ts('You can re-add it by clicking the "Configure Your Dashboard" button.'), + ts('"%1" Removed', {1: widget.title}), + 'success' + ); }; // End public methods of widget. diff --git a/templates/CRM/Contact/Page/Dashlet.tpl b/templates/CRM/Contact/Page/Dashlet.tpl index 7fc60f81b1..8ddc57d66c 100644 --- a/templates/CRM/Contact/Page/Dashlet.tpl +++ b/templates/CRM/Contact/Page/Dashlet.tpl @@ -98,32 +98,32 @@ var postUrl = {/literal}"{crmURL p='civicrm/ajax/dashboard' h=0 }"{literal}; params['op'] = 'save_columns'; params['key'] = {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}; - $.post( postUrl, params, function(response, status) { - // TO DO show done / disable escape action - }); + CRM.status({}, $.post(postUrl, params)); } } $('.delete-dashlet').click( function( ) { - var message = {/literal}'{ts escape="js"}Do you want to remove this dashlet as an "Available Dashlet", AND delete it from all user dashboards?{/ts}'{literal}; - if ( confirm( message) ) { - var dashletID = $(this).parent().attr('id'); - var idState = dashletID.split('-') - - // Build a list of params to post to the server. - var params = {}; + var $dashlet = $(this).closest('.portlet-header'); + CRM.confirm({ + title: {/literal}'{ts escape="js"}Remove Permanently?{/ts}'{literal}, + message: {/literal}'{ts escape="js"}Do you want to remove this dashlet as an "Available Dashlet", AND delete it from all user dashboards?{/ts}'{literal} + }) + .on('crmConfirm:yes', function() { + var dashletID = $dashlet.attr('id'); + var idState = dashletID.split('-'); - params['dashlet_id'] = idState[0]; + // Build a list of params to post to the server. + var params = {dashlet_id: idState[0]}; - // delete dashlet - var postUrl = {/literal}"{crmURL p='civicrm/ajax/dashboard' h=0 }"{literal}; - params['op'] = 'delete_dashlet'; - params['key'] = {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}; - $.post( postUrl, params, function(response, status) { - // delete dom object - $('#' + dashletID ).parent().remove(); - }); - } + // delete dashlet + var postUrl = {/literal}"{crmURL p='civicrm/ajax/dashboard' h=0 }"{literal}; + params['op'] = 'delete_dashlet'; + params['key'] = {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}; + CRM.status({}, $.post(postUrl, params)); + $dashlet.parent().fadeOut('fast', function() { + $(this).remove(); + }); + }); }); });