CRM-17663 - Dashboard cleanup
authorColeman Watts <coleman@civicrm.org>
Thu, 4 Aug 2016 02:40:46 +0000 (22:40 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 12 Aug 2016 03:32:35 +0000 (23:32 -0400)
CRM/Contact/Page/AJAX.php
CRM/Core/BAO/Dashboard.php
js/jquery/jquery.dashboard.js
templates/CRM/Contact/Page/Dashlet.tpl

index c98b4e78c64b76b8b3e22bf3f2373f08074217b2..8a4675845c679625e10daba8645ab55795517e8b 100644 (file)
@@ -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();
   }
 
   /**
index 51caf401440f8ca26ea7587d02a3aeeb3bd9db2b..3d74b07cfbc45e52c6d7985799892ad8f22065de 100644 (file)
@@ -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)) {
index 34cfec6109ad94753f0ac9edce9b4fd6fdcadea6..c97dc329960414fa05214abd02c61a8b336faea8 100644 (file)
  *      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];
 
       // 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.
 
       // 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.
 
index 7fc60f81b132b101f8faeb8b4d75343bc00da96f..8ddc57d66cbd0482a160c40a2b8cb97bbf047384 100644 (file)
                 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();
+              });
+            });
         });
   });
 </script>