CRM-17663 - Configurable cache time per dashlet & auto-refresh
[civicrm-core.git] / templates / CRM / common / dashboard.tpl
index c66cb538693b9f9a253b48f1e0b8a575f93de5f1..ee61aacd8b1cad80e9f413ed7a06f3dfe2aee838 100644 (file)
@@ -2,7 +2,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 CRM.$(function($) {
   // The set of options we can use to initialize jQuery.dashboard().
   var options = {
-    // Optional. Defaults to 3.  You'll need to change the width of columns in CSS too.
-    columns: 2,
 
-    // Set this to a link to your server-side script that adds widgets to the dashboard.
-    // The server will need to choose a column to add it to, and change the user's settings
-    // stored server-side.
-    // 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', }
-      //
-      // Required properties:
-      //  * title: Text string.  Widget title
-      //  * content: HTML string.  Widget content
-      //
-      // Optional properties:
-      //  * classes: String CSS classes that will be added to the widget's <li>
-      //  * fullscreen: HTML string for the content of the widget's full screen display.
-      //  * settings: Boolean.  True if widget has settings pane/display and server-side
-      //    callback.
-      //
-      // Server-side executable script callbacks are called and executed on certain
-      // events.  They can use the widgets property of the dashboard object returned
-      // from jQuery.dashboard().  E.g. dashboard.widgets[widgetID].  They should be
-      // javascript files on the server.  Set the property to the path of the js file:
-      //  * initScript:  Called when dashboard is initialising (but not finished).
-      //  * fullscreenInitScript:  Called when the full screen element is initialising
-      //    (being created for the first time).
-      //  * fullscreenScript:  Called when switching into full screen mode.  Executed
-      //    every time the widget goes into full-screen mode.
-      //  * reloadContentScript:  Called when the widget's reloadContent() method is
-      //    called.  (The widget.reloadContent() method is not used internally so must
-      //    have either the callback function or this server-side executable javascript
-      //    file implemented for the method to do anything.)
-      //
-      // The 'id' property of data is reserved for the widget ID – a string.
-      getWidget: {
-        url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal},
-        data: {
-          // id: widgetID,
-          op: 'get_widget', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}
-        }
-      },
-
-      // jQuery.dashboard() POSTs the widget-to-column settings here.  The server's
-      // response is sent to console.log() (if it exists), but is not used.  No checks
-      // for errors have been implemented yet.
+      // jQuery.dashboard() POSTs the widget-to-column settings here.
       // The 'columns' property of data is reserved for the widget-to-columns settings:
       //    An array (keyed by zero-indexed column ID), of arrays (keyed by widget ID)
       //    of ints; 1 if the widget is minimized.  0 if not.
@@ -130,81 +73,26 @@ CRM.$(function($) {
           op: 'widget_settings', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}
         }
       }
-    },
-
-    // Optional javascript callbacks for dashboard events.
-    // All callbacks have the dashboard object available as the 'this' variable.
-    // This property and all of it's members are optional.
-    callbacks: {
-      // Called when dashboard is initializing.
-      init: function() {
-        var dashboard = this;
-      },
-
-      // Called when dashboard has finished initializing.
-      ready: function() {
-        var dashboard = this;
-      },
-
-      // Called when dashboard has saved columns to the server.
-      saveColumns: function() {
-        var dashboard = this;
-      },
-
-      // Called when a widget has gone into fullscreen mode.
-      // Takes one argument for the widget.
-      enterFullscreen: function(widget) {
-        var dashboard = this;
-      },
-
-      // Called when a widget has come out of fullscreen mode.
-      // Takes one argument for the widget.
-      exitFullscreen: function(widget) {
-        var dashboard = this;
-      }
-    },
-
-    // Optional javascript callbacks for widget events.
-    // All callbacks have the respective widget object available as the 'this' variable.
-    // This property and all of it's members are optional.
-    widgetCallbacks: {
-      // Called when a widget has been gotten from the server.
-      get: function() {
-        var widget = this;
-      },
-
-      // Called when an external script has invoked the widget.reloadContent() method.
-      // (The widget.reloadContent() method is not used internally so must have either
-      // this callback function or a server-side executable javascript file implemented
-      // for the method to do anything.)
-      reloadContent: function() {
-        var widget = this;
-      },
-
-      // Called when the widget has gone into settings-edit mode.
-      showSettings: function() {
-        var widget = this;
-      },
-
-      // Called when the widget's settings have been saved to the server.
-      saveSettings: function() {
-        var widget = this;
-      },
-
-      // Called when the widget has gone out of settings-edit mode.
-      hideSettings: function() {
-        var widget = this;
-      },
-
-      // Called when the widget has been removed from the dashboard.
-      remove: function() {
-        var widget = this;
-      }
     }
+
   };
 
-  // Initialize the dashboard using these options
-  $('#civicrm-dashboard').dashboard(options);
+  var dashboard = $('#civicrm-dashboard')
+    .on('mouseover', '.widget-header', function() {
+      $(this).closest('.widget-wrapper').addClass('db-hover-handle');
+    })
+    .on('mouseout', '.widget-header', function() {
+      $(this).closest('.widget-wrapper').removeClass('db-hover-handle');
+    })
+    .dashboard(options);
+
+
+  $('.crm-hover-button.show-refresh').click(function(e) {
+    e.preventDefault();
+    $.each(dashboard.widgets, function(id, widget) {
+      widget.reloadContent();
+    });
+  });
 
 });