This is a rather extended example on the usage of the Notification Item async functionality provided by src/UI/templates/js/Item/notification.js.
See notification.js for a detailed description of the function. Note that we use some il.DemoScope to store some JS for Demo purposes, it contains the following three items:
Important, this is the heart of the example. By creating our Notification Item we attach in additionalOnLoad code the logic to store access to our freshly created Notification Item.
Note the work from here on is usually done by the global screen. This is just done to get the example up and running and to give it a more realistic look. See ilias/src/GlobalScreen/Scope/Notification/README.md
30{
31
33 $f =
$DIC->ui()->factory();
34 $renderer =
$DIC->ui()->renderer();
35
36
37 $icon =
$f->symbol()->icon()->standard(
"chtr",
"chtr");
38 $title =
$f->link()->standard(
"Some Title",
"#");
39 $item =
$f->item()->notification($title, $icon);
40
41
42
43 $async_close =
$_SERVER[
'REQUEST_URI'] .
'&close_item=true&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=false';
44
45 $closable_item = $item->withCloseAction($async_close);
46
47 $async_replace_url =
$_SERVER[
'REQUEST_URI'] .
'&close_item=false&async_load_replace=true&async_load_replace_content=false&async_add_aggregate=false';
48
49 $async_replace_content_load_url =
$_SERVER[
'REQUEST_URI'] .
'&close_item=false&async_load_replace=false&async_load_replace_content=true&async_add_aggregate=false';
50
51 $async_add_aggregate =
$_SERVER[
'REQUEST_URI'] .
'&close_item=false&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=true';
52
53 if (
$_GET[
'close_item'] ===
"true") {
54
55 $js =
$f->legacy(
"")->withOnLoadCode(
function ($id) use ($async_replace_content_load_url) {
56 return "
57 il.DemoScopeRemaining--;
58 il.DemoScopeItem.replaceContentByAsyncItemContent('$async_replace_content_load_url',{remaining: il.DemoScopeRemaining,added: il.DemoScopeAdded});
59 ";
60 });
61 echo $renderer->renderAsync($js);
63 }
64
65 if (
$_GET[
'async_load_replace'] ===
"true") {
66 $remaining =
$_GET[
"remaining"];
67 $added =
$_GET[
"added"];
68
69
70
71 $items = [];
72 for (
$i = 1;
$i < $added + 1;
$i++) {
73 $items[] = $closable_item->withDescription(
"This item is number: " .
$i .
" of a fix set of 10 entries.");
74 }
75 $replacement = $item->withDescription("Number of Async non-closed Aggregates: " . $remaining . ", totally created: " . $added)
76 ->withAggregateNotifications($items);
77
78 echo $renderer->renderAsync([$replacement]);
80 }
81
82 if (
$_GET[
'async_load_replace_content'] ===
"true") {
83 $remaining =
$_GET[
"remaining"];
84 $added =
$_GET[
"added"];
85 $replacement = $item->withDescription("Number of Async non-closed Aggregates: " . $remaining . ", totally created: " . $added);
86 echo $renderer->renderAsync([$replacement]);
88 }
89
90 if (
$_GET[
'async_add_aggregate'] ===
"true") {
91 $remaining =
$_GET[
"remaining"];
92 $added =
$_GET[
"added"];
93
94 $new_aggregate = $closable_item->withDescription("The item has been added, Nr: " . $added);
95
96 echo $renderer->renderAsync([$new_aggregate]);
98 }
99
100
101
102
103 $add_button =
$f->button()->standard(
"Add Chat Notification",
"#")
104 ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url, $async_add_aggregate) {
105 return "
106 $('#$id').click(function() {
107 il.DemoScopeItem.getCounterObjectIfAny().incrementNoveltyCount(1);
108 il.DemoScopeAdded++;
109 il.DemoScopeRemaining++;
110 il.DemoScopeItem.addAsyncAggregate('$async_add_aggregate',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
111 il.DemoScopeItem.replaceContentByAsyncItemContent('$async_replace_url',{remaining: il.DemoScopeRemaining,added: il.DemoScopeAdded});
112 });";
113 });
114
115
116 $reset_button =
$f->button()->standard(
"Reset Chat",
"#")
117 ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url) {
118 return "
119 $('#$id').click(function() {
120 il.DemoScopeItem.getCounterObjectIfAny().decrementNoveltyCount(il.DemoScopeRemaining);
121 il.DemoScopeAdded = 0;
122 il.DemoScopeRemaining = 0;
123 il.DemoScopeItem.replaceByAsyncItem('$async_replace_url',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
124 });";
125 });
126
127
128 $set_button =
$f->button()->standard(
"Set to 10 chat entries",
"#")
129 ->withAdditionalOnLoadCode(function ($id) use ($async_replace_url) {
130 return "
131 $('#$id').click(function() {
132 il.DemoScopeItem.getCounterObjectIfAny().decrementNoveltyCount(il.DemoScopeRemaining);
133 il.DemoScopeItem.getCounterObjectIfAny().incrementNoveltyCount(10);
134 il.DemoScopeAdded = 10;
135 il.DemoScopeRemaining = 10;
136 il.DemoScopeItem.replaceByAsyncItem('$async_replace_url',{remaining: il.DemoScopeAdded,added: il.DemoScopeAdded});
137 });";
138 });
139
145 $async_item = $item
146 ->withDescription("This is the original Version after the Page has loaded. Will be replaced completely.")
147 ->withAdditionalOnLoadCode(function ($id) {
148 return "
149 il.DemoScopeAdded = 0;
150 il.DemoScopeRemaining = 0;
151 il.DemoScopeItem = il.UI.item.notification.getNotificationItemObject($($id));
152 ";
153 });
154
161}
usuallyDoneByGlobalScreenProbablyIgnore($async_item, $f, $renderer, $add_button, $set_button, $reset_button)