Load home dashboard faster
[civicrm-core.git] / templates / CRM / common / dashboard.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
6a488035 4 +--------------------------------------------------------------------+
fa938177 5 | Copyright CiviCRM LLC (c) 2004-2016 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
26{literal}
27<script type="text/javascript">
f813f78e 28
3cc60a06 29CRM.$(function($) {
6a488035
TO
30 // The set of options we can use to initialize jQuery.dashboard().
31 var options = {
32 // Optional. Defaults to 3. You'll need to change the width of columns in CSS too.
33 columns: 2,
34
35 // Set this to a link to your server-side script that adds widgets to the dashboard.
36 // The server will need to choose a column to add it to, and change the user's settings
37 // stored server-side.
38 // Required.
39 emptyPlaceholderInner: '',
40
55be4d47
CW
41 widgetsByColumn: {/literal}{$contactDashlets|@json_encode}{literal},
42
6a488035 43 // These define the urls and data objects used for all of the ajax requests to the server.
6a488035
TO
44 ajaxCallbacks: {
45
6a488035
TO
46 // Given the widget ID, the server returns the widget object as an associative array.
47 // E.g. {content: '<p>Widget content</p>', title: 'Widget Title', }
48 //
49 // Required properties:
50 // * title: Text string. Widget title
51 // * content: HTML string. Widget content
52 //
53 // Optional properties:
54 // * classes: String CSS classes that will be added to the widget's <li>
55 // * fullscreen: HTML string for the content of the widget's full screen display.
56 // * settings: Boolean. True if widget has settings pane/display and server-side
57 // callback.
58 //
f813f78e 59 // Server-side executable script callbacks are called and executed on certain
6a488035 60 // events. They can use the widgets property of the dashboard object returned
f813f78e 61 // from jQuery.dashboard(). E.g. dashboard.widgets[widgetID]. They should be
6a488035
TO
62 // javascript files on the server. Set the property to the path of the js file:
63 // * initScript: Called when dashboard is initialising (but not finished).
64 // * fullscreenInitScript: Called when the full screen element is initialising
65 // (being created for the first time).
66 // * fullscreenScript: Called when switching into full screen mode. Executed
67 // every time the widget goes into full-screen mode.
68 // * reloadContentScript: Called when the widget's reloadContent() method is
69 // called. (The widget.reloadContent() method is not used internally so must
70 // have either the callback function or this server-side executable javascript
71 // file implemented for the method to do anything.)
72 //
73 // The 'id' property of data is reserved for the widget ID – a string.
74 getWidget: {
75 url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal},
76 data: {
77 // id: widgetID,
78 op: 'get_widget', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}
79 }
80 },
81
f813f78e 82 // jQuery.dashboard() POSTs the widget-to-column settings here. The server's
6a488035
TO
83 // response is sent to console.log() (if it exists), but is not used. No checks
84 // for errors have been implemented yet.
85 // The 'columns' property of data is reserved for the widget-to-columns settings:
86 // An array (keyed by zero-indexed column ID), of arrays (keyed by widget ID)
87 // of ints; 1 if the widget is minimized. 0 if not.
88 saveColumns: {
89 url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal},
90 data: {
91 // columns: array(0 => array(widgetId => isMinimized, ...), ...),
92 op: 'save_columns', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}
93 }
94 },
f813f78e 95
6a488035
TO
96 // jQuery.dashboard() GETs a widget's settings object and POST's a users submitted
97 // settings back to the server. The return, in both cases, is an associative
98 // array with the new settings markup and other info:
99 //
100 // Required properties:
101 // * markup: HTML string. The inner HTML of the settings form. jQuery.dashboard()
102 // provides the Save and Cancel buttons and wrapping <form> element. Can include
103 // <input>s of any standard type and <select>s, nested in <div>s etc.
104 //
105 // Server-side executable script callbacks (See documentation for
106 // ajaxCallbacks.getWidgets):
107 // * initScript: Called when widget settings are initialising.
108 // * script: Called when switching into settings mode. Executed every time
109 // the widget goes into settings-edit mode.
110 //
111 // The 'id' property of data is reserved for the widget ID.
112 // The 'settings' property of data is reserved for the user-submitted settings.
113 // An array (keyed by the name="" attributes of <input>s), of <input> values.
114 widgetSettings: {
115 url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal},
116 data: {
117 // id: widgetId,
118 // settings: array(name => value, ...),
119 op: 'widget_settings', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal}
120 }
121 }
122 },
123
124 // Optional javascript callbacks for dashboard events.
125 // All callbacks have the dashboard object available as the 'this' variable.
126 // This property and all of it's members are optional.
127 callbacks: {
128 // Called when dashboard is initializing.
129 init: function() {
130 var dashboard = this;
131 },
132
133 // Called when dashboard has finished initializing.
134 ready: function() {
135 var dashboard = this;
136 },
137
138 // Called when dashboard has saved columns to the server.
139 saveColumns: function() {
140 var dashboard = this;
141 },
142
143 // Called when a widget has gone into fullscreen mode.
144 // Takes one argument for the widget.
145 enterFullscreen: function(widget) {
146 var dashboard = this;
147 },
148
149 // Called when a widget has come out of fullscreen mode.
150 // Takes one argument for the widget.
151 exitFullscreen: function(widget) {
152 var dashboard = this;
153 }
154 },
155
156 // Optional javascript callbacks for widget events.
157 // All callbacks have the respective widget object available as the 'this' variable.
158 // This property and all of it's members are optional.
159 widgetCallbacks: {
160 // Called when a widget has been gotten from the server.
161 get: function() {
162 var widget = this;
163 },
164
165 // Called when an external script has invoked the widget.reloadContent() method.
166 // (The widget.reloadContent() method is not used internally so must have either
167 // this callback function or a server-side executable javascript file implemented
168 // for the method to do anything.)
169 reloadContent: function() {
170 var widget = this;
171 },
172
173 // Called when the widget has gone into settings-edit mode.
174 showSettings: function() {
175 var widget = this;
176 },
177
178 // Called when the widget's settings have been saved to the server.
179 saveSettings: function() {
180 var widget = this;
181 },
182
183 // Called when the widget has gone out of settings-edit mode.
184 hideSettings: function() {
185 var widget = this;
186 },
187
188 // Called when the widget has been removed from the dashboard.
189 remove: function() {
190 var widget = this;
191 }
192 }
193 };
194
201ddbaf
CW
195 // Initialize the dashboard using these options
196 $('#civicrm-dashboard').dashboard(options);
6a488035 197
201ddbaf 198});
6a488035
TO
199
200</script>
201{/literal}