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
33 $f = $DIC->ui()->factory();
34 $renderer = $DIC->ui()->renderer();
37 $icon =
$f->symbol()->icon()->standard(
"chtr",
"chtr");
38 $title =
$f->link()->standard(
"Some Title",
"#");
39 $item =
$f->item()->notification($title, $icon);
43 $async_close =
$_SERVER[
'REQUEST_URI'] .
'&close_item=true&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=false';
45 $closable_item = $item->withCloseAction($async_close);
47 $async_replace_url =
$_SERVER[
'REQUEST_URI'] .
'&close_item=false&async_load_replace=true&async_load_replace_content=false&async_add_aggregate=false';
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';
51 $async_add_aggregate =
$_SERVER[
'REQUEST_URI'] .
'&close_item=false&async_load_replace=false&async_load_replace_content=false&async_add_aggregate=true';
53 if (
$_GET[
'close_item'] ===
"true") {
55 $js =
$f->legacy(
"")->withOnLoadCode(
function ($id) use ($async_replace_content_load_url) {
57 il.DemoScopeRemaining--; 58 il.DemoScopeItem.replaceContentByAsyncItemContent('$async_replace_content_load_url',{remaining: il.DemoScopeRemaining,added: il.DemoScopeAdded}); 61 echo $renderer->renderAsync($js);
65 if (
$_GET[
'async_load_replace'] ===
"true") {
66 $remaining =
$_GET[
"remaining"];
67 $added =
$_GET[
"added"];
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.");
75 $replacement = $item->withDescription(
"Number of Async non-closed Aggregates: " . $remaining .
", totally created: " . $added)
76 ->withAggregateNotifications($items);
78 echo $renderer->renderAsync([$replacement]);
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]);
90 if (
$_GET[
'async_add_aggregate'] ===
"true") {
91 $remaining =
$_GET[
"remaining"];
92 $added =
$_GET[
"added"];
94 $new_aggregate = $closable_item->withDescription(
"The item has been added, Nr: " . $added);
96 echo $renderer->renderAsync([$new_aggregate]);
103 $add_button =
$f->button()->standard(
"Add Chat Notification",
"#")
104 ->withAdditionalOnLoadCode(
function ($id) use ($async_replace_url, $async_add_aggregate) {
106 $('#$id').click(function() { 107 il.DemoScopeItem.getCounterObjectIfAny().incrementNoveltyCount(1); 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}); 116 $reset_button =
$f->button()->standard(
"Reset Chat",
"#")
117 ->withAdditionalOnLoadCode(
function ($id) use ($async_replace_url) {
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}); 128 $set_button =
$f->button()->standard(
"Set to 10 chat entries",
"#")
129 ->withAdditionalOnLoadCode(
function ($id) use ($async_replace_url) {
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}); 146 ->withDescription(
"This is the original Version after the Page has loaded. Will be replaced completely.")
147 ->withAdditionalOnLoadCode(
function ($id) {
149 il.DemoScopeAdded = 0; 150 il.DemoScopeRemaining = 0; 151 il.DemoScopeItem = il.UI.item.notification.getNotificationItemObject($($id));
usuallyDoneByGlobalScreenProbablyIgnore($async_item, $f, $renderer, $add_button, $set_button, $reset_button)