UPDATE-RATE

Die Test-Installation wird aktuell zwischen 8:00 und 18:00 Uhr stündlich zur vollen Stunde aktualisiert.

Alles neu macht der Mai

ILIAS 9 ist da! Alle Infos zu den Highlights der neuen Version gibt es hier!

Documentation

Kitchen Sink documentation of style: 'Delos' of skin: 'ILIAS'

Interruptive

Description

Purpose
An Interruptive modal disrupts the user in critical situation, forcing him or her to focus on the task at hand.
Composition
The modal states why this situation needs attention and may point out consequences.
Effect
All controls of the original context are inaccessible until the modal is completed. Upon completion the user returns to the original context.

Rules

Usage
  1. Due to the heavily disruptive nature of this type of modal it MUST be restricted to critical situations (e.g. loss of data).
  2. All actions where data is deleted from the system are considered to be critical situations and SHOULD be implemented as an Interruptive modal. Exceptions are possible if items from lists in forms are to be deleted or if the modal would heavily disrupt the workflow.
  3. Interruptive modals MUST contain a primary button continuing the action that initiated the modal (e.g. Delete the item) on the left side of the footer of the modal and a default button canceling the action on the right side of the footer.
  4. The cancel button in the footer and the close button in the header MUST NOT perform any additional action than closing the Interruptive modal.

Example 1: Base

<?php
 
declare(strict_types=1);
 
namespace ILIAS\UI\examples\Modal\Interruptive;
 
function base()
{
    global $DIC;
    $factory = $DIC->ui()->factory();
    $renderer = $DIC->ui()->renderer();
    $message = 'Are you sure you want to delete the following items?';
    $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
    $modal = $factory->modal()->interruptive('My Title', $message, $form_action);
 
    // Note: This modal is just rendered in the DOM but not displayed
    // because its show/close signals are not triggered by any components
    return $renderer->render($modal);
}
 

Example 2: Show modal on button click async rendered

<?php
 
declare(strict_types=1);
 
namespace ILIAS\UI\examples\Modal\Interruptive;
 
function show_modal_on_button_click_async_rendered()
{
    global $DIC;
    $factory = $DIC->ui()->factory();
    $renderer = $DIC->ui()->renderer();
    $refinery = $DIC->refinery();
    $request_wrapper = $DIC->http()->wrapper()->query();
    $post_wrapper = $DIC->http()->wrapper()->post();
    $ctrl = $DIC->ctrl();
 
    $message = 'Are you sure you want to delete the following item?';
    $ctrl->setParameterByClass('ilsystemstyledocumentationgui', 'modal_nr', "2");
    $form_action = $ctrl->getFormActionByClass('ilsystemstyledocumentationgui');
    $items = ['First Item', 'Second Item', 'Third Item'];
 
    // Check if this is the ajax request to deliver the new modal showing the affected item
    if ($request_wrapper->has('item')) {
        $id = $request_wrapper->retrieve('item', $refinery->kindlyTo()->string());
        $item = $items[$id];
        $affected_item = $factory->modal()->interruptiveItem()->standard($id, $item);
        $modal = $factory->modal()->interruptive('Delete Items', $message, $form_action)
            ->withAffectedItems([$affected_item]);
        echo $renderer->render($modal);
        exit();
    }
 
    // Create a button per item
    $out = [];
    foreach ($items as $i => $item) {
        $ajax_url = $_SERVER['REQUEST_URI'] . '&item=' . $i;
        $modal = $factory->modal()->interruptive('', '', '')
            ->withAsyncRenderUrl($ajax_url);
        $button = $factory->button()->standard('Delete ' . $item, '#')
            ->withOnClick($modal->getShowSignal());
        $out[] = $button;
        $out[] = $modal;
    }
 
    // Display POST data of affected items in a panel
    if (
        $post_wrapper->has('interruptive_items') &&
        $request_wrapper->has('modal_nr') && $request_wrapper->retrieve('modal_nr', $refinery->kindlyTo()->string()) === '2'
    ) {
        $out[] = $post_wrapper->retrieve('interruptive_items', $refinery->custom()->transformation(
            function ($v) use ($factory, $post_wrapper, $items) {
                return $factory->panel()->standard('Affected Item', $factory->legacy($items[$v[0]]));
            }
        ));
    }
 
    return $renderer->render($out);
}
 

Example 3: Show modal on button click

<?php
 
declare(strict_types=1);
 
namespace ILIAS\UI\examples\Modal\Interruptive;
 
function show_modal_on_button_click()
{
    global $DIC;
    $factory = $DIC->ui()->factory();
    $renderer = $DIC->ui()->renderer();
    $refinery = $DIC->refinery();
    $request_wrapper = $DIC->http()->wrapper()->query();
    $post_wrapper = $DIC->http()->wrapper()->post();
    $ctrl = $DIC->ctrl();
 
    $message = 'Are you sure you want to delete the following items?';
    $ctrl->setParameterByClass('ilsystemstyledocumentationgui', 'modal_nr', 1);
    $form_action = $ctrl->getFormActionByClass('ilsystemstyledocumentationgui');
    $icon = $factory->image()->standard('./templates/default/images/standard/icon_crs.svg', '');
    $modal = $factory->modal()->interruptive('My Title', $message, $form_action)
        ->withAffectedItems(array(
            $factory->modal()->interruptiveItem()->standard('10', 'Course 1', $icon, 'Some description text'),
            $factory->modal()->interruptiveItem()->keyValue('20', 'Item Key', 'item value'),
            $factory->modal()->interruptiveItem()->standard('30', 'Course 3', $icon, 'Last but not least, a description'),
            $factory->modal()->interruptiveItem()->keyValue('50', 'Second Item Key', 'another item value'),
        ));
    $button = $factory->button()->standard('Show Modal', '')
        ->withOnClick($modal->getShowSignal());
 
    $out = [$button, $modal];
 
    // Display POST data of affected items in a panel
    if (
        $request_wrapper->has('interruptive_items') &&
        $request_wrapper->retrieve('modal_nr', $refinery->kindlyTo()->string()) === '1'
    ) {
        $panel = $factory->panel()->standard(
            'Affected Items',
            $factory->legacy(print_r($post_wrapper->retrieve('interruptive_items', $refinery->kindlyTo()->string()), true))
        );
        $out[] = $panel;
    }
 
    return $renderer->render($out);
}
 

Example 4: With custom labels

<?php
 
declare(strict_types=1);
 
namespace ILIAS\UI\examples\Modal\Interruptive;
 
/**
 * An example showing how you can set a custom label for the
 * modals action- and cancel-button.
 */
function with_custom_labels()
{
    global $DIC;
    $factory = $DIC->ui()->factory();
    $renderer = $DIC->ui()->renderer();
 
    $modal = $factory->modal()->interruptive(
        'Interrupting something',
        'Am I interrupting you?',
        '#'
    )->withActionButtonLabel(
        'Yeah you do!'
    )->withCancelButtonLabel(
        'Nah, not really'
    );
 
    $trigger = $factory->button()->standard('I will interrupt you', $modal->getShowSignal());
 
    return $renderer->render([$modal, $trigger]);
}
 

Relations

Parents
  1. UIComponent
  2. Modal