ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\UI\examples\Prompt\Standard Namespace Reference

Functions

 base ()
 
 form ()
 
 parameters ()
 

Function Documentation

◆ base()

ILIAS\UI\examples\Prompt\Standard\base ( )

description: > This example wraps a Message Box into a Prompt (State).

expected output: > A Message Box is rendered along with a Button triggering the Prompt. The action of the Message Box is without function. When clicking "Show Simple Prompt", a Prompt is shown, making controls on the original page inaccessible. The action of the Message Box is removed from the content and shown in

the button-section of the Prompt.

Definition at line 40 of file base.php.

41{
42 global $DIC;
43 $factory = $DIC->ui()->factory();
44 $renderer = $DIC->ui()->renderer();
45
46 $df = new \ILIAS\Data\Factory();
47 $refinery = $DIC['refinery'];
48
49 $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
50 $url_builder = new URLBuilder($here_uri);
51
52 //The messagebox we are going to wrap into the prompt
53 $message = $factory->messageBox()->success('some message box')
54 ->withButtons([$factory->button()->standard('some Action', '#')]);
55
56 //when expecting a state, we do not want to render other examples
57 $example_namespace = ['prompt', 'endpoints'];
58 list($url_builder, $endpointtoken) = $url_builder->acquireParameters($example_namespace, "endpoint");
59 $url_builder = $url_builder->withParameter($endpointtoken, "true");
60
61 //build the prompt
62 $query_namespace = ['prompt', 'example0'];
63 list($url_builder, $token) = $url_builder->acquireParameters($query_namespace, "show");
64 $url_builder = $url_builder->withParameter($token, "true");
65 $prompt = $factory->prompt()->standard($url_builder->buildURI());
66
67 //build the endpoint returning the wrapped message
68 $query = $DIC->http()->wrapper()->query();
69 if ($query->has($token->getName())) {
70 $response = $factory->prompt()->state()->show($message);
71 echo($renderer->renderAsync($response));
72 exit();
73 }
74
75 //a button to open the prompt:
76 $show_button = $factory->button()->standard('Show Simple Prompt', $prompt->getShowSignal());
77
78 if (!$query->has($endpointtoken->getName())) {
79 return $renderer->render([
81 $prompt,
82 $show_button
83 ]);
84 }
85}
$renderer
exit
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31
$token
Definition: xapitoken.php:70
$response
Definition: xapitoken.php:93

References $DIC, $message, ILIAS\UI\examples\Layout\Page\Standard\$refinery, $renderer, $response, $token, and exit.

◆ form()

ILIAS\UI\examples\Prompt\Standard\form ( )

description: > This shows a Form being used in a Prompt.

expected output: > Initially, there is but a button to open the Prompt. Clicking the button, a Prompt is shown with a required Text Input. Leave it blank and click 'Save', the Form's error messages should be shown. Enter any string and click 'Save' again; the error disappears, but the Prompt and Form are still shown.

Finally, enter the word 'close' and save again. The Prompt closes.

alternatively: $response = $response->withCloseModal(true);

Definition at line 39 of file form.php.

40{
41 global $DIC;
42 $factory = $DIC->ui()->factory();
43 $renderer = $DIC->ui()->renderer();
44
45 $df = new \ILIAS\Data\Factory();
46 $refinery = $DIC['refinery'];
47
48 $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
49 $url_builder = new URLBuilder($here_uri);
50
51 //when expecting a state, we do not want to render other examples
52 $example_namespace = ['prompt', 'endpoints'];
53 list($url_builder, $endpointtoken) = $url_builder->acquireParameters($example_namespace, "endpoint");
54 $url_builder = $url_builder->withParameter($endpointtoken, "true");
55
56 //build the prompt
57 $query_namespace = ['prompt', 'example2'];
58 list($url_builder, $action_token) = $url_builder->acquireParameters($query_namespace, "action");
59 $url_builder = $url_builder->withParameter($action_token, "form");
60 $prompt = $factory->prompt()->standard($url_builder->buildURI());
61
62 //fill the state according to (query-)parameters
63 $query = $DIC->http()->wrapper()->query();
64 if ($query->has($action_token->getName())
65 && $query->has($action_token->getName())
66 && $query->retrieve($action_token->getName(), $refinery->kindlyTo()->string()) === 'form'
67 ) {
68
69 //setup a form.
70 $uri = $url_builder->buildURI()->__toString();
71 $form = $factory->input()->container()->form()->standard(
72 $uri,
73 [
74 $factory->input()->field()->text(
75 "Text Input",
76 "write 'close' to close the prompt."
77 )->withRequired(true)
78 ]
79 );
80
81 //set the response
82 $response = $factory->prompt()->state()->show($form);
83
84 $request = $DIC->http()->request();
85 if ($request->getMethod() === 'POST') {
86 $form = $form->withRequest($request);
87 $data = $form->getData();
88 if ($data !== null && reset($data) === 'close') {
93 $response = $factory->prompt()->state()->close();
94 } else {
95 $response = $factory->prompt()->state()->show($form);
96 }
97 }
98 $response = $response->withTitle('prompt form example');
99 echo($renderer->renderAsync($response));
100 exit();
101 }
102
103 if (!$query->has($endpointtoken->getName())) {
104 $show_button = $factory->button()->standard('Show Prompt with Form', $prompt->getShowSignal());
105 return $renderer->render([$prompt, $show_button]);
106 }
107}

References $data, $DIC, ILIAS\UI\examples\Layout\Page\Standard\$refinery, $renderer, $response, and exit.

◆ parameters()

ILIAS\UI\examples\Prompt\Standard\parameters ( )

description: > This shows how different states are being used in the same Prompt according to parameters, thus creating an 'internally navigational' Prompt. the additional buttons demonstrate the usage of JS within Prompts.

expected output: > Initially, there are three buttons to open the Prompt. The Prompt will display several links. Clicking a Link will display the

clicked number in the content, along with a "back"-Button.

Definition at line 39 of file parameters.php.

40{
41 global $DIC;
42 $factory = $DIC->ui()->factory();
43 $renderer = $DIC->ui()->renderer();
44
45 $df = new \ILIAS\Data\Factory();
46 $refinery = $DIC['refinery'];
47
48 $here_uri = $df->uri($DIC->http()->request()->getUri()->__toString());
49 $url_builder = new URLBuilder($here_uri);
50
51 //when expecting a state, we do not want to render other examples
52 $example_namespace = ['prompt', 'endpoints'];
53 list($url_builder, $endpointtoken) = $url_builder->acquireParameters($example_namespace, "endpoint");
54 $url_builder = $url_builder->withParameter($endpointtoken, "true");
55
56 //build a prompt
57 $query_namespace = ['prompt', 'example1'];
58 list($url_builder, $action_token, $amount_token) = $url_builder->acquireParameters($query_namespace, "action", "amount");
59 $url_builder = $url_builder->withParameter($action_token, "showprompt");
60
61 $default_uri = $url_builder->withParameter($amount_token, "1")->buildURI();
62 $prompt = $factory->prompt()->standard($default_uri);
63
64 //build some endpoint
65 $query = $DIC->http()->wrapper()->query();
66 $icon = $factory->symbol()->icon()->standard('someExample', 'Example');
67 $item = $icon;
68 $links = [];
69
70 if ($query->has($action_token->getName())) {
71 $action = $query->retrieve($action_token->getName(), $refinery->kindlyTo()->string());
72 $amount = $query->retrieve($amount_token->getName(), $refinery->kindlyTo()->int()) ;
73 switch ($action) {
74 case 'showprompt':
75 foreach (range(1, $amount) as $idx) {
76 $link_uri = $url_builder
77 ->withParameter($action_token, "promptlink")
78 ->withParameter($amount_token, (string) $idx)
79 ->buildURI()->__toString();
80 $links[] = $factory->link()->standard((string) $idx, $link_uri);
81 }
82 $buttons = [
83 $factory->button()->standard('OK', '#')->withOnLoadCode(
84 fn($id) => "$('#$id').on('click', (e)=> {alert('$id');});"
85 )
86 ];
87 \ilSession::set("full_amount", (string) $idx);
88 $prompt_content = $factory->messageBox()->info('some text')
89 ->withLinks($links)
90 ->withButtons($buttons);
91 break;
92
93 case 'promptlink':
94 $back_uri = $url_builder
95 ->withParameter($action_token, "showprompt")
96 ->withParameter($amount_token, (string) \ilSession::get("full_amount"))
97 ->buildURI()->__toString();
98 $back = $factory->button()->standard('back', '#')->withOnLoadCode(
99 fn($id) => "$('#$id').on('click', (e)=> {
100 let promptId = e.target.closest('.il-prompt').id;
101 il.UI.prompt.get(promptId).show('$back_uri');
102 });"
103 );
104 $prompt_content = $factory->messageBox()->info((string) $amount)
105 ->withButtons([$back]);
106 break;
107
108 default:
109 throw new \Exception('?' . $action . $amount);
110 }
111
112 $response = $factory->prompt()->state()->show($prompt_content);
113 echo($renderer->renderAsync($response));
114 exit();
115 }
116
117 if (!$query->has($endpointtoken->getName())) {
118 $show_button = $factory->button()->standard('Show Simple Prompt', $prompt->getShowSignal());
119 $close_button = $factory->button()->standard('close Simple Prompt', $prompt->getCloseSignal());
120
121 $uri = $url_builder->withParameter($amount_token, "8")->buildURI();
122 $show_button8 = $factory->button()->standard('Show Prompt with Parameter', $prompt->getShowSignal($uri));
123
124 $uri = $url_builder->withParameter($amount_token, "78")->buildURI();
125 $show_button78 = $factory->button()->standard('Show Prompt with a lot of Items', $prompt->getShowSignal($uri));
126
127 return $renderer->render([
128 $prompt,
129 $show_button, $show_button8, $show_button78
130 ]);
131 }
132}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.

References $DIC, $id, ILIAS\UI\examples\Layout\Page\Standard\$refinery, $renderer, $response, exit, ilSession\get(), and ilSession\set().

Referenced by ilMediaItem\__construct(), ilStyleClassAddedObjective\__construct(), ilWebLinkBaseItem\__construct(), ilStyleClassAddedObjective\achieve(), ilWebLinkDraftItem\addParameter(), ilSessionAppEventListener\fetchRecipientParticipants(), ILIAS\MetaData\Editor\Http\LinkBuilder\get(), ilMediaItem\getParameter(), ilMediaItem\getParameterString(), ilMailAppEventListener\handle(), ilSessionAppEventListener\handle(), ilCertificateAppEventListener\handleDeletedUser(), ilCertificateAppEventListener\handleLPUpdate(), ilMediaItem\resetParameters(), ilSessionAppEventListener\sendMail(), ilMediaItem\setParameter(), ilSCORMItem\setParameters(), ilWACPath\setParameters(), ilWACPath\setTimestamp(), ilWACPath\setToken(), and ilWACPath\setTTL().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: