You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: content/developer/reference/frontend/services.rst
+176
Original file line number
Diff line number
Diff line change
@@ -118,6 +118,8 @@ Reference List
118
118
- Short Description
119
119
* - :ref:`cookie <services/cookie>`
120
120
- read or modify cookies
121
+
* - :ref:`effect <services/effect>`
122
+
- display graphical effects
121
123
* - :ref:`notification <services/notification>`
122
124
- display notifications
123
125
* - :ref:`rpc <services/rpc>`
@@ -165,6 +167,180 @@ API
165
167
166
168
Deletes the cookie `name`.
167
169
170
+
.. _services/effect:
171
+
172
+
Effect service
173
+
--------------
174
+
175
+
Overview
176
+
~~~~~~~~
177
+
178
+
* Technical name: `effect`
179
+
* Dependencies: None
180
+
181
+
Effects are graphical elements that can be temporarily displayed on top of the page, usually to provide feedback to the user that something interesting happened.
182
+
183
+
A good example would be the rainbow man:
184
+
185
+
.. image:: images/rainbow_man.png
186
+
:alt:The rainbow man effect
187
+
:width:600
188
+
:align:center
189
+
190
+
191
+
Here's how this can be displayed:
192
+
193
+
.. code-block:: javascript
194
+
195
+
consteffectService=useService("effect");
196
+
effectService.add({
197
+
type:"rainbow_man",
198
+
message:"Boom! Team record for the past 30 days.",
199
+
});
200
+
201
+
.. warning ::
202
+
The hook `useEffect` is not related to the effect service.
203
+
204
+
API
205
+
~~~
206
+
207
+
.. js:function::effectService.add(options)
208
+
209
+
:param object options: the options for the effect. They will get passed along to the underlying effect component.
210
+
211
+
Display an effect.
212
+
213
+
The options are defined by:
214
+
215
+
.. code-block:: ts
216
+
217
+
@typedef {Object} [EffectOptions]
218
+
@property {string} [type="rainbow_man"]
219
+
// The name of the desired effect
220
+
221
+
Available effects
222
+
~~~~~~~~~~~~~~~~~
223
+
224
+
Currently, the only effect is the rainbow man.
225
+
226
+
RainbowMan
227
+
**********
228
+
229
+
.. code-block:: javascript
230
+
231
+
effectService.add({ type:"rainbow_man" });
232
+
233
+
.. list-table::
234
+
:widths: 20 40 40
235
+
:header-rows: 1
236
+
237
+
* - Name
238
+
- Type
239
+
- Description
240
+
* - `params.message`
241
+
- `string?="Well Done"`
242
+
- The message in the notice the rainbowman holds or the content of the notification if effects are disabled.
243
+
244
+
Can be a simple a string.
245
+
246
+
Can be a string representation of html (prefer component if you want interactions in the DOM).
247
+
* - `params.img_url`
248
+
- `string?=/web/static/img/smile.svg`
249
+
- The url of the image to display inside the rainbow.
250
+
* - `params.messageIsHtml`
251
+
- `boolean?=false`
252
+
- Set to true if the message encodes html, s.t. it will be correctly inserted into the DOM.
253
+
* - `params.fadeout`
254
+
- `("slow"|"medium"|"fast"|"no")?="medium"`
255
+
- Delay for rainbowman to disappear.
256
+
257
+
`"fast"` will make rainbowman dissapear quickly.
258
+
259
+
`"medium"` and 'slow' will wait little longer before disappearing (can be used when `options.message` is longer).
260
+
261
+
`"no"` will keep rainbowman on screen until user clicks anywhere outside rainbowman.
262
+
263
+
* - `params.Component`
264
+
- `owl.Component?=RainbowMan`
265
+
- Component class to instantiate (if effects aren't disabled).
266
+
* - `params.props`
267
+
- `object?={}`
268
+
- If params.Component is given, its props can be passed with this argument.
269
+
270
+
How to add an effect
271
+
~~~~~~~~~~~~~~~~~~~~
272
+
273
+
.. _javascript/effect_registry:
274
+
275
+
The effects are stored in a registry called `effects`.
276
+
You can add new effects by providing a name and a function.
0 commit comments