Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
---
2
layout: docs
3
title: "Notifications"
4
description: "Moodle notifications"
5
date: 2020-02-04T09:40:32+01:00
6
draft: false
7
weight: 50
8
tags:
9
- Available
10
- Needs review
11
---
12
 
13
## How it works
14
 
15
Notifications are coupled with actions and provide instant feedback to the action results. Moodle notifications are shown right above the actionable content or overlaying the user interface for JavaScript related actions.
16
 
17
## Example
18
 
19
{{< example show_markup="false">}}
20
<div class="alert alert-info alert-block fade in foo bar" role="alert" data-aria-autofocus="true" id="yui_3_17_2_1_1599746674354_24">
21
    <button type="button" class="close" data-dismiss="alert">×</button>
22
    Hello
23
</div>
24
{{< /example >}}
25
 
26
## Source files
27
 
28
* `lib/amd/src/notification.js`
29
* `lib/templates/notification_info.mustache`
30
* `lib/templates/notification_success.mustache`
31
* `lib/templates/notification_warning.mustache`
32
* `lib/templates/notification_error.mustache`
33
 
34
## Core renderer
35
 
36
Notifications can be added in PHP using the core renderer notification method
37
 
38
{{< php >}}
39
  $OUTPUT->notification('message', 'info');
40
{{< / php >}}
41
 
42
## Notification templates
43
 
44
{{< mustache template="core/notification_info" >}}
45
{{< /mustache >}}
46
 
47
{{< mustache template="core/notification_success" >}}
48
{
49
    "message": "Your pants are on awesome!",
50
    "closebutton": 1,
51
    "announce": 1,
52
    "extraclasses": "foo bar"
53
}
54
{{< /mustache >}}
55
 
56
{{< mustache template="core/notification_warning" >}}
57
{
58
    "message": "Your pants are on down!",
59
    "closebutton": 1,
60
    "announce": 1,
61
    "extraclasses": "foo bar"
62
}
63
{{< /mustache >}}
64
 
65
{{< mustache template="core/notification_error" >}}
66
{
67
    "message": "Your pants are on fire!",
68
    "closebutton": 1,
69
    "announce": 1,
70
    "extraclasses": "foo bar"
71
}
72
{{< /mustache >}}
73
 
74
## JavaScript Notifications
75
 
76
{{< example >}}
77
<button class="btn btn-secondary" data-action="shownotification">Show JS Notification</button>
78
{{#js}}
79
require(
80
[
81
    'core/notification'
82
],
83
function(
84
    Notification
85
) {
86
    document.querySelector('[data-action="shownotification"]').addEventListener('click', function() {
87
        Notification.alert('Notification message', 'Extra content for notification message');
88
    });
89
});
90
{{/js}}
91
{{< /example >}}
92
 
93
## Toast Notifications
94
 
95
{{< example >}}
96
<button class="btn btn-secondary" data-action="showtoastnotification">Show Toast Notification</button>
97
{{#js}}
98
require(
99
[
100
    'core/toast'
101
],
102
function(
103
    Toast
104
) {
105
    document.querySelector('[data-action="showtoastnotification"]').addEventListener('click', function() {
106
        Toast.add('Toast message');
107
    });
108
});
109
{{/js}}
110
{{< /example >}}