Eliminate unnecessary ajax call should speed up load times significantly.
$resources = CRM_Core_Resources::singleton();
$resources->addScriptFile('civicrm', 'js/jquery/jquery.dashboard.js', 0, 'html-header', FALSE);
$resources->addStyleFile('civicrm', 'css/dashboard.css');
+ $this->assign('contactDashlets', CRM_Core_BAO_Dashboard::getContactDashlets());
$resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject);
// Merge in the caller's options with the defaults.
var opts = $.extend({}, $.fn.dashboard.defaults, options);
- // Execution 'forks' here and restarts in init(). Tell the user we're busy with a throbber.
- var throbber = $(opts.throbberMarkup).appendTo(dashboard.element);
- $.getJSON(opts.ajaxCallbacks.getWidgetsByColumn.url, opts.ajaxCallbacks.getWidgetsByColumn.data, init);
- asynchronousRequestCounter++;
+ init(opts.widgetsByColumn);
+
return dashboard;
// End of constructor and private properties for dashboard object.
* Private methods of dashboard.
*/
- // Ajax callback for getWidgetsByColumn.
- function init(widgets, status) {
- asynchronousRequestCounter--;
- throbber.remove();
+ // Initialize widget columns.
+ function init(widgets) {
var markup = '<li class="empty-placeholder">' + opts.emptyPlaceholderInner + '</li>';
// Build the dashboard in the DOM. For each column...
minimize: {
description: ts('Collapse or expand'),
callback: widget.toggleMinimize,
- icon: 'fa-caret-down',
+ icon: 'fa-caret-down'
},
fullscreen: {
description: ts('View fullscreen'),
callback: widget.enterFullscreen,
- icon: 'fa-expand',
+ icon: 'fa-expand'
},
close: {
description: ts('Remove from dashboard'),
// Required.
emptyPlaceholderInner: '',
+ widgetsByColumn: {/literal}{$contactDashlets|@json_encode}{literal},
+
// These define the urls and data objects used for all of the ajax requests to the server.
- // data objects are extended with more properties, as defined below.
- // All are required. All should return JSON.
ajaxCallbacks: {
- // Server returns the configuration of widgets for this user;
- // An array (keyed by zero-indexed column ID), of arrays (keyed by widget ID) of
- // booleans; true if the widget is minimized. False if not.
- // E.g. [{ widgetID: isMinimized, ...}, ...]
- getWidgetsByColumn: {
- url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal},
- data: {
- op: 'get_widgets_by_column', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}
- }
- },
-
// Given the widget ID, the server returns the widget object as an associative array.
// E.g. {content: '<p>Widget content</p>', title: 'Widget Title', }
//