* 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();
}
/**
* @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)) {
* 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.
*/
// 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.
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>