Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
3 | | CiviCRM version 4.3 | | |
4 | +--------------------------------------------------------------------+ | |
5 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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"> | |
28 | ||
29 | // Create closure, so that we don't accidentally spoil the global/window namespace. | |
30 | cj(function() { | |
31 | // The set of options we can use to initialize jQuery.dashboard(). | |
32 | var options = { | |
33 | // Optional. Defaults to 3. You'll need to change the width of columns in CSS too. | |
34 | columns: 2, | |
35 | ||
36 | // Set this to a link to your server-side script that adds widgets to the dashboard. | |
37 | // The server will need to choose a column to add it to, and change the user's settings | |
38 | // stored server-side. | |
39 | // Required. | |
40 | emptyPlaceholderInner: '', | |
41 | ||
42 | // These define the urls and data objects used for all of the ajax requests to the server. | |
43 | // data objects are extended with more properties, as defined below. | |
44 | // All are required. All should return JSON. | |
45 | ajaxCallbacks: { | |
46 | ||
47 | // Server returns the configuration of widgets for this user; | |
48 | // An array (keyed by zero-indexed column ID), of arrays (keyed by widget ID) of | |
49 | // booleans; true if the widget is minimized. False if not. | |
50 | // E.g. [{ widgetID: isMinimized, ...}, ...] | |
51 | getWidgetsByColumn: { | |
52 | url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal}, | |
53 | data: { | |
54 | op: 'get_widgets_by_column', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal} | |
55 | } | |
56 | }, | |
57 | ||
58 | // Given the widget ID, the server returns the widget object as an associative array. | |
59 | // E.g. {content: '<p>Widget content</p>', title: 'Widget Title', } | |
60 | // | |
61 | // Required properties: | |
62 | // * title: Text string. Widget title | |
63 | // * content: HTML string. Widget content | |
64 | // | |
65 | // Optional properties: | |
66 | // * classes: String CSS classes that will be added to the widget's <li> | |
67 | // * fullscreen: HTML string for the content of the widget's full screen display. | |
68 | // * settings: Boolean. True if widget has settings pane/display and server-side | |
69 | // callback. | |
70 | // | |
71 | // Server-side executable script callbacks are called and executed on certain | |
72 | // events. They can use the widgets property of the dashboard object returned | |
73 | // from jQuery.dashboard(). E.g. dashboard.widgets[widgetID]. They should be | |
74 | // javascript files on the server. Set the property to the path of the js file: | |
75 | // * initScript: Called when dashboard is initialising (but not finished). | |
76 | // * fullscreenInitScript: Called when the full screen element is initialising | |
77 | // (being created for the first time). | |
78 | // * fullscreenScript: Called when switching into full screen mode. Executed | |
79 | // every time the widget goes into full-screen mode. | |
80 | // * reloadContentScript: Called when the widget's reloadContent() method is | |
81 | // called. (The widget.reloadContent() method is not used internally so must | |
82 | // have either the callback function or this server-side executable javascript | |
83 | // file implemented for the method to do anything.) | |
84 | // | |
85 | // The 'id' property of data is reserved for the widget ID – a string. | |
86 | getWidget: { | |
87 | url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal}, | |
88 | data: { | |
89 | // id: widgetID, | |
90 | op: 'get_widget', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal} | |
91 | } | |
92 | }, | |
93 | ||
94 | // jQuery.dashboard() POSTs the widget-to-column settings here. The server's | |
95 | // response is sent to console.log() (if it exists), but is not used. No checks | |
96 | // for errors have been implemented yet. | |
97 | // The 'columns' property of data is reserved for the widget-to-columns settings: | |
98 | // An array (keyed by zero-indexed column ID), of arrays (keyed by widget ID) | |
99 | // of ints; 1 if the widget is minimized. 0 if not. | |
100 | saveColumns: { | |
101 | url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal}, | |
102 | data: { | |
103 | // columns: array(0 => array(widgetId => isMinimized, ...), ...), | |
104 | op: 'save_columns', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal} | |
105 | } | |
106 | }, | |
107 | ||
108 | // jQuery.dashboard() GETs a widget's settings object and POST's a users submitted | |
109 | // settings back to the server. The return, in both cases, is an associative | |
110 | // array with the new settings markup and other info: | |
111 | // | |
112 | // Required properties: | |
113 | // * markup: HTML string. The inner HTML of the settings form. jQuery.dashboard() | |
114 | // provides the Save and Cancel buttons and wrapping <form> element. Can include | |
115 | // <input>s of any standard type and <select>s, nested in <div>s etc. | |
116 | // | |
117 | // Server-side executable script callbacks (See documentation for | |
118 | // ajaxCallbacks.getWidgets): | |
119 | // * initScript: Called when widget settings are initialising. | |
120 | // * script: Called when switching into settings mode. Executed every time | |
121 | // the widget goes into settings-edit mode. | |
122 | // | |
123 | // The 'id' property of data is reserved for the widget ID. | |
124 | // The 'settings' property of data is reserved for the user-submitted settings. | |
125 | // An array (keyed by the name="" attributes of <input>s), of <input> values. | |
126 | widgetSettings: { | |
127 | url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal}, | |
128 | data: { | |
129 | // id: widgetId, | |
130 | // settings: array(name => value, ...), | |
131 | op: 'widget_settings', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal} | |
132 | } | |
133 | } | |
134 | }, | |
135 | ||
136 | // Optional javascript callbacks for dashboard events. | |
137 | // All callbacks have the dashboard object available as the 'this' variable. | |
138 | // This property and all of it's members are optional. | |
139 | callbacks: { | |
140 | // Called when dashboard is initializing. | |
141 | init: function() { | |
142 | var dashboard = this; | |
143 | }, | |
144 | ||
145 | // Called when dashboard has finished initializing. | |
146 | ready: function() { | |
147 | var dashboard = this; | |
148 | }, | |
149 | ||
150 | // Called when dashboard has saved columns to the server. | |
151 | saveColumns: function() { | |
152 | var dashboard = this; | |
153 | }, | |
154 | ||
155 | // Called when a widget has gone into fullscreen mode. | |
156 | // Takes one argument for the widget. | |
157 | enterFullscreen: function(widget) { | |
158 | var dashboard = this; | |
159 | }, | |
160 | ||
161 | // Called when a widget has come out of fullscreen mode. | |
162 | // Takes one argument for the widget. | |
163 | exitFullscreen: function(widget) { | |
164 | var dashboard = this; | |
165 | } | |
166 | }, | |
167 | ||
168 | // Optional javascript callbacks for widget events. | |
169 | // All callbacks have the respective widget object available as the 'this' variable. | |
170 | // This property and all of it's members are optional. | |
171 | widgetCallbacks: { | |
172 | // Called when a widget has been gotten from the server. | |
173 | get: function() { | |
174 | var widget = this; | |
175 | }, | |
176 | ||
177 | // Called when an external script has invoked the widget.reloadContent() method. | |
178 | // (The widget.reloadContent() method is not used internally so must have either | |
179 | // this callback function or a server-side executable javascript file implemented | |
180 | // for the method to do anything.) | |
181 | reloadContent: function() { | |
182 | var widget = this; | |
183 | }, | |
184 | ||
185 | // Called when the widget has gone into settings-edit mode. | |
186 | showSettings: function() { | |
187 | var widget = this; | |
188 | }, | |
189 | ||
190 | // Called when the widget's settings have been saved to the server. | |
191 | saveSettings: function() { | |
192 | var widget = this; | |
193 | }, | |
194 | ||
195 | // Called when the widget has gone out of settings-edit mode. | |
196 | hideSettings: function() { | |
197 | var widget = this; | |
198 | }, | |
199 | ||
200 | // Called when the widget has been removed from the dashboard. | |
201 | remove: function() { | |
202 | var widget = this; | |
203 | } | |
204 | } | |
205 | }; | |
206 | ||
207 | // Initialize the dashboard using these options, and save to the global/window | |
208 | // namesapace so that server-side executable js file callbacks can access | |
209 | // window.dashboardDemo.widgets by ID. | |
210 | window.dashboardDemo = cj('#civicrm-dashboard').dashboard(options); | |
211 | ||
212 | }); // End closure. | |
213 | ||
214 | </script> | |
215 | {/literal} |